From dfcafbec34e0e454d9995551998af5d40a27c7ad Mon Sep 17 00:00:00 2001 From: christian mueller Date: Thu, 1 Mar 2012 19:12:55 +0100 Subject: * fix [GAM-28] problems in routingsender.cpp * [GAM-27] major refactoring: bringing everything to standardized names * Enhancement of CAmSerializer.h * improvement of documentation * adoption & regeneration of inerfaces --- AudioManagerDaemon/CMakeLists.txt | 36 +- AudioManagerDaemon/include/CAmCommandReceiver.h | 92 + AudioManagerDaemon/include/CAmCommandSender.h | 85 + AudioManagerDaemon/include/CAmControlReceiver.h | 131 + AudioManagerDaemon/include/CAmControlSender.h | 103 + AudioManagerDaemon/include/CAmDatabaseHandler.h | 280 ++ AudioManagerDaemon/include/CAmDatabaseObserver.h | 83 + AudioManagerDaemon/include/CAmRouter.h | 84 + AudioManagerDaemon/include/CAmRoutingReceiver.h | 112 + AudioManagerDaemon/include/CAmRoutingSender.h | 202 + AudioManagerDaemon/include/CAmTelnetMenuHelper.h | 44 +- AudioManagerDaemon/include/CAmTelnetServer.h | 105 + AudioManagerDaemon/include/CommandReceiver.h | 92 - AudioManagerDaemon/include/CommandSender.h | 85 - AudioManagerDaemon/include/ControlReceiver.h | 131 - AudioManagerDaemon/include/ControlSender.h | 103 - AudioManagerDaemon/include/DAmDoxygenMainPage.h | 115 + AudioManagerDaemon/include/DatabaseHandler.h | 280 -- AudioManagerDaemon/include/DatabaseObserver.h | 83 - AudioManagerDaemon/include/PluginTemplate.h | 92 - AudioManagerDaemon/include/Router.h | 84 - AudioManagerDaemon/include/RoutingReceiver.h | 112 - AudioManagerDaemon/include/RoutingSender.h | 202 - AudioManagerDaemon/include/TAmPluginTemplate.h | 92 + AudioManagerDaemon/include/TelnetServer.h | 105 - AudioManagerDaemon/include/mainpage.h | 115 - AudioManagerDaemon/src/CAmCommandReceiver.cpp | 224 + AudioManagerDaemon/src/CAmCommandSender.cpp | 286 ++ AudioManagerDaemon/src/CAmControlReceiver.cpp | 513 +++ AudioManagerDaemon/src/CAmControlSender.cpp | 314 ++ AudioManagerDaemon/src/CAmDatabaseHandler.cpp | 4402 ++++++++++++++++++++ AudioManagerDaemon/src/CAmDatabaseObserver.cpp | 207 + AudioManagerDaemon/src/CAmDbusWrapper.cpp | 434 ++ AudioManagerDaemon/src/CAmDltWrapper.cpp | 219 + AudioManagerDaemon/src/CAmRouter.cpp | 354 ++ AudioManagerDaemon/src/CAmRoutingReceiver.cpp | 382 ++ AudioManagerDaemon/src/CAmRoutingSender.cpp | 560 +++ AudioManagerDaemon/src/CAmSocketHandler.cpp | 498 +++ AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp | 28 +- AudioManagerDaemon/src/CAmTelnetServer.cpp | 262 ++ AudioManagerDaemon/src/CommandReceiver.cpp | 222 - AudioManagerDaemon/src/CommandSender.cpp | 285 -- AudioManagerDaemon/src/ControlReceiver.cpp | 514 --- AudioManagerDaemon/src/ControlSender.cpp | 314 -- AudioManagerDaemon/src/DBusWrapper.cpp | 432 -- AudioManagerDaemon/src/DLTWrapper.cpp | 214 - AudioManagerDaemon/src/DatabaseHandler.cpp | 4401 ------------------- AudioManagerDaemon/src/DatabaseObserver.cpp | 206 - AudioManagerDaemon/src/Router.cpp | 354 -- AudioManagerDaemon/src/RoutingReceiver.cpp | 382 -- AudioManagerDaemon/src/RoutingSender.cpp | 544 --- AudioManagerDaemon/src/SocketHandler.cpp | 499 --- AudioManagerDaemon/src/TelnetServer.cpp | 261 -- AudioManagerDaemon/src/main.cpp | 73 +- .../CAmControlInterfaceTest.cpp | 529 +++ .../CAmControlInterfaceTest.h | 79 + .../test/AmControlInterfaceTest/CMakeLists.txt | 85 + .../CAmDatabaseHandlerTest.cpp | 1941 +++++++++ .../AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h | 78 + .../test/AmDatabaseHandlerTest/CMakeLists.txt | 81 + .../test/AmRouterTest/CAmRouterTest.cpp | 1820 ++++++++ .../test/AmRouterTest/CAmRouterTest.h | 83 + .../test/AmRouterTest/CMakeLists.txt | 81 + .../CAmRoutingInterfaceTest.cpp | 439 ++ .../CAmRoutingInterfaceTest.h | 74 + .../test/AmRoutingInterfaceTest/CMakeLists.txt | 84 + .../AmSocketHandlerTest/CAmSocketHandlerTest.cpp | 367 ++ .../AmSocketHandlerTest/CAmSocketHandlerTest.h | 88 + .../test/AmSocketHandlerTest/CMakeLists.txt | 78 + .../AmTelnetServerTest/CAmTelnetServerTest.cpp | 190 + .../test/AmTelnetServerTest/CAmTelnetServerTest.h | 87 + .../test/AmTelnetServerTest/CMakeLists.txt | 92 + AudioManagerDaemon/test/CAmCommonFunctions.cpp | 328 ++ AudioManagerDaemon/test/CAmCommonFunctions.h | 91 + AudioManagerDaemon/test/CMakeLists.txt | 12 +- AudioManagerDaemon/test/CommandInterfaceBackdoor.h | 50 - AudioManagerDaemon/test/CommonFunctions.cpp | 328 -- AudioManagerDaemon/test/CommonFunctions.h | 91 - AudioManagerDaemon/test/ControlInterfaceBackdoor.h | 47 - AudioManagerDaemon/test/IAmCommandBackdoor.h | 50 + AudioManagerDaemon/test/IAmControlBackdoor.h | 47 + AudioManagerDaemon/test/IAmRoutingBackdoor.h | 49 + AudioManagerDaemon/test/MockIAmCommandSend.h | 82 + AudioManagerDaemon/test/MockIAmControlSend.h | 134 + AudioManagerDaemon/test/MockIAmRoutingSend.h | 76 + AudioManagerDaemon/test/RoutingInterfaceBackdoor.h | 49 - .../test/controlInterface/CMakeLists.txt | 85 - .../test/controlInterface/MockInterfaces.h | 182 - .../test/controlInterface/controlInterfaceTest.cpp | 529 --- .../test/controlInterface/controlInterfaceTest.h | 78 - AudioManagerDaemon/test/database/CMakeLists.txt | 81 - AudioManagerDaemon/test/database/MockInterfaces.h | 189 - AudioManagerDaemon/test/database/databaseTest.cpp | 1941 --------- AudioManagerDaemon/test/database/databaseTest.h | 77 - AudioManagerDaemon/test/routing/CMakeLists.txt | 81 - AudioManagerDaemon/test/routing/MockInterfaces.h | 187 - AudioManagerDaemon/test/routing/routingTest.cpp | 1829 -------- AudioManagerDaemon/test/routing/routingTest.h | 81 - .../test/routingInterface/CMakeLists.txt | 84 - .../test/routingInterface/MockRoutingInterface.h | 76 - .../test/routingInterface/routingInterfaceTest.cpp | 439 -- .../test/routingInterface/routingInterfaceTest.h | 74 - .../test/sockethandler/CMakeLists.txt | 78 - .../test/sockethandler/sockethandlerTest.cpp | 365 -- .../test/sockethandler/sockethandlerTest.h | 88 - .../test/telnetserver/CAmTelnetServerTest.cpp | 190 - .../test/telnetserver/CAmTelnetServerTest.h | 87 - .../test/telnetserver/CMakeLists.txt | 92 - CMakeLists.txt | 13 +- PluginCommandInterfaceDbus/CMakeLists.txt | 12 +- .../include/CAmCommandSenderDbus.h | 123 + .../include/CAmDbusMessageHandler.h | 127 + .../include/CommandInterface.xml | 174 + .../include/CommandReceiverShadow.h | 111 - .../include/DBusCommandSender.h | 122 - .../include/DBusMessageHandler.h | 126 - .../include/IAmCommandReceiverShadow.h | 113 + PluginCommandInterfaceDbus/include/mainpage.h | 32 - .../src/CAmCommandSenderDbus.cpp | 331 ++ .../src/CAmDbusMessageHandler.cpp | 631 +++ .../src/CommandReceiverShadow.cpp | 442 -- .../src/DBusCommandSender.cpp | 328 -- .../src/DBusMessageHandler.cpp | 629 --- .../src/IAmCommandReceiverShadow.cpp | 447 ++ .../test/CAmCommandSenderDbusBackdoor.cpp | 71 + .../test/CAmCommandSenderDbusBackdoor.h | 52 + .../test/CAmCommandSenderDbusSignalTest.cpp | 806 ++++ .../test/CAmCommandSenderDbusSignalTest.h | 51 + .../test/CAmCommandSenderDbusTest.cpp | 629 +++ .../test/CAmCommandSenderDbusTest.h | 61 + PluginCommandInterfaceDbus/test/CMakeLists.txt | 47 +- .../test/DbusCommandInterfaceBackdoor.cpp | 70 - .../test/DbusCommandInterfaceBackdoor.h | 51 - .../test/MockIAmCommandReceive.h | 59 + PluginCommandInterfaceDbus/test/MockInterfaces.h | 85 - .../test/dbuscommandpluginInterfaceTest.cpp | 608 --- .../test/dbuscommandpluginInterfaceTest.h | 72 - .../test/dbuscommaninterfacesignalsTest.cpp | 906 ---- .../test/dbuscommaninterfacesignalsTest.h | 53 - PluginControlInterface/CMakeLists.txt | 8 +- .../include/CAmControlSenderBase.h | 165 + PluginControlInterface/include/ControlSender.h | 165 - .../src/CAmControlSenderBase.cpp | 477 +++ PluginControlInterface/src/ControlSender.cpp | 477 --- PluginRoutingInterfaceAsync/CMakeLists.txt | 8 +- .../include/CAmRoutingSenderAsync.h | 396 ++ .../include/IAmRoutingReceiverShadow.h | 79 + .../include/RoutingReceiverAsyncShadow.h | 78 - .../include/RoutingSenderAsyn.h | 398 -- .../src/CAmRoutingSenderAsync.cpp | 1294 ++++++ .../src/IAmRoutingReceiverShadow.cpp | 195 + .../src/RoutingReceiverAsyncShadow.cpp | 188 - .../src/RoutingSenderAsync.cpp | 1372 ------ .../test/CAmRoutingReceiverAsync.cpp | 518 +++ .../test/CAmRoutingReceiverAsync.h | 73 + PluginRoutingInterfaceAsync/test/CMakeLists.txt | 36 +- .../test/MockIAmRoutingReceive.h | 91 + PluginRoutingInterfaceAsync/test/mocklnterfaces.h | 119 - .../test/testRoutingInterfaceAsync.cpp | 517 --- .../test/testRoutingInterfaceAsync.h | 72 - .../test/testRoutingInterfaceAsyncInterrupt.cpp | 157 - PluginRoutingInterfaceDbus/CMakeLists.txt | 10 +- .../include/CAmRoutingSenderDbus.h | 57 + PluginRoutingInterfaceDbus/include/RoutingSender.h | 57 - .../src/CAmRoutingSenderDbus.cpp | 174 + PluginRoutingInterfaceDbus/src/RoutingSender.cpp | 174 - cmake/AudioManagerCodestyle.xml | 155 + cmake/AudioManager_Codestyle.xml | 155 - cmake/FindDBUS.cmake | 4 +- cmake/config.cmake | 2 - include/audiomanagertypes.h | 819 ++++ include/command/IAmCommandReceive.h | 220 + include/command/IAmCommandSend.h | 194 + include/control/IAmControlReceive.h | 614 +++ include/control/IAmControlSend.h | 388 ++ include/projecttypes.h | 203 + include/routing/IAmRoutingReceive.h | 348 ++ include/routing/IAmRoutingSend.h | 204 + include/shared/CAmDbusWrapper.h | 92 + include/shared/CAmDltWrapper.h | 820 ++++ include/shared/CAmSerializer.h | 708 ++++ include/shared/CAmSocketHandler.h | 258 ++ includes/CAmSerializer.h | 708 ---- includes/DLTWrapper.h | 521 --- includes/SocketHandler.h | 266 -- includes/audiomanagertypes.h | 819 ---- includes/command/CommandReceiveInterface.h | 220 - includes/command/CommandSendInterface.h | 194 - includes/control/ControlReceiveInterface.h | 614 --- includes/control/ControlSendInterface.h | 388 -- includes/dbus/CommandInterface.xml | 174 - includes/dbus/DBusWrapper.h | 101 - includes/projecttypes.h | 203 - includes/routing/RoutingReceiveInterface.h | 348 -- includes/routing/RoutingSendInterface.h | 204 - 195 files changed, 29642 insertions(+), 30094 deletions(-) create mode 100644 AudioManagerDaemon/include/CAmCommandReceiver.h create mode 100644 AudioManagerDaemon/include/CAmCommandSender.h create mode 100644 AudioManagerDaemon/include/CAmControlReceiver.h create mode 100644 AudioManagerDaemon/include/CAmControlSender.h create mode 100644 AudioManagerDaemon/include/CAmDatabaseHandler.h create mode 100644 AudioManagerDaemon/include/CAmDatabaseObserver.h create mode 100644 AudioManagerDaemon/include/CAmRouter.h create mode 100644 AudioManagerDaemon/include/CAmRoutingReceiver.h create mode 100644 AudioManagerDaemon/include/CAmRoutingSender.h create mode 100644 AudioManagerDaemon/include/CAmTelnetServer.h delete mode 100644 AudioManagerDaemon/include/CommandReceiver.h delete mode 100644 AudioManagerDaemon/include/CommandSender.h delete mode 100644 AudioManagerDaemon/include/ControlReceiver.h delete mode 100644 AudioManagerDaemon/include/ControlSender.h create mode 100644 AudioManagerDaemon/include/DAmDoxygenMainPage.h delete mode 100644 AudioManagerDaemon/include/DatabaseHandler.h delete mode 100644 AudioManagerDaemon/include/DatabaseObserver.h delete mode 100644 AudioManagerDaemon/include/PluginTemplate.h delete mode 100644 AudioManagerDaemon/include/Router.h delete mode 100644 AudioManagerDaemon/include/RoutingReceiver.h delete mode 100644 AudioManagerDaemon/include/RoutingSender.h create mode 100644 AudioManagerDaemon/include/TAmPluginTemplate.h delete mode 100644 AudioManagerDaemon/include/TelnetServer.h delete mode 100644 AudioManagerDaemon/include/mainpage.h create mode 100644 AudioManagerDaemon/src/CAmCommandReceiver.cpp create mode 100644 AudioManagerDaemon/src/CAmCommandSender.cpp create mode 100644 AudioManagerDaemon/src/CAmControlReceiver.cpp create mode 100644 AudioManagerDaemon/src/CAmControlSender.cpp create mode 100644 AudioManagerDaemon/src/CAmDatabaseHandler.cpp create mode 100644 AudioManagerDaemon/src/CAmDatabaseObserver.cpp create mode 100644 AudioManagerDaemon/src/CAmDbusWrapper.cpp create mode 100644 AudioManagerDaemon/src/CAmDltWrapper.cpp create mode 100644 AudioManagerDaemon/src/CAmRouter.cpp create mode 100644 AudioManagerDaemon/src/CAmRoutingReceiver.cpp create mode 100644 AudioManagerDaemon/src/CAmRoutingSender.cpp create mode 100644 AudioManagerDaemon/src/CAmSocketHandler.cpp create mode 100644 AudioManagerDaemon/src/CAmTelnetServer.cpp delete mode 100644 AudioManagerDaemon/src/CommandReceiver.cpp delete mode 100644 AudioManagerDaemon/src/CommandSender.cpp delete mode 100644 AudioManagerDaemon/src/ControlReceiver.cpp delete mode 100644 AudioManagerDaemon/src/ControlSender.cpp delete mode 100644 AudioManagerDaemon/src/DBusWrapper.cpp delete mode 100644 AudioManagerDaemon/src/DLTWrapper.cpp delete mode 100644 AudioManagerDaemon/src/DatabaseHandler.cpp delete mode 100644 AudioManagerDaemon/src/DatabaseObserver.cpp delete mode 100644 AudioManagerDaemon/src/Router.cpp delete mode 100644 AudioManagerDaemon/src/RoutingReceiver.cpp delete mode 100644 AudioManagerDaemon/src/RoutingSender.cpp delete mode 100644 AudioManagerDaemon/src/SocketHandler.cpp delete mode 100644 AudioManagerDaemon/src/TelnetServer.cpp create mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp create mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h create mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp create mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h create mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp create mode 100644 AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h create mode 100644 AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp create mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h create mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp create mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h create mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp create mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h create mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt create mode 100644 AudioManagerDaemon/test/CAmCommonFunctions.cpp create mode 100644 AudioManagerDaemon/test/CAmCommonFunctions.h delete mode 100644 AudioManagerDaemon/test/CommandInterfaceBackdoor.h delete mode 100644 AudioManagerDaemon/test/CommonFunctions.cpp delete mode 100644 AudioManagerDaemon/test/CommonFunctions.h delete mode 100644 AudioManagerDaemon/test/ControlInterfaceBackdoor.h create mode 100644 AudioManagerDaemon/test/IAmCommandBackdoor.h create mode 100644 AudioManagerDaemon/test/IAmControlBackdoor.h create mode 100644 AudioManagerDaemon/test/IAmRoutingBackdoor.h create mode 100644 AudioManagerDaemon/test/MockIAmCommandSend.h create mode 100644 AudioManagerDaemon/test/MockIAmControlSend.h create mode 100644 AudioManagerDaemon/test/MockIAmRoutingSend.h delete mode 100644 AudioManagerDaemon/test/RoutingInterfaceBackdoor.h delete mode 100644 AudioManagerDaemon/test/controlInterface/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/controlInterface/MockInterfaces.h delete mode 100644 AudioManagerDaemon/test/controlInterface/controlInterfaceTest.cpp delete mode 100644 AudioManagerDaemon/test/controlInterface/controlInterfaceTest.h delete mode 100644 AudioManagerDaemon/test/database/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/database/MockInterfaces.h delete mode 100644 AudioManagerDaemon/test/database/databaseTest.cpp delete mode 100644 AudioManagerDaemon/test/database/databaseTest.h delete mode 100644 AudioManagerDaemon/test/routing/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/routing/MockInterfaces.h delete mode 100644 AudioManagerDaemon/test/routing/routingTest.cpp delete mode 100644 AudioManagerDaemon/test/routing/routingTest.h delete mode 100644 AudioManagerDaemon/test/routingInterface/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/routingInterface/MockRoutingInterface.h delete mode 100644 AudioManagerDaemon/test/routingInterface/routingInterfaceTest.cpp delete mode 100644 AudioManagerDaemon/test/routingInterface/routingInterfaceTest.h delete mode 100644 AudioManagerDaemon/test/sockethandler/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp delete mode 100644 AudioManagerDaemon/test/sockethandler/sockethandlerTest.h delete mode 100644 AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.cpp delete mode 100644 AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.h delete mode 100644 AudioManagerDaemon/test/telnetserver/CMakeLists.txt create mode 100644 PluginCommandInterfaceDbus/include/CAmCommandSenderDbus.h create mode 100644 PluginCommandInterfaceDbus/include/CAmDbusMessageHandler.h create mode 100644 PluginCommandInterfaceDbus/include/CommandInterface.xml delete mode 100644 PluginCommandInterfaceDbus/include/CommandReceiverShadow.h delete mode 100644 PluginCommandInterfaceDbus/include/DBusCommandSender.h delete mode 100644 PluginCommandInterfaceDbus/include/DBusMessageHandler.h create mode 100644 PluginCommandInterfaceDbus/include/IAmCommandReceiverShadow.h delete mode 100644 PluginCommandInterfaceDbus/include/mainpage.h create mode 100644 PluginCommandInterfaceDbus/src/CAmCommandSenderDbus.cpp create mode 100644 PluginCommandInterfaceDbus/src/CAmDbusMessageHandler.cpp delete mode 100644 PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp delete mode 100644 PluginCommandInterfaceDbus/src/DBusCommandSender.cpp delete mode 100644 PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp create mode 100644 PluginCommandInterfaceDbus/src/IAmCommandReceiverShadow.cpp create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.cpp create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.h create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.cpp create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.h create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.cpp create mode 100644 PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.h delete mode 100644 PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.cpp delete mode 100644 PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.h create mode 100644 PluginCommandInterfaceDbus/test/MockIAmCommandReceive.h delete mode 100644 PluginCommandInterfaceDbus/test/MockInterfaces.h delete mode 100644 PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.cpp delete mode 100644 PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.h delete mode 100644 PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.cpp delete mode 100644 PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.h create mode 100644 PluginControlInterface/include/CAmControlSenderBase.h delete mode 100644 PluginControlInterface/include/ControlSender.h create mode 100644 PluginControlInterface/src/CAmControlSenderBase.cpp delete mode 100644 PluginControlInterface/src/ControlSender.cpp create mode 100644 PluginRoutingInterfaceAsync/include/CAmRoutingSenderAsync.h create mode 100644 PluginRoutingInterfaceAsync/include/IAmRoutingReceiverShadow.h delete mode 100644 PluginRoutingInterfaceAsync/include/RoutingReceiverAsyncShadow.h delete mode 100644 PluginRoutingInterfaceAsync/include/RoutingSenderAsyn.h create mode 100644 PluginRoutingInterfaceAsync/src/CAmRoutingSenderAsync.cpp create mode 100644 PluginRoutingInterfaceAsync/src/IAmRoutingReceiverShadow.cpp delete mode 100644 PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp delete mode 100644 PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp create mode 100644 PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.cpp create mode 100644 PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.h create mode 100644 PluginRoutingInterfaceAsync/test/MockIAmRoutingReceive.h delete mode 100644 PluginRoutingInterfaceAsync/test/mocklnterfaces.h delete mode 100644 PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.cpp delete mode 100644 PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.h delete mode 100644 PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsyncInterrupt.cpp create mode 100644 PluginRoutingInterfaceDbus/include/CAmRoutingSenderDbus.h delete mode 100644 PluginRoutingInterfaceDbus/include/RoutingSender.h create mode 100644 PluginRoutingInterfaceDbus/src/CAmRoutingSenderDbus.cpp delete mode 100644 PluginRoutingInterfaceDbus/src/RoutingSender.cpp create mode 100644 cmake/AudioManagerCodestyle.xml delete mode 100644 cmake/AudioManager_Codestyle.xml create mode 100644 include/audiomanagertypes.h create mode 100644 include/command/IAmCommandReceive.h create mode 100644 include/command/IAmCommandSend.h create mode 100644 include/control/IAmControlReceive.h create mode 100644 include/control/IAmControlSend.h create mode 100644 include/projecttypes.h create mode 100644 include/routing/IAmRoutingReceive.h create mode 100644 include/routing/IAmRoutingSend.h create mode 100644 include/shared/CAmDbusWrapper.h create mode 100644 include/shared/CAmDltWrapper.h create mode 100644 include/shared/CAmSerializer.h create mode 100644 include/shared/CAmSocketHandler.h delete mode 100644 includes/CAmSerializer.h delete mode 100644 includes/DLTWrapper.h delete mode 100644 includes/SocketHandler.h delete mode 100644 includes/audiomanagertypes.h delete mode 100644 includes/command/CommandReceiveInterface.h delete mode 100644 includes/command/CommandSendInterface.h delete mode 100644 includes/control/ControlReceiveInterface.h delete mode 100644 includes/control/ControlSendInterface.h delete mode 100644 includes/dbus/CommandInterface.xml delete mode 100644 includes/dbus/DBusWrapper.h delete mode 100644 includes/projecttypes.h delete mode 100644 includes/routing/RoutingReceiveInterface.h delete mode 100644 includes/routing/RoutingSendInterface.h diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt index beb1a74..c0a31b0 100644 --- a/AudioManagerDaemon/CMakeLists.txt +++ b/AudioManagerDaemon/CMakeLists.txt @@ -29,7 +29,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/AudioManager) -set(INCLUDES_FOLDER "include") +set(include_FOLDER "include") pkg_check_modules(SQLITE REQUIRED sqlite3) @@ -39,40 +39,40 @@ ENDIF(WITH_DBUS_WRAPPER) SET(AUDIOMAN_SRCS_CXX src/main.cpp - src/CommandReceiver.cpp - src/CommandSender.cpp - src/ControlReceiver.cpp - src/ControlSender.cpp - src/DatabaseHandler.cpp - src/DatabaseObserver.cpp - src/RoutingReceiver.cpp - src/RoutingSender.cpp - src/SocketHandler.cpp - src/TelnetServer.cpp - src/Router.cpp - src/DLTWrapper.cpp + src/CAmCommandReceiver.cpp + src/CAmCommandSender.cpp + src/CAmControlReceiver.cpp + src/CAmControlSender.cpp + src/CAmDatabaseHandler.cpp + src/CAmDatabaseObserver.cpp + src/CAmRoutingReceiver.cpp + src/CAmRoutingSender.cpp + src/CAmSocketHandler.cpp + src/CAmTelnetServer.cpp + src/CAmRouter.cpp + src/CAmDltWrapper.cpp src/CAmTelnetMenuHelper.cpp ) IF(WITH_DBUS_WRAPPER) SET (AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} - src/DBusWrapper.cpp + src/CAmDbusWrapper.cpp ) ENDIF(WITH_DBUS_WRAPPER) IF(WITH_SOCKETHANDLER_LOOP) SET (AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} - src/SocketHandler.cpp + src/CAmSocketHandler.cpp ) ENDIF(WITH_SOCKETHANDLER_LOOP) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} + ${include_FOLDER} ) IF(WITH_DLT) @@ -127,7 +127,7 @@ INSTALL(TARGETS AudioManager COMPONENT bin ) -INSTALL(DIRECTORY "${AUDIO_INCLUDES_FOLDER}/" +INSTALL(DIRECTORY "${AUDIO_include_FOLDER}/" DESTINATION include COMPONENT dev ) diff --git a/AudioManagerDaemon/include/CAmCommandReceiver.h b/AudioManagerDaemon/include/CAmCommandReceiver.h new file mode 100644 index 0000000..72f72f2 --- /dev/null +++ b/AudioManagerDaemon/include/CAmCommandReceiver.h @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CommandReveiver.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef COMMANDRECEIVER_H_ +#define COMMANDRECEIVER_H_ + +#include +#include + +namespace am +{ + +class CAmDatabaseHandler; +class CAmControlSender; +class CAmDbusWrapper; +class CAmSocketHandler; + +/** + * This class realizes the command Interface + */ +class CAmCommandReceiver: public IAmCommandReceive +{ +public: + CAmCommandReceiver(CAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iControlSender, CAmSocketHandler* iSocketHandler); + CAmCommandReceiver(CAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iControlSender, CAmSocketHandler* iSocketHandler, CAmDbusWrapper* iDBusWrapper); + ~CAmCommandReceiver(); + am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID); + am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID); + am_Error_e setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume); + am_Error_e volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep); + am_Error_e setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState); + am_Error_e setMainSinkSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); + am_Error_e setMainSourceSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); + am_Error_e setSystemProperty(const am_SystemProperty_s& property); + am_Error_e getListMainConnections(std::vector& listConnections) const; + am_Error_e getListMainSinks(std::vector& listMainSinks) const; + am_Error_e getListMainSources(std::vector& listMainSources) const; + am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const; + am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const; + am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; + am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; + am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; + am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const; + am_Error_e getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const; + am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) const; + void getInterfaceVersion(std::string& version) const; + void confirmCommandReady(const uint16_t handle); + void confirmCommandRundown(const uint16_t handle); + + uint16_t getStartupHandle(); //!< returns a startup handle + uint16_t getRundownHandle(); //!< returns a rundown handle + + void waitOnStartup(bool startup); //!< tells the ComandReceiver to start waiting for all handles to be confirmed + void waitOnRundown(bool rundown); //!< tells the ComandReceiver to start waiting for all handles to be confirmed + +private: + CAmDatabaseHandler* mDatabaseHandler; //!< pointer to the databasehandler + CAmControlSender* mControlSender; //!< pointer to the control sender + CAmDbusWrapper* mDBusWrapper; //!< pointer to the dbuswrapper + CAmSocketHandler* mSocketHandler; //!< pointer to the SocketHandler + + uint16_t handleCount; //!< counts all handles + std::vector mListStartupHandles; //!< list of handles that wait for a confirm + std::vector mListRundownHandles; //!< list of handles that wait for a confirm + bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0 + bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0 +}; + +} + +#endif /* COMMANDRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmCommandSender.h b/AudioManagerDaemon/include/CAmCommandSender.h new file mode 100644 index 0000000..d902e96 --- /dev/null +++ b/AudioManagerDaemon/include/CAmCommandSender.h @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CommandSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef COMMANDSENDER_H_ +#define COMMANDSENDER_H_ + +#ifdef UNIT_TEST +#include "../test/IAmCommandBackdoor.h" //we need this for the unit test +#endif + +#include "command/IAmCommandSend.h" + +namespace am +{ + +class CAmCommandReceiver; + + +/** + * This class is used to send data to the CommandInterface. + * All loaded plugins will be called when a callback is invoked. + */ +class CAmCommandSender +{ +public: + CAmCommandSender(const std::vector& listOfPluginDirectories); + ~CAmCommandSender(); + am_Error_e startupInterfaces(CAmCommandReceiver* iCommandReceiver); + void setCommandReady(); + void setCommandRundown(); + void cbNewMainConnection(const am_MainConnectionType_s mainConnection); + void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection); + void cbNewSink(am_SinkType_s sink); + void cbRemovedSink(const am_sinkID_t sink); + void cbNewSource(const am_SourceType_s source); + void cbRemovedSource(const am_sourceID_t source); + void cbNumberOfSinkClassesChanged(); + void cbNumberOfSourceClassesChanged(); + void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); + void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); + void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); + void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); + void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); + void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); + void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); + void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty); + void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); + void getInterfaceVersion(std::string& version) const; + am_Error_e getListPlugins(std::vector& interfaces) const; +#ifdef UNIT_TEST + friend class IAmCommandBackdoor; //this is to get access to the loaded plugins and be able to exchange the interfaces +#endif +private: + void unloadLibraries(void); //!< unload the shared libraries + std::vector mListInterfaces; //!< list of all interfaces + std::vector mListLibraryHandles; //!< list of all library handles. This information is used to unload the plugins correctly. + std::vector mListLibraryNames; //!< list of all library names. This information is used for getListPlugins. + + CAmCommandReceiver *mCommandReceiver; +}; + +} + +#endif /* COMMANDSENDER_H_ */ diff --git a/AudioManagerDaemon/include/CAmControlReceiver.h b/AudioManagerDaemon/include/CAmControlReceiver.h new file mode 100644 index 0000000..af5a0e4 --- /dev/null +++ b/AudioManagerDaemon/include/CAmControlReceiver.h @@ -0,0 +1,131 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmControlReceiver.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef CONTRONLRECEIVER_H_ +#define CONTRONLRECEIVER_H_ + +#include +#include + +namespace am +{ + +class CAmSocketHandler; +class CAmDatabaseHandler; +class CAmRoutingSender; +class CAmCommandSender; +class CAmRouter; + +/** + * This class is used to receive all commands from the control interface + */ +class CAmControlReceiver: public IAmControlReceive +{ +public: + CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter); + ~CAmControlReceiver(); + am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); + am_Error_e connect(am_Handle_s& handle, am_connectionID_t& connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID); + am_Error_e disconnect(am_Handle_s& handle, const am_connectionID_t connectionID); + am_Error_e crossfade(am_Handle_s& handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime); + am_Error_e abortAction(const am_Handle_s handle); + am_Error_e setSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state); + am_Error_e setSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); + am_Error_e setSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time); + am_Error_e setSinkSoundProperties(am_Handle_s& handle, const am_sinkID_t sinkID, const std::vector& soundProperty); + am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); + am_Error_e setSourceSoundProperties(am_Handle_s& handle, const am_sourceID_t sourceID, const std::vector& soundProperty); + am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); + am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); + am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); + am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); + am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); + am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); + am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); + am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID); + am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID); + am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass); + am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass); + am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass); + am_Error_e enterSystemPropertiesListDB(const std::vector& listSystemProperties); + am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID); + am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState); + am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID); + am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID); + am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID); + am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID); + am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); + am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); + am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID); + am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property); + am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID); + am_Error_e removeSinkDB(const am_sinkID_t sinkID); + am_Error_e removeSourceDB(const am_sourceID_t sourceID); + am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID); + am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID); + am_Error_e removeDomainDB(const am_domainID_t domainID); + am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID); + am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID); + am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const; + am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const; + am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const; + am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const; + am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const; + am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const; + am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const; + am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const; + am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const; + am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listCrossfadersID) const; + am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; + am_Error_e getListMainConnections(std::vector& listMainConnections) const; + am_Error_e getListDomains(std::vector& listDomains) const; + am_Error_e getListConnections(std::vector& listConnections) const; + am_Error_e getListSinks(std::vector& listSinks) const; + am_Error_e getListSources(std::vector& listSources) const; + am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; + am_Error_e getListHandles(std::vector& listHandles) const; + am_Error_e getListCrossfaders(std::vector& listCrossfaders) const; + am_Error_e getListGateways(std::vector& listGateways) const; + am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; + am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; + void setCommandReady(); + void setCommandRundown(); + void setRoutingReady(); + void setRoutingRundown(); + void confirmControllerReady(); + void confirmControllerRundown(); + am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler); + void getInterfaceVersion(std::string& version) const; + +private: + CAmDatabaseHandler* mDatabaseHandler; //!< pointer tto the databasehandler + CAmRoutingSender* mRoutingSender; //!< pointer to the routing send interface. + CAmCommandSender* mCommandSender; //!< pointer to the command send interface + CAmSocketHandler* mSocketHandler; //!< pointer to the socketHandler + CAmRouter* mRouter; //!< pointer to the Router +}; + +} + +#endif /* CONTRONLRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmControlSender.h b/AudioManagerDaemon/include/CAmControlSender.h new file mode 100644 index 0000000..ddc8cf3 --- /dev/null +++ b/AudioManagerDaemon/include/CAmControlSender.h @@ -0,0 +1,103 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmControlSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef CONTROLSENDER_H_ +#define CONTROLSENDER_H_ + +#ifdef UNIT_TEST +#include "../test/IAmControlBackdoor.h" +#endif + +#include "control/IAmControlSend.h" + +namespace am +{ + +/** + * sends data to the commandInterface, takes the file of the library that needs to be loaded + */ +class CAmControlSender +{ +public: + CAmControlSender(std::string controlPluginFile); + ~CAmControlSender(); + am_Error_e startupController(IAmControlReceive* controlreceiveinterface) ; + void setControllerReady() ; + void setControllerRundown() ; + am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) ; + am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) ; + am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) ; + am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) ; + am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property) ; + am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) ; + am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) ; + am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) ; + am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID) ; + am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID) ; + void hookSystemDomainRegistrationComplete(const am_domainID_t domainID) ; + am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) ; + am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID) ; + am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ; + am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) ; + am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ; + am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ; + am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ; + am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) ; + void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) ; + void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) ; + void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) ; + void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability) ; + void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability) ; + void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) ; + void hookSystemReceiveEarlyData(const std::vector& data) ; + void hookSystemSpeedChange(const am_speed_t speed) ; + void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) ; + void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) ; + void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) ; + void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) ; + void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) ; + void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) ; + void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) ; + am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats) ; + void getInterfaceVersion(std::string& version) const ; + void confirmCommandReady() ; + void confirmRoutingReady() ; + void confirmCommandRundown() ; + void confirmRoutingRundown() ; + +#ifdef UNIT_TEST + friend class IAmControlBackdoor; +#endif +private: + void* mlibHandle; //!< pointer to the loaded control plugin interface + IAmControlSend* mController; //!< pointer to the ControlSend interface +}; + +} + +#endif /* CONTROLSENDER_H_ */ diff --git a/AudioManagerDaemon/include/CAmDatabaseHandler.h b/AudioManagerDaemon/include/CAmDatabaseHandler.h new file mode 100644 index 0000000..ceaff88 --- /dev/null +++ b/AudioManagerDaemon/include/CAmDatabaseHandler.h @@ -0,0 +1,280 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDatabaseHandler.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef DATABASEHANDLER_H_ +#define DATABASEHANDLER_H_ + +#include "audiomanagertypes.h" +#include +#include +#include + +namespace am +{ + +class CAmDatabaseObserver; +class CAmRoutingTree; +class CAmRoutingTreeItem; + +#define DYNAMIC_ID_BOUNDARY 100 //!< the value below is reserved for staticIDs, the value above will be assigned to dynamically registered items +//todo: check the enum values before entering & changing in the database. +//todo: change asserts for dynamic boundary checks into failure answers.# +//todo: check autoincrement boundary and set to 16bit limits +//todo: If the sink is part of a gateway, the listconnectionFormats is copied to the gatewayInformation. Check this statement for sinks & sources +//todo: exchange last_insert_row id to be more safe +//todo: create test to ensure uniqueness of names throughout the database +//todo: enforce the uniqueness of names + +/** + * This class handles and abstracts the database + */ +class CAmDatabaseHandler +{ +public: + CAmDatabaseHandler(std::string databasePath); + ~CAmDatabaseHandler(); + am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); + am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); + am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); + am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); + am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); + am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID); + am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID); + am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID); + am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass); + am_Error_e enterSystemProperties(const std::vector& listSystemProperties); + am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID); + am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState); + am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID); + am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID); + am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID); + am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID); + am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); + am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); + am_Error_e changeSourceSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sourceID_t sourceID); + am_Error_e changeSinkSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sinkID_t sinkID); + am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID); + am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property); + am_Error_e changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID); + am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass); + am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass); + am_Error_e changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay); + am_Error_e changeConnectionFinal(const am_connectionID_t connectionID); + am_Error_e changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState); + am_Error_e changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume); + am_Error_e changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume); + am_Error_e changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink); + am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID); + am_Error_e removeSinkDB(const am_sinkID_t sinkID); + am_Error_e removeSourceDB(const am_sourceID_t sourceID); + am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID); + am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID); + am_Error_e removeDomainDB(const am_domainID_t domainID); + am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID); + am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID); + am_Error_e removeConnection(const am_connectionID_t connectionID); + am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const; + am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const; + am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const; + am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const; + am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const; + am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const; + am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const; + am_Error_e getSinkVolume(const am_sinkID_t sinkID, am_volume_t& volume) const; + am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const; + am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t& value) const; + am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t& value) const; + am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const; + am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const; + am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; + am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; + am_Error_e getListMainConnections(std::vector& listMainConnections) const; + am_Error_e getListDomains(std::vector& listDomains) const; + am_Error_e getListConnections(std::vector& listConnections) const; + am_Error_e getListSinks(std::vector& listSinks) const; + am_Error_e getListSources(std::vector& lisSources) const; + am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; + am_Error_e getListCrossfaders(std::vector& listCrossfaders) const; + am_Error_e getListGateways(std::vector& listGateways) const; + am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; + am_Error_e getListVisibleMainConnections(std::vector& listConnections) const; + am_Error_e getListMainSinks(std::vector& listMainSinks) const; + am_Error_e getListMainSources(std::vector& listMainSources) const; + am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const; + am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const; + am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; + am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const; + am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const; + am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const; + am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const; + am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const; + am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const; + am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const; + am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e state) const; + am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector& flatTree); + am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID); + am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID); + am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID); + am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); + am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); + /** + * checks for a certain mainConnection + * @param mainConnectionID to be checked for + * @return true if it exists + */ + bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const; + + /** + * checks if a CrossFader exists + * @param crossfaderID the ID of the crossfader to be checked + * @return true if exists + */ + bool existcrossFader(const am_crossfaderID_t crossfaderID) const; + + /** + * checks if a connection already exists. + * Only takes sink, source and format information for search! + * @param connection the connection to be checked + * @return true if connections exists + */ + bool existConnection(const am_Connection_s connection); + + /** + * checks if a connection with the given ID exists + * @param connectionID + * @return true if connection exits + */ + bool existConnectionID(const am_connectionID_t connectionID); + /** + * checks for a certain Source + * @param sourceID to be checked for + * @return true if it exists + */ + bool existSource(const am_sourceID_t sourceID) const; + + /** + * checks if a source name or ID exists + * @param sourceID the sourceID + * @param name the name + * @return true if it exits + */ + bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const; + + /** + * checks if a name exits + * @param name the name + * @return true if it exits + */ + bool existSourceName(const std::string& name) const; + /** + * checks for a certain Sink + * @param sinkID to be checked for + * @return true if it exists + */ + bool existSink(const am_sinkID_t sinkID) const; + + /** + * checks if a sink with the ID or the name exists + * @param sinkID the ID + * @param name the name + * @return true if it exists. + */ + bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const; + + /** + * checks if a sink with the name exists + * @param name the name + * @return true if it exists + */ + bool existSinkName(const std::string& name) const; + + /** + * checks for a certain domain + * @param domainID to be checked for + * @return true if it exists + */ + bool existDomain(const am_domainID_t domainID) const; + + /** + * checks for certain gateway + * @param gatewayID to be checked for + * @return true if it exists + */ + bool existGateway(const am_gatewayID_t gatewayID) const; + + /** + * checks for certain SinkClass + * @param sinkClassID + * @return true if it exists + */ + bool existSinkClass(const am_sinkClass_t sinkClassID) const; + + /** + * checks for certain sourceClass + * @param sourceClassID + * @return true if it exists + */ + bool existSourceClass(const am_sourceClass_t sourceClassID) const; + + /** + * registers the Observer at the Database + * @param iObserver pointer to the observer + */ + void registerObserver(CAmDatabaseObserver *iObserver); + + /** + * gives information about the visibility of a source + * @param sourceID the sourceID + * @return true if source is visible + */ + bool sourceVisible(const am_sourceID_t sourceID) const; + + /** + * gives information about the visibility of a sink + * @param sinkID the sinkID + * @return true if source is visible + */ + bool sinkVisible(const am_sinkID_t sinkID) const; + +private: + am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; + bool sqQuery(const std::string& query); + bool openDatabase(); //!< opens the database + void createTables(); //!< creates all tables from the static table + sqlite3 *mDatabase; //!< pointer to the database + std::string mPath; //!< path to the database + CAmDatabaseObserver *mDatabaseObserver; //!< pointer to the Observer + bool mFirstStaticSink; + bool mFirstStaticSource; + bool mFirstStaticGateway; + bool mFirstStaticSinkClass; + bool mFirstStaticSourceClass; + bool mFirstStaticCrossfader; + typedef std::map > ListConnectionFormat; //!< type for list of connection formats + ListConnectionFormat mListConnectionFormat; //!< list of connection formats +}; + +} + +#endif /* DATABASEHANDLER_H_ */ diff --git a/AudioManagerDaemon/include/CAmDatabaseObserver.h b/AudioManagerDaemon/include/CAmDatabaseObserver.h new file mode 100644 index 0000000..430f061 --- /dev/null +++ b/AudioManagerDaemon/include/CAmDatabaseObserver.h @@ -0,0 +1,83 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDatabaseObserver.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef DATABASEOBSERVER_H_ +#define DATABASEOBSERVER_H_ + +#include +#include +#include "shared/CAmSerializer.h" + +namespace am +{ + +class CAmTelnetServer; +class CAmCommandSender; +class CAmRoutingSender; +class CAmSocketHandler; + +/** + * This class observes the Database and notifies other classes about important events, mainly the CommandSender. + */ + +class CAmDatabaseObserver +{ +public: + CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler); + CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler, CAmTelnetServer *iTelnetServer); + ~CAmDatabaseObserver(); + void numberOfSinkClassesChanged(); + void numberOfSourceClassesChanged(); + void newSink(const am_Sink_s& sink); + void newSource(const am_Source_s& source); + void newDomain(const am_Domain_s& domain); + void newGateway(const am_Gateway_s& gateway); + void newCrossfader(const am_Crossfader_s& crossfader); + void newMainConnection(const am_MainConnectionType_s& mainConnection); + void removedMainConnection(const am_mainConnectionID_t mainConnection); + void removedSink(const am_sinkID_t sinkID, const bool visible); + void removedSource(const am_sourceID_t sourceID, const bool visible); + void removeDomain(const am_domainID_t domainID); + void removeGateway(const am_gatewayID_t gatewayID); + void removeCrossfader(const am_crossfaderID_t crossfaderID); + void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); + void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty); + void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty); + void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); + void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); + void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); + void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); + void systemPropertyChanged(const am_SystemProperty_s& SystemProperty); + void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time); + +private: + CAmCommandSender *mCommandSender; //!< pointer to the comandSender + CAmRoutingSender* mRoutingSender; //!< pointer to the routingSender + CAmTelnetServer* mTelnetServer; //!< pointer to the telnetserver + CAmSerializer mSerializer; +}; + +} + +#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmRouter.h b/AudioManagerDaemon/include/CAmRouter.h new file mode 100644 index 0000000..ba13bf1 --- /dev/null +++ b/AudioManagerDaemon/include/CAmRouter.h @@ -0,0 +1,84 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRouter.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef ROUTER_H_ +#define ROUTER_H_ + +#include + +namespace am +{ + +class CAmDatabaseHandler; +class CAmControlSender; + +class CAmRouter +{ +public: + CAmRouter(CAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); + am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); + ~CAmRouter(); + +private: + am_Error_e findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector& listRoute, std::vector::iterator routeIterator, std::vector::iterator gatewayIterator); + void listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& listFormats) const; + void listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_ConnectionFormat_e sinkConnectionFormat, std::vector& listFormats) const; + CAmDatabaseHandler* mDatabaseHandler; + CAmControlSender* mControlSender; +}; + +class CAmRoutingTreeItem +{ +public: + CAmRoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID = 0, CAmRoutingTreeItem *parent = 0); + void appendChild(CAmRoutingTreeItem *newChild); + void returnChildItems(std::vector listChildItems); + am_domainID_t returnDomainID() const; + am_gatewayID_t returnGatewayID() const; + virtual ~CAmRoutingTreeItem(); + CAmRoutingTreeItem* returnParent() const; +private: + std::vector mListChildItems; //!< List of all child items + am_domainID_t mDomainID; //!< the domain ID of the item + am_gatewayID_t mGatewayID; //!< the gateway Id + CAmRoutingTreeItem *mParentItem; //!< pointer to the parent item +}; + +class CAmRoutingTree +{ +public: + CAmRoutingTree(const am_domainID_t rootDomainID); + CAmRoutingTreeItem* insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent); + void getRoute(CAmRoutingTreeItem* targetItem, std::vector& listGateways); + am_domainID_t returnRootDomainID() const; + CAmRoutingTreeItem* returnRootItem(); + virtual ~CAmRoutingTree(); +private: + CAmRoutingTreeItem mRootItem; //!< pointer to root item + std::vector mListChild; //!< list of all childs +}; + +} /* namespace am */ +#endif /* ROUTER_H_ */ + diff --git a/AudioManagerDaemon/include/CAmRoutingReceiver.h b/AudioManagerDaemon/include/CAmRoutingReceiver.h new file mode 100644 index 0000000..dfacc3b --- /dev/null +++ b/AudioManagerDaemon/include/CAmRoutingReceiver.h @@ -0,0 +1,112 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRoutingReceiver.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef ROUTINGRECEIVER_H_ +#define ROUTINGRECEIVER_H_ + +#include +#include + +namespace am +{ + +class CAmSocketHandler; +class CAmDbusWrapper; +class CAmDatabaseHandler; +class CAmRoutingSender; +class CAmControlSender; + +/** + * Implements the Receiving side of the RoutingPlugins. + */ +class CAmRoutingReceiver: public IAmRoutingReceive +{ +public: + CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler); + CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper); + ~CAmRoutingReceiver(); + void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); + void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); + void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); + void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); + void ackSetSourceState(const am_Handle_s handle, const am_Error_e error); + void ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); + void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); + void ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error); + void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); + void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error); + void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); + void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); + am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID); + am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID); + am_Error_e deregisterDomain(const am_domainID_t domainID); + am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); + am_Error_e deregisterGateway(const am_gatewayID_t gatewayID); + am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID); + am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID); + am_Error_e deregisterSink(const am_sinkID_t sinkID); + am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID); + am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID); + am_Error_e deregisterSource(const am_sourceID_t sourceID); + am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); + am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID); + am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); + am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); + void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); + void hookDomainRegistrationComplete(const am_domainID_t domainID); + void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); + void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability); + void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState); + void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay); + void sendChangedData(const std::vector& earlyData); + am_Error_e getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const; + am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) const; + void getInterfaceVersion(std::string& version) const; + void confirmRoutingReady(const uint16_t handle); + void confirmRoutingRundown(const uint16_t handle); + + uint16_t getStartupHandle(); //!< returns a startup handle + uint16_t getRundownHandle(); //!< returns a rundown handle + + void waitOnStartup(bool startup); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed + void waitOnRundown(bool rundown); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed + +private: + CAmDatabaseHandler *mDatabaseHandler; //!< pointer to the databaseHandler + CAmRoutingSender *mRoutingSender; //!< pointer to the routingSender + CAmControlSender *mControlSender; //!< pointer to the controlSender + CAmSocketHandler *mSocketHandler; //!< pointer to sockethandler + CAmDbusWrapper *mDBusWrapper; //!< pointer to dbuswrapper + + uint16_t handleCount; //!< counts all handles + std::vector mListStartupHandles; //!< list of handles that wait for a confirm + std::vector mListRundownHandles; //!< list of handles that wait for a confirm + bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0 + bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0 + +}; + +} + +#endif /* ROUTINGRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmRoutingSender.h b/AudioManagerDaemon/include/CAmRoutingSender.h new file mode 100644 index 0000000..c6a7677 --- /dev/null +++ b/AudioManagerDaemon/include/CAmRoutingSender.h @@ -0,0 +1,202 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRoutingSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef ROUTINGSENDER_H_ +#define ROUTINGSENDER_H_ + +#include "routing/IAmRoutingSend.h" +#include + +#ifdef UNIT_TEST //this is needed to test RoutingSender +#include "../test/IAmRoutingBackdoor.h" +#endif + +namespace am +{ + +class CAmRoutingReceiver; + +/** + * Implements the RoutingSendInterface. Loads all plugins and dispatches calls to the plugins + */ +class CAmRoutingSender +{ +public: + CAmRoutingSender(const std::vector& listOfPluginDirectories); + ~CAmRoutingSender(); + + /** + * removes a handle from the list + * @param handle to be removed + * @return E_OK in case of success + */ + am_Error_e removeHandle(const am_Handle_s& handle); + + /** + * @author Christian + * this adds the domain to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. + * This must be done whenever a domain is registered. + */ + am_Error_e addDomainLookup(const am_Domain_s& domainData); + /** + * @author Christian + * this adds the Source to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. + * This must be done whenever a Source is registered. + */ + am_Error_e addSourceLookup(const am_Source_s& sourceData); + /** + * @author Christian + * this adds the Sink to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. + * This must be done whenever a Sink is registered. + */ + am_Error_e addSinkLookup(const am_Sink_s& sinkData); + /** + * @author Christian + * this adds the Crossfader to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. + * This must be done whenever a Crossfader is registered. + */ + am_Error_e addCrossfaderLookup(const am_Crossfader_s& crossfaderData); + /** + * @author Christian + * this removes the Domain to the lookup table of the Router. This must be done everytime a domain is deregistered. + */ + am_Error_e removeDomainLookup(const am_domainID_t domainID); + /** + * @author Christian + * this removes the Source to the lookup table of the Router. This must be done everytime a source is deregistered. + */ + am_Error_e removeSourceLookup(const am_sourceID_t sourceID); + /** + * @author Christian + * this removes the Sink to the lookup table of the Router. This must be done everytime a sink is deregistered. + */ + am_Error_e removeSinkLookup(const am_sinkID_t sinkID); + /** + * @author Christian + * this removes the Crossfader to the lookup table of the Router. This must be done everytime a crossfader is deregistered. + */ + am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID); + am_Error_e startupInterfaces(CAmRoutingReceiver* iRoutingReceiver); + void setRoutingReady(); + void setRoutingRundown(); + am_Error_e asyncAbort(const am_Handle_s& handle); + am_Error_e asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); + am_Error_e asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID); + am_Error_e asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); + am_Error_e asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); + am_Error_e asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state); + am_Error_e asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); + am_Error_e asyncSetSourceSoundProperties(am_Handle_s& handle, const std::vector& listSoundProperties, const am_sourceID_t sourceID); + am_Error_e asyncSetSinkSoundProperties(am_Handle_s& handle, const std::vector& listSoundProperties, const am_sinkID_t sinkID); + am_Error_e asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); + am_Error_e asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time); + am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); + am_Error_e getListHandles(std::vector & listHandles) const; + am_Error_e getListPlugins(std::vector& interfaces) const; + void getInterfaceVersion(std::string& version) const; + + //!< is used to pair interfaces with busnames + struct InterfaceNamePairs + { + IAmRoutingSend* routingInterface; + std::string busName; + }; + + //!< is used to store data related to handles + class am_handleData_c + { + public: + union + { + am_sinkID_t sinkID; + am_sourceID_t sourceID; + am_crossfaderID_t crossfaderID; + am_connectionID_t connectionID; + }; + union + { + am_SoundProperty_s soundPropery; + am_SourceState_e sourceState; + am_volume_t volume; + am_HotSink_e hotSink; + std::vector* soundProperties; + }; + + }; + +#ifdef UNIT_TEST //this is needed to test RoutingSender + friend class IAmRoutingBackdoor; +#endif + + /** + * returns the data that belong to handles + * @param handle the handle + * @return a class holding the handle data + */ + am_handleData_c returnHandleData(const am_Handle_s handle) const; + +private: + + //!< is needed to sort the handles in the map + struct comparator + { + bool operator()(const am_Handle_s& a, const am_Handle_s& b) const + { + return (a.handle < b.handle); + } + }; + + /** + * creates a handle and adds it to the list of handles + * @param handleData the data that should be saves together with the handle + * @param type the type of handle to be created + * @return the handle + */ + am_Handle_s createHandle(const am_handleData_c& handleData, const am_Handle_e type); + void unloadLibraries(void); //!< unloads all loaded plugins + + typedef std::map DomainInterfaceMap; //!< maps domains to interfaces + typedef std::map SinkInterfaceMap; //!< maps sinks to interfaces + typedef std::map SourceInterfaceMap; //!< maps sources to interfaces + typedef std::map CrossfaderInterfaceMap; //!< maps crossfaders to interfaces + typedef std::map ConnectionInterfaceMap; //!< maps connections to interfaces + typedef std::map HandleInterfaceMap; //!< maps handles to interfaces + typedef std::map HandlesMap; //!< maps handleData to handles + + int16_t mHandleCount; //!< is used to create handles + HandlesMap mlistActiveHandles; //!< list of all currently "running" handles. + std::vector mListLibraryHandles; //!< list of all loaded pluginInterfaces + std::vector mListInterfaces; //!< list of busname/interface relation + ConnectionInterfaceMap mMapConnectionInterface; //!< map of connection to interfaces + CrossfaderInterfaceMap mMapCrossfaderInterface; //!< map of crossfaders to interface + DomainInterfaceMap mMapDomainInterface; //!< map of domains to interfaces + SinkInterfaceMap mMapSinkInterface; //!< map of sinks to interfaces + SourceInterfaceMap mMapSourceInterface; //!< map of sources to interfaces + HandleInterfaceMap mMapHandleInterface; //!< map of handles to interfaces + CAmRoutingReceiver *mRoutingReceiver; +}; + +} + +#endif /* ROUTINGSENDER_H_ */ diff --git a/AudioManagerDaemon/include/CAmTelnetMenuHelper.h b/AudioManagerDaemon/include/CAmTelnetMenuHelper.h index 5322526..54a0ee5 100644 --- a/AudioManagerDaemon/include/CAmTelnetMenuHelper.h +++ b/AudioManagerDaemon/include/CAmTelnetMenuHelper.h @@ -41,17 +41,17 @@ namespace am { -class TelnetServer; -class DatabaseHandler; -class CommandSender; -class RoutingSender; -class ControlSender; -class CommandReceiver; -class RoutingReceiver; -class ControlReceiver; - -class Router; -class SocketHandler; +class CAmTelnetServer; +class CAmDatabaseHandler; +class CAmCommandSender; +class CAmRoutingSender; +class CAmControlSender; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; + +class CAmRouter; +class CAmSocketHandler; class CAmTelnetMenuHelper { @@ -62,7 +62,7 @@ public: eRootState = 0, eListState, eInfoState, eGetState, eSetState }; - CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, TelnetServer *iTelnetServer); + CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer); ~CAmTelnetMenuHelper(); @@ -171,16 +171,16 @@ private: std::map mCurrentMainStateMap; static CAmTelnetMenuHelper* instance; - TelnetServer *mpTelenetServer; - SocketHandler *mpSocketHandler; - CommandSender *mpCommandSender; - CommandReceiver *mpCommandReceiver; - RoutingSender *mpRoutingSender; - RoutingReceiver *mpRoutingReceiver; - ControlSender *mpControlSender; - ControlReceiver *mpControlReceiver; - DatabaseHandler *mpDatabasehandler; - Router *mpRouter; + CAmTelnetServer *mpTelenetServer; + CAmSocketHandler *mpSocketHandler; + CAmCommandSender *mpCommandSender; + CAmCommandReceiver *mpCommandReceiver; + CAmRoutingSender *mpRoutingSender; + CAmRoutingReceiver *mpRoutingReceiver; + CAmControlSender *mpControlSender; + CAmControlReceiver *mpControlReceiver; + CAmDatabaseHandler *mpDatabasehandler; + CAmRouter *mpRouter; tCommandMap mRootCommands; tCommandMap mListCommands; diff --git a/AudioManagerDaemon/include/CAmTelnetServer.h b/AudioManagerDaemon/include/CAmTelnetServer.h new file mode 100644 index 0000000..f7bf274 --- /dev/null +++ b/AudioManagerDaemon/include/CAmTelnetServer.h @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmTelnetServer.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef TELNETSERVER_H_ +#define TELNETSERVER_H_ + +#include "shared/CAmSocketHandler.h" +#include "CAmTelnetMenuHelper.h" +#include +#include + +namespace am +{ + +class CAmDatabaseHandler; +class CAmCommandSender; +class CAmRoutingSender; +class CAmControlSender; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; +class CAmRouter; +class CAmTelnetMenuHelper; + +class CAmTelnetServer +{ +public: + CAmTelnetServer(CAmSocketHandler *iSocketHandler, + CAmCommandSender *iCommandSender, + CAmCommandReceiver *iCommandReceiver, + CAmRoutingSender *iRoutingSender, + CAmRoutingReceiver *iRoutingReceiver, + CAmControlSender *iControlSender, + CAmControlReceiver *iControlReceiver, + CAmDatabaseHandler *iDatabasehandler, + CAmRouter *iRouter, + unsigned int servPort, + unsigned int maxConnections); + + ~CAmTelnetServer(); + void connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void* userData); + void disconnectClient(int filedescriptor); + void receiveData(const pollfd pfd, const sh_pollHandle_t handle, void* userData); + bool dispatchData(const sh_pollHandle_t handle, void* userData); + bool check(const sh_pollHandle_t handle, void* userData); + TAmShPollFired telnetConnectFiredCB; + TAmShPollFired telnetReceiveFiredCB; + TAmShPollDispatch telnetDispatchCB; + TAmShPollCheck telnetCheckCB; +private: + + typedef void (*CommandPrototype)(std::vector& msg,int filedescriptor); + typedef std::map mMapCommand_t; + + void sliceCommand(const std::string& string,std::string& command,std::queue& msg); + mMapCommand_t createCommandMap(); + struct connection_s + { + int filedescriptor; + sh_pollHandle_t handle; + }; + + static CAmTelnetServer* instance; + CAmSocketHandler *mSocketHandler; + CAmCommandSender *mCommandSender; + CAmCommandReceiver *mCommandReceiver; + CAmRoutingSender *mRoutingSender; + CAmRoutingReceiver *mRoutingReceiver; + CAmControlSender *mControlSender; + CAmControlReceiver *mControlReceiver; + CAmDatabaseHandler *mDatabasehandler; + CAmRouter *mRouter; + sh_pollHandle_t mConnecthandle; + std::queue mMsgList; + std::vector mListConnections; + int mConnectFD; + unsigned int mServerPort; + unsigned int mMaxConnections; + CAmTelnetMenuHelper mTelnetMenuHelper; + +}; + +} /* namespace am */ +#endif /* TELNETSERVER_H_ */ diff --git a/AudioManagerDaemon/include/CommandReceiver.h b/AudioManagerDaemon/include/CommandReceiver.h deleted file mode 100644 index 5279a31..0000000 --- a/AudioManagerDaemon/include/CommandReceiver.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommandReveiver.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef COMMANDRECEIVER_H_ -#define COMMANDRECEIVER_H_ - -#include -#include - -namespace am -{ - -class DatabaseHandler; -class ControlSender; -class DBusWrapper; -class SocketHandler; - -/** - * This class realizes the command Interface - */ -class CommandReceiver: public CommandReceiveInterface -{ -public: - CommandReceiver(DatabaseHandler* iDatabaseHandler, ControlSender* iControlSender, SocketHandler* iSocketHandler); - CommandReceiver(DatabaseHandler* iDatabaseHandler, ControlSender* iControlSender, SocketHandler* iSocketHandler, DBusWrapper* iDBusWrapper); - ~CommandReceiver(); - am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID); - am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID); - am_Error_e setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume); - am_Error_e volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep); - am_Error_e setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState); - am_Error_e setMainSinkSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); - am_Error_e setMainSourceSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); - am_Error_e setSystemProperty(const am_SystemProperty_s& property); - am_Error_e getListMainConnections(std::vector& listConnections) const; - am_Error_e getListMainSinks(std::vector& listMainSinks) const; - am_Error_e getListMainSources(std::vector& listMainSources) const; - am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const; - am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const; - am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; - am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; - am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; - am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const; - am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const; - am_Error_e getSocketHandler(SocketHandler*& socketHandler) const; - void getInterfaceVersion(std::string& version) const; - void confirmCommandReady(const uint16_t handle); - void confirmCommandRundown(const uint16_t handle); - - uint16_t getStartupHandle(); //!< returns a startup handle - uint16_t getRundownHandle(); //!< returns a rundown handle - - void waitOnStartup(bool startup); //!< tells the ComandReceiver to start waiting for all handles to be confirmed - void waitOnRundown(bool rundown); //!< tells the ComandReceiver to start waiting for all handles to be confirmed - -private: - DatabaseHandler* mDatabaseHandler; //!< pointer to the databasehandler - ControlSender* mControlSender; //!< pointer to the control sender - DBusWrapper* mDBusWrapper; //!< pointer to the dbuswrapper - SocketHandler* mSocketHandler; //!< pointer to the SocketHandler - - uint16_t handleCount; //!< counts all handles - std::vector mListStartupHandles; //!< list of handles that wait for a confirm - std::vector mListRundownHandles; //!< list of handles that wait for a confirm - bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0 - bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0 -}; - -} - -#endif /* COMMANDRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CommandSender.h b/AudioManagerDaemon/include/CommandSender.h deleted file mode 100644 index 0a8d2b2..0000000 --- a/AudioManagerDaemon/include/CommandSender.h +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommandSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef COMMANDSENDER_H_ -#define COMMANDSENDER_H_ - -#ifdef UNIT_TEST -#include "../test/CommandInterfaceBackdoor.h" //we need this for the unit test -#endif - -#include "command/CommandSendInterface.h" - -namespace am -{ - -class CommandReceiver; - - -/** - * This class is used to send data to the CommandInterface. - * All loaded plugins will be called when a callback is invoked. - */ -class CommandSender -{ -public: - CommandSender(const std::vector& listOfPluginDirectories); - ~CommandSender(); - am_Error_e startupInterfaces(CommandReceiver* iCommandReceiver); - void setCommandReady(); - void setCommandRundown(); - void cbNewMainConnection(const am_MainConnectionType_s mainConnection); - void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection); - void cbNewSink(am_SinkType_s sink); - void cbRemovedSink(const am_sinkID_t sink); - void cbNewSource(const am_SourceType_s source); - void cbRemovedSource(const am_sourceID_t source); - void cbNumberOfSinkClassesChanged(); - void cbNumberOfSourceClassesChanged(); - void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); - void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); - void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); - void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); - void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); - void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); - void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); - void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty); - void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); - void getInterfaceVersion(std::string& version) const; - am_Error_e getListPlugins(std::vector& interfaces) const; -#ifdef UNIT_TEST - friend class CommandInterfaceBackdoor; //this is to get access to the loaded plugins and be able to exchange the interfaces -#endif -private: - void unloadLibraries(void); //!< unload the shared libraries - std::vector mListInterfaces; //!< list of all interfaces - std::vector mListLibraryHandles; //!< list of all library handles. This information is used to unload the plugins correctly. - std::vector mListLibraryNames; //!< list of all library names. This information is used for getListPlugins. - - CommandReceiver *mCommandReceiver; -}; - -} - -#endif /* COMMANDSENDER_H_ */ diff --git a/AudioManagerDaemon/include/ControlReceiver.h b/AudioManagerDaemon/include/ControlReceiver.h deleted file mode 100644 index dfb0695..0000000 --- a/AudioManagerDaemon/include/ControlReceiver.h +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file ControlReceiver.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef CONTRONLRECEIVER_H_ -#define CONTRONLRECEIVER_H_ - -#include -#include - -namespace am -{ - -class SocketHandler; -class DatabaseHandler; -class RoutingSender; -class CommandSender; -class Router; - -/** - * This class is used to receive all commands from the control interface - */ -class ControlReceiver: public ControlReceiveInterface -{ -public: - ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender, SocketHandler *iSocketHandler, Router* iRouter); - ~ControlReceiver(); - am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - am_Error_e connect(am_Handle_s& handle, am_connectionID_t& connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID); - am_Error_e disconnect(am_Handle_s& handle, const am_connectionID_t connectionID); - am_Error_e crossfade(am_Handle_s& handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime); - am_Error_e abortAction(const am_Handle_s handle); - am_Error_e setSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state); - am_Error_e setSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); - am_Error_e setSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time); - am_Error_e setSinkSoundProperties(am_Handle_s& handle, const am_sinkID_t sinkID, const std::vector& soundProperty); - am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); - am_Error_e setSourceSoundProperties(am_Handle_s& handle, const am_sourceID_t sourceID, const std::vector& soundProperty); - am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); - am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); - am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); - am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); - am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); - am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); - am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID); - am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass); - am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass); - am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass); - am_Error_e enterSystemPropertiesListDB(const std::vector& listSystemProperties); - am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID); - am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState); - am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID); - am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID); - am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID); - am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID); - am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); - am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); - am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID); - am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property); - am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID); - am_Error_e removeSinkDB(const am_sinkID_t sinkID); - am_Error_e removeSourceDB(const am_sourceID_t sourceID); - am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID); - am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID); - am_Error_e removeDomainDB(const am_domainID_t domainID); - am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID); - am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID); - am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const; - am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const; - am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const; - am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const; - am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const; - am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const; - am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const; - am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const; - am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const; - am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listCrossfadersID) const; - am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; - am_Error_e getListMainConnections(std::vector& listMainConnections) const; - am_Error_e getListDomains(std::vector& listDomains) const; - am_Error_e getListConnections(std::vector& listConnections) const; - am_Error_e getListSinks(std::vector& listSinks) const; - am_Error_e getListSources(std::vector& listSources) const; - am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; - am_Error_e getListHandles(std::vector& listHandles) const; - am_Error_e getListCrossfaders(std::vector& listCrossfaders) const; - am_Error_e getListGateways(std::vector& listGateways) const; - am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; - am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; - void setCommandReady(); - void setCommandRundown(); - void setRoutingReady(); - void setRoutingRundown(); - void confirmControllerReady(); - void confirmControllerRundown(); - am_Error_e getSocketHandler(SocketHandler*& socketHandler); - void getInterfaceVersion(std::string& version) const; - -private: - DatabaseHandler* mDatabaseHandler; //!< pointer tto the databasehandler - RoutingSender* mRoutingSender; //!< pointer to the routing send interface. - CommandSender* mCommandSender; //!< pointer to the command send interface - SocketHandler* mSocketHandler; //!< pointer to the socketHandler - Router* mRouter; //!< pointer to the Router -}; - -} - -#endif /* CONTRONLRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/ControlSender.h b/AudioManagerDaemon/include/ControlSender.h deleted file mode 100644 index 6e04d48..0000000 --- a/AudioManagerDaemon/include/ControlSender.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file ControlSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef CONTROLSENDER_H_ -#define CONTROLSENDER_H_ - -#ifdef UNIT_TEST -#include "../test/ControlInterfaceBackdoor.h" -#endif - -#include "control/ControlSendInterface.h" - -namespace am -{ - -/** - * sends data to the commandInterface, takes the file of the library that needs to be loaded - */ -class ControlSender -{ -public: - ControlSender(std::string controlPluginFile); - ~ControlSender(); - am_Error_e startupController(ControlReceiveInterface* controlreceiveinterface) ; - void setControllerReady() ; - void setControllerRundown() ; - am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) ; - am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) ; - am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) ; - am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) ; - am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property) ; - am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) ; - am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) ; - am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) ; - am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID) ; - am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID) ; - void hookSystemDomainRegistrationComplete(const am_domainID_t domainID) ; - am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) ; - am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID) ; - am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ; - am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) ; - am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ; - am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ; - am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ; - am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) ; - void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) ; - void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) ; - void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) ; - void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability) ; - void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability) ; - void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) ; - void hookSystemReceiveEarlyData(const std::vector& data) ; - void hookSystemSpeedChange(const am_speed_t speed) ; - void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) ; - void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) ; - void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) ; - void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) ; - void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) ; - void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) ; - void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) ; - void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) ; - void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) ; - void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) ; - void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) ; - am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats) ; - void getInterfaceVersion(std::string& version) const ; - void confirmCommandReady() ; - void confirmRoutingReady() ; - void confirmCommandRundown() ; - void confirmRoutingRundown() ; - -#ifdef UNIT_TEST - friend class ControlInterfaceBackdoor; -#endif -private: - void* mlibHandle; //!< pointer to the loaded control plugin interface - ControlSendInterface* mController; //!< pointer to the ControlSend interface -}; - -} - -#endif /* CONTROLSENDER_H_ */ diff --git a/AudioManagerDaemon/include/DAmDoxygenMainPage.h b/AudioManagerDaemon/include/DAmDoxygenMainPage.h new file mode 100644 index 0000000..e27b233 --- /dev/null +++ b/AudioManagerDaemon/include/DAmDoxygenMainPage.h @@ -0,0 +1,115 @@ +/** + * \mainpage + * + * + * \image html genivilogo.png + * + * \author Christian Mueller (christian.ei.mueller@bmw.de) + * + * \par Copyright + * Copyright Copyright (C) 2011,2012 GENIVI Alliance\n + * Copyright Copyright (C) 2011,2012 BMW AG + * + * \par License + * Contributions are licensed to the GENIVI Alliance under one or more Contribution License Agreements. + * This file is licensed under the terms of the Mozilla Public License 2.0.\n + * A copy of the license text has been included in the “LICENSE” file in the root directory of the source distribution. + * You can also obtain a copy of the license text at\n + * http://mozilla.org/MPL/2.0/. + * + * \par More information + * can be found at https://collab.genivi.org/wiki/display/genivi/GENIVI+Home \n + * + * \par About AudioManager + * The AudioManager is a Deamon that manages all Audio Connections in a GENIVI headunit. + * It is a managing instance that uses so called RoutingAdaptors to control AudioDomains that then do the "real" connections. + * \n\n\n + * + * + * \section architecture Architecture Overview + * + * The architecture concept bases on the partition of management (logic) and routing (action). Sinks and sources are clustered into independent parts which are capable of exchanging audio with each other (AudioDomains). Between these AudioDomains, Audio can be interchanged via Gateways. \n + * Since the routing and the management shall be independent from the actual used system, it is realized as an OwnedComponent, the AudioManager. Each AudioDomain has a Routing Adapter which implements some necessary logic and is the interface between the AudioManager and the AudioDomains. + * + * \section domains Audio Domains + * + * An Audio Domain consists of sinks and sources that can exchange audio with each other. To make the most out of the concept, AudioDomains shall be chosen in such a way that they are implemented by already existing audio routing engines. + * + * The AudioManager assumes that there are no restrictions in interconnection of sinks and sources. One or more sources can be connected to one sink and one or more sinks can be connected to one source. Since real hardware or software might end up in having restrictions, the knowledge of this must exist in the AudioManager and handled by him accordingly. This shall be accomplished via a plug-in mechanism. An AudioDomain is not tied to a hardware or software implementation. It can be software or hardware or even a combination of both. \n + * + * Examples for possible audio domains:\n + * PulseAudio, Alsa, Jack, DSP, FPGA, MOST, In-chip switching matrix\n + * + * The clustering and usage of the AudioDomains will vary from each product. Care must be taken while choosing the right AudioDomains in regards to system load (due to resampling), latency and of course flexibility.\n + * In special implementations of the AudioDomain, it is capable of operation a certain time without interaction to the AudioManager. This is needed to fulfill the requirements for Early & Late Audio, more information can be found below. + * + * \section routing_adaptor Routing Adapter + * + * Via this adapter, the interconnection from the AudioManager to the AudioDomains is accomplished. An AudioDomain shall have exactly one RoutingAdapter. In the terms of GENIVI, a RoutingAdapter is an AbstractComponent, this means that we define an API and a certain behavior in UML models but do not maintain components itself. Existing implementations from Proof of Concepts are shipped as example Adapters "as is" but cannot be seen as maintained components.\n + * The implementation of a routing adapter can and will vary from each project to another since the combination of sinks and sources, the used hardware etc has influence on the adapters. Besides interchanging and abstracting information between the AudioManager and the sinks and sources, the Adapters also need to implement some business logic in order to interact with the AudioManager. This include for example the registering of components, managing the current state, error handling etc.\n + * In the special case of an EarlyDomain, the routing adapter also has to manage start-up and rundown including persistence for his domain while the AudioManager is not started or already stopped. During this periods of time, these special adapters have to be able to fulfill basic tasks like changing volumes, for example (this implies that the Adapter is implemented on a different piece of hardware, e.g. vehicle processor). + * + * \section Gateway + * + * Gateways are used to let audio flow between two domains. They always have a direction and can only transport one stream at a time. Several gateways connecting the same domains together can exist in parallel so that more than one source can be connected to more than one sink from the same domains at the same time.\n + * The representation of a Gateway in the domain which originates the audio is a sink. In the receiving domain, the gateway appears as a source. The AudioManager knows about the Gateways, in terms of connection, it handles it as simple sources and sinks. + * + * \section AudioManagerDaemon + * + * The AudioManager is the central managing instance of the Audio architecture. It is designed as an OwnedComponent, this means that the software is maintained within GENIVI as open source component. The AudioManager consists of 4 central components.\n + * + * GOwnedComponent: AudioManager Daemon\n + * + * This component is owned and maintained by Genivi. It is the central audio framework component. There can be only one daemon in a system (singleton). + * + * \subsection controlinterface Control Interface Plugin + * + * This describes the interface towards the Controlling Instances of the AudioManagerDaemon. This is the HMI and interrupt sources that use this interface to start their interrupt and stop it again. The interface shall be asynchronous. Via this interface all user interactions are handled. + * + * \subsection routinginterface Routing Interface Plugin + * + * This interface is used by the AudioManager to control the RoutingAdapters and communicate with them. The communication is based on two interfaces, one is provided by the AudioManager for communication from the adapters towards the AudioManager and one for the opposite direction. The design of the AudioManager shall be done in such a way that several Interfaces are supported at the same time via a plug-in mechanism. The plug-ins are (either statically - due to performance reasons or dynamically) loaded at start-up. Due to this architecture, the number of buses and routing adapters that are supported are as low as possible for each system and as high as needed without the need of changing the AudioManager itself. The AudioManager expects a bus-like structure behind each plug-in, so that a plug-in can implement a bus interface and proxy the messages to the routing adapters - the AudioManager will be capable of addressing more than one adapter one each plug-in. The interface shall is asynchronous for all timely critical commands. + * + * \section interfaces Interfaces + * the calls to the interfaces of the AudioManagerDaemon are generally not threadsafe ! + * Nevertheless if such calls from a different thread-context are needed, you may use the defered-call pattern that utilizes the mainloop (Sockethandler) to get self called in the next loop of the mainloop. For more infomation please check the audiomanger wiki page. + * + * \section deferred The deferred call pattern + * Create a unix pipe or socket and add the file descriptor to the Sockethandler. Whenever a call needs to be deferred you can store the necessary information protected by a mutex in a queue and write to the socket or pipe. This will lead to a callback in the next loop of the mainloop - when getting called by the callback that was registered at the Sockethandler execute your call with the information stored away. + * + * + * \section sources_sinks Sources & Sinks + * \subsection Visibility + * Sources and sinks can either be visible or not. If they are visible, the HMI is informed about their existence and can use them. \n + * Invisible Sources and Sinks either are system only relevant (e.g. an audio processing that has a source and a sink) or belong to a gateway. + * + * \subsection Availability + * It can be the case, that sources and sinks are present in the system but cannot be used at the moment. This is indicated via the availability. A sample use-case for this feature is CD drive that shall only be available if a CD is inserted. + * + * \section Interrupts + * \subsection llinterrupts Low level interrupts + * \todo write low level Interrupts description + * + * \subsection Interrupts + * \todo write Interrupts description + * + * \section Persistency + * It is the job of the AudioManagerController to handle the persistency. It is planned to expose an interface via the ControlInterface to accomplish this but the GENIVI persistance is not ready yet. \n + * + * + * \section speed Speed dependent volume + * The adjustments for the speed are done product specific in the controller. The speed information itself is retrieved by the AudioManagerDaemon, sampled and quantified and forwarded to the controller.\n + * Turning speed controlled volume on/off and possible settings are achieved via SinkSoundProperty settings. + * + * \section Lipsync + * It is the job of the AudioManager to retrieve all latency timing information from each connection, to aggregate this information and provide a latency information on a per MainConnection Basis. It is not the task of the AudioManager to actually delay or speed up video or audio signals to achieve a lipsync. The actual correction shall be done in the videoplayer with the information provided by the AudioManager. + * The time information is always reported by the routingadaptors for each connection. Delays that are introduced in a sink or a gateway are counting for the connection that connects to this sink or gateway.\n + * After the buildup of a connection the first timing information needs to be sent within 5 seconds, the timing information from the routing adaptors need to be sent via 4 seconds. If the latency for a connection is variable and changes over lifetime of the connection, the routing adaptors shall resend the value and the audiomanger will correct the over all latency.\n + * @author Christian Mueller + * @created 25-Feb-2012 3:54:06 PM + */ + +#ifndef MAINPAGE_H_ +#define MAINPAGE_H_ + +#endif /* MAINPAGE_H_ */ diff --git a/AudioManagerDaemon/include/DatabaseHandler.h b/AudioManagerDaemon/include/DatabaseHandler.h deleted file mode 100644 index 964bbbe..0000000 --- a/AudioManagerDaemon/include/DatabaseHandler.h +++ /dev/null @@ -1,280 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file Databasehandler.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef DATABASEHANDLER_H_ -#define DATABASEHANDLER_H_ - -#include "audiomanagertypes.h" -#include -#include -#include - -namespace am -{ - -class DatabaseObserver; -class RoutingTree; -class RoutingTreeItem; - -#define DYNAMIC_ID_BOUNDARY 100 //!< the value below is reserved for staticIDs, the value above will be assigned to dynamically registered items -//todo: check the enum values before entering & changing in the database. -//todo: change asserts for dynamic boundary checks into failure answers.# -//todo: check autoincrement boundary and set to 16bit limits -//todo: If the sink is part of a gateway, the listconnectionFormats is copied to the gatewayInformation. Check this statement for sinks & sources -//todo: exchange last_insert_row id to be more safe -//todo: create test to ensure uniqueness of names throughout the database -//todo: enforce the uniqueness of names - -/** - * This class handles and abstracts the database - */ -class DatabaseHandler -{ -public: - DatabaseHandler(std::string databasePath); - ~DatabaseHandler(); - am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); - am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); - am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); - am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); - am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID); - am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID); - am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass); - am_Error_e enterSystemProperties(const std::vector& listSystemProperties); - am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID); - am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState); - am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID); - am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID); - am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID); - am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID); - am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID); - am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); - am_Error_e changeSourceSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sourceID_t sourceID); - am_Error_e changeSinkSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sinkID_t sinkID); - am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID); - am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property); - am_Error_e changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID); - am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass); - am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass); - am_Error_e changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay); - am_Error_e changeConnectionFinal(const am_connectionID_t connectionID); - am_Error_e changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState); - am_Error_e changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume); - am_Error_e changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume); - am_Error_e changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink); - am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID); - am_Error_e removeSinkDB(const am_sinkID_t sinkID); - am_Error_e removeSourceDB(const am_sourceID_t sourceID); - am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID); - am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID); - am_Error_e removeDomainDB(const am_domainID_t domainID); - am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID); - am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID); - am_Error_e removeConnection(const am_connectionID_t connectionID); - am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const; - am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const; - am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const; - am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const; - am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const; - am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const; - am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const; - am_Error_e getSinkVolume(const am_sinkID_t sinkID, am_volume_t& volume) const; - am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const; - am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t& value) const; - am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t& value) const; - am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const; - am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const; - am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; - am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const; - am_Error_e getListMainConnections(std::vector& listMainConnections) const; - am_Error_e getListDomains(std::vector& listDomains) const; - am_Error_e getListConnections(std::vector& listConnections) const; - am_Error_e getListSinks(std::vector& listSinks) const; - am_Error_e getListSources(std::vector& lisSources) const; - am_Error_e getListSourceClasses(std::vector& listSourceClasses) const; - am_Error_e getListCrossfaders(std::vector& listCrossfaders) const; - am_Error_e getListGateways(std::vector& listGateways) const; - am_Error_e getListSinkClasses(std::vector& listSinkClasses) const; - am_Error_e getListVisibleMainConnections(std::vector& listConnections) const; - am_Error_e getListMainSinks(std::vector& listMainSinks) const; - am_Error_e getListMainSources(std::vector& listMainSources) const; - am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const; - am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const; - am_Error_e getListSystemProperties(std::vector& listSystemProperties) const; - am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const; - am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const; - am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const; - am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const; - am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const; - am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const; - am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const; - am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e state) const; - am_Error_e getRoutingTree(bool onlyfree, RoutingTree& tree, std::vector& flatTree); - am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID); - am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID); - am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID); - am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); - am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); - /** - * checks for a certain mainConnection - * @param mainConnectionID to be checked for - * @return true if it exists - */ - bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const; - - /** - * checks if a CrossFader exists - * @param crossfaderID the ID of the crossfader to be checked - * @return true if exists - */ - bool existcrossFader(const am_crossfaderID_t crossfaderID) const; - - /** - * checks if a connection already exists. - * Only takes sink, source and format information for search! - * @param connection the connection to be checked - * @return true if connections exists - */ - bool existConnection(const am_Connection_s connection); - - /** - * checks if a connection with the given ID exists - * @param connectionID - * @return true if connection exits - */ - bool existConnectionID(const am_connectionID_t connectionID); - /** - * checks for a certain Source - * @param sourceID to be checked for - * @return true if it exists - */ - bool existSource(const am_sourceID_t sourceID) const; - - /** - * checks if a source name or ID exists - * @param sourceID the sourceID - * @param name the name - * @return true if it exits - */ - bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const; - - /** - * checks if a name exits - * @param name the name - * @return true if it exits - */ - bool existSourceName(const std::string& name) const; - /** - * checks for a certain Sink - * @param sinkID to be checked for - * @return true if it exists - */ - bool existSink(const am_sinkID_t sinkID) const; - - /** - * checks if a sink with the ID or the name exists - * @param sinkID the ID - * @param name the name - * @return true if it exists. - */ - bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const; - - /** - * checks if a sink with the name exists - * @param name the name - * @return true if it exists - */ - bool existSinkName(const std::string& name) const; - - /** - * checks for a certain domain - * @param domainID to be checked for - * @return true if it exists - */ - bool existDomain(const am_domainID_t domainID) const; - - /** - * checks for certain gateway - * @param gatewayID to be checked for - * @return true if it exists - */ - bool existGateway(const am_gatewayID_t gatewayID) const; - - /** - * checks for certain SinkClass - * @param sinkClassID - * @return true if it exists - */ - bool existSinkClass(const am_sinkClass_t sinkClassID) const; - - /** - * checks for certain sourceClass - * @param sourceClassID - * @return true if it exists - */ - bool existSourceClass(const am_sourceClass_t sourceClassID) const; - - /** - * registers the Observer at the Database - * @param iObserver pointer to the observer - */ - void registerObserver(DatabaseObserver *iObserver); - - /** - * gives information about the visibility of a source - * @param sourceID the sourceID - * @return true if source is visible - */ - bool sourceVisible(const am_sourceID_t sourceID) const; - - /** - * gives information about the visibility of a sink - * @param sinkID the sinkID - * @return true if source is visible - */ - bool sinkVisible(const am_sinkID_t sinkID) const; - -private: - am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; - bool sqQuery(const std::string& query); - bool openDatabase(); //!< opens the database - void createTables(); //!< creates all tables from the static table - sqlite3 *mDatabase; //!< pointer to the database - std::string mPath; //!< path to the database - DatabaseObserver *mDatabaseObserver; //!< pointer to the Observer - bool mFirstStaticSink; - bool mFirstStaticSource; - bool mFirstStaticGateway; - bool mFirstStaticSinkClass; - bool mFirstStaticSourceClass; - bool mFirstStaticCrossfader; - typedef std::map > ListConnectionFormat; //!< type for list of connection formats - ListConnectionFormat mListConnectionFormat; //!< list of connection formats -}; - -} - -#endif /* DATABASEHANDLER_H_ */ diff --git a/AudioManagerDaemon/include/DatabaseObserver.h b/AudioManagerDaemon/include/DatabaseObserver.h deleted file mode 100644 index 3862a79..0000000 --- a/AudioManagerDaemon/include/DatabaseObserver.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DatabaseObserver.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef DATABASEOBSERVER_H_ -#define DATABASEOBSERVER_H_ - -#include -#include -#include "CAmSerializer.h" - -namespace am -{ - -class TelnetServer; -class CommandSender; -class RoutingSender; -class SocketHandler; - -/** - * This class observes the Database and notifies other classes about important events, mainly the CommandSender. - */ - -class DatabaseObserver -{ -public: - DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler); - DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler, TelnetServer *iTelnetServer); - ~DatabaseObserver(); - void numberOfSinkClassesChanged(); - void numberOfSourceClassesChanged(); - void newSink(const am_Sink_s& sink); - void newSource(const am_Source_s& source); - void newDomain(const am_Domain_s& domain); - void newGateway(const am_Gateway_s& gateway); - void newCrossfader(const am_Crossfader_s& crossfader); - void newMainConnection(const am_MainConnectionType_s& mainConnection); - void removedMainConnection(const am_mainConnectionID_t mainConnection); - void removedSink(const am_sinkID_t sinkID, const bool visible); - void removedSource(const am_sourceID_t sourceID, const bool visible); - void removeDomain(const am_domainID_t domainID); - void removeGateway(const am_gatewayID_t gatewayID); - void removeCrossfader(const am_crossfaderID_t crossfaderID); - void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); - void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty); - void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty); - void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); - void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); - void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); - void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); - void systemPropertyChanged(const am_SystemProperty_s& SystemProperty); - void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time); - -private: - CommandSender *mCommandSender; //!< pointer to the comandSender - RoutingSender* mRoutingSender; //!< pointer to the routingSender - TelnetServer* mTelnetServer; //!< pointer to the telnetserver - CAmSerializer mSerializer; -}; - -} - -#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerDaemon/include/PluginTemplate.h b/AudioManagerDaemon/include/PluginTemplate.h deleted file mode 100644 index 2c4dc42..0000000 --- a/AudioManagerDaemon/include/PluginTemplate.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file pluginTemplate.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef PLUGINTEMPLATE_H_ -#define PLUGINTEMPLATE_H_ - -#include -#include -#include "DLTWrapper.h" - -namespace am -{ - -/** - * This template tries to load a library and cast ot to a class - * @param libname the full path to the library to be loaded - * @return returns the pointer to the class to be loaded - */ -template T* getCreateFunction(const std::string& libname, void*& libraryHandle) -{ - - logInfo("getCreateFunction : Trying to load library with name: ",libname); - - // cut off directories - char* fileWithPath = const_cast(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"; - - // open library - dlerror(); // Clear any existing error - libraryHandle = dlopen(libname.c_str(), RTLD_LAZY); - const char* dlopen_error = dlerror(); - if (!libraryHandle || dlopen_error) - { - logError("getCreateFunction : dlopen failed",dlopen_error); - return 0; - } - - // get entry point from shared lib - dlerror(); // Clear any existing error - - union - { - void* voidPointer; - T* typedPointer; - } functionPointer; - - // Note: direct cast is not allowed by ISO C++. e.g. - // T* createFunction = reinterpret_cast(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) - { - logError("getCreateFunction: Failed to load shared lib entry point",dlsym_error); - } - else - { - logInfo("getCreateFunction : loaded successfully plugin", createFunctionName); - } - return createFunction; -} - -} - -#endif /* PLUGINTEMPLATE_H_ */ diff --git a/AudioManagerDaemon/include/Router.h b/AudioManagerDaemon/include/Router.h deleted file mode 100644 index 11a5634..0000000 --- a/AudioManagerDaemon/include/Router.h +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file Router.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef ROUTER_H_ -#define ROUTER_H_ - -#include - -namespace am -{ - -class DatabaseHandler; -class ControlSender; - -class Router -{ -public: - Router(DatabaseHandler* iDatabaseHandler, ControlSender* iSender); - am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - ~Router(); - -private: - am_Error_e findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector& listRoute, std::vector::iterator routeIterator, std::vector::iterator gatewayIterator); - void listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& listFormats) const; - void listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_ConnectionFormat_e sinkConnectionFormat, std::vector& listFormats) const; - DatabaseHandler* mDatabaseHandler; - ControlSender* mControlSender; -}; - -class RoutingTreeItem -{ -public: - RoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID = 0, RoutingTreeItem *parent = 0); - void appendChild(RoutingTreeItem *newChild); - void returnChildItems(std::vector listChildItems); - am_domainID_t returnDomainID() const; - am_gatewayID_t returnGatewayID() const; - virtual ~RoutingTreeItem(); - RoutingTreeItem* returnParent() const; -private: - std::vector mListChildItems; //!< List of all child items - am_domainID_t mDomainID; //!< the domain ID of the item - am_gatewayID_t mGatewayID; //!< the gateway Id - RoutingTreeItem *mParentItem; //!< pointer to the parent item -}; - -class RoutingTree -{ -public: - RoutingTree(const am_domainID_t rootDomainID); - RoutingTreeItem* insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, RoutingTreeItem *parent); - void getRoute(RoutingTreeItem* targetItem, std::vector& listGateways); - am_domainID_t returnRootDomainID() const; - RoutingTreeItem* returnRootItem(); - virtual ~RoutingTree(); -private: - RoutingTreeItem mRootItem; //!< pointer to root item - std::vector mListChild; //!< list of all childs -}; - -} /* namespace am */ -#endif /* ROUTER_H_ */ - diff --git a/AudioManagerDaemon/include/RoutingReceiver.h b/AudioManagerDaemon/include/RoutingReceiver.h deleted file mode 100644 index ae964ff..0000000 --- a/AudioManagerDaemon/include/RoutingReceiver.h +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingReceiver.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef ROUTINGRECEIVER_H_ -#define ROUTINGRECEIVER_H_ - -#include -#include - -namespace am -{ - -class SocketHandler; -class DBusWrapper; -class DatabaseHandler; -class RoutingSender; -class ControlSender; - -/** - * Implements the Receiving side of the RoutingPlugins. - */ -class RoutingReceiver: public RoutingReceiveInterface -{ -public: - RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler); - RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler, DBusWrapper *iDBusWrapper); - ~RoutingReceiver(); - void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); - void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); - void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void ackSetSourceState(const am_Handle_s handle, const am_Error_e error); - void ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); - void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); - void ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error); - void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); - void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error); - void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); - void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); - am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID); - am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID); - am_Error_e deregisterDomain(const am_domainID_t domainID); - am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); - am_Error_e deregisterGateway(const am_gatewayID_t gatewayID); - am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID); - am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - am_Error_e deregisterSink(const am_sinkID_t sinkID); - am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID); - am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e deregisterSource(const am_sourceID_t sourceID); - am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); - am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID); - am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); - am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); - void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); - void hookDomainRegistrationComplete(const am_domainID_t domainID); - void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); - void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability); - void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState); - void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay); - void sendChangedData(const std::vector& earlyData); - am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const; - am_Error_e getSocketHandler(SocketHandler*& socketHandler) const; - void getInterfaceVersion(std::string& version) const; - void confirmRoutingReady(const uint16_t handle); - void confirmRoutingRundown(const uint16_t handle); - - uint16_t getStartupHandle(); //!< returns a startup handle - uint16_t getRundownHandle(); //!< returns a rundown handle - - void waitOnStartup(bool startup); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed - void waitOnRundown(bool rundown); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed - -private: - DatabaseHandler *mDatabaseHandler; //!< pointer to the databaseHandler - RoutingSender *mRoutingSender; //!< pointer to the routingSender - ControlSender *mControlSender; //!< pointer to the controlSender - SocketHandler *mSocketHandler; //!< pointer to sockethandler - DBusWrapper *mDBusWrapper; //!< pointer to dbuswrapper - - uint16_t handleCount; //!< counts all handles - std::vector mListStartupHandles; //!< list of handles that wait for a confirm - std::vector mListRundownHandles; //!< list of handles that wait for a confirm - bool mWaitStartup; //!< if true confirmation will be sent if list of handles = 0 - bool mWaitRundown; //!< if true confirmation will be sent if list of handles = 0 - -}; - -} - -#endif /* ROUTINGRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/RoutingSender.h b/AudioManagerDaemon/include/RoutingSender.h deleted file mode 100644 index f445313..0000000 --- a/AudioManagerDaemon/include/RoutingSender.h +++ /dev/null @@ -1,202 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef ROUTINGSENDER_H_ -#define ROUTINGSENDER_H_ - -#include "routing/RoutingSendInterface.h" -#include - -#ifdef UNIT_TEST //this is needed to test RoutingSender -#include "../test/RoutingInterfaceBackdoor.h" -#endif - -namespace am -{ - -class RoutingReceiver; - -/** - * Implements the RoutingSendInterface. Loads all plugins and dispatches calls to the plugins - */ -class RoutingSender -{ -public: - RoutingSender(const std::vector& listOfPluginDirectories); - ~RoutingSender(); - - /** - * removes a handle from the list - * @param handle to be removed - * @return E_OK in case of success - */ - am_Error_e removeHandle(const am_Handle_s& handle); - - /** - * @author Christian - * this adds the domain to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. - * This must be done whenever a domain is registered. - */ - am_Error_e addDomainLookup(const am_Domain_s& domainData); - /** - * @author Christian - * this adds the Source to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. - * This must be done whenever a Source is registered. - */ - am_Error_e addSourceLookup(const am_Source_s& sourceData); - /** - * @author Christian - * this adds the Sink to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. - * This must be done whenever a Sink is registered. - */ - am_Error_e addSinkLookup(const am_Sink_s& sinkData); - /** - * @author Christian - * this adds the Crossfader to the lookup table of the Router. The data is used to have a quick lookup of the correct pluginInterface. - * This must be done whenever a Crossfader is registered. - */ - am_Error_e addCrossfaderLookup(const am_Crossfader_s& crossfaderData); - /** - * @author Christian - * this removes the Domain to the lookup table of the Router. This must be done everytime a domain is deregistered. - */ - am_Error_e removeDomainLookup(const am_domainID_t domainID); - /** - * @author Christian - * this removes the Source to the lookup table of the Router. This must be done everytime a source is deregistered. - */ - am_Error_e removeSourceLookup(const am_sourceID_t sourceID); - /** - * @author Christian - * this removes the Sink to the lookup table of the Router. This must be done everytime a sink is deregistered. - */ - am_Error_e removeSinkLookup(const am_sinkID_t sinkID); - /** - * @author Christian - * this removes the Crossfader to the lookup table of the Router. This must be done everytime a crossfader is deregistered. - */ - am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID); - am_Error_e startupInterfaces(RoutingReceiver* iRoutingReceiver); - void setRoutingReady(); - void setRoutingRundown(); - am_Error_e asyncAbort(const am_Handle_s& handle); - am_Error_e asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); - am_Error_e asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID); - am_Error_e asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); - am_Error_e asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); - am_Error_e asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state); - am_Error_e asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); - am_Error_e asyncSetSourceSoundProperties(am_Handle_s& handle, const std::vector& listSoundProperties, const am_sourceID_t sourceID); - am_Error_e asyncSetSinkSoundProperties(am_Handle_s& handle, const std::vector& listSoundProperties, const am_sinkID_t sinkID); - am_Error_e asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); - am_Error_e asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time); - am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); - am_Error_e getListHandles(std::vector & listHandles) const; - am_Error_e getListPlugins(std::vector& interfaces) const; - void getInterfaceVersion(std::string& version) const; - - //!< is used to pair interfaces with busnames - struct InterfaceNamePairs - { - RoutingSendInterface* routingInterface; - std::string busName; - }; - - //!< is used to store data related to handles - class am_handleData_c - { - public: - union - { - am_sinkID_t sinkID; - am_sourceID_t sourceID; - am_crossfaderID_t crossfaderID; - am_connectionID_t connectionID; - }; - union - { - am_SoundProperty_s soundPropery; - am_SourceState_e sourceState; - am_volume_t volume; - am_HotSink_e hotSink; - std::vector* soundProperties; - }; - - }; - -#ifdef UNIT_TEST //this is needed to test RoutingSender - friend class RoutingInterfaceBackdoor; -#endif - - /** - * returns the data that belong to handles - * @param handle the handle - * @return a class holding the handle data - */ - am_handleData_c returnHandleData(const am_Handle_s handle) const; - -private: - - //!< is needed to sort the handles in the map - struct comparator - { - bool operator()(const am_Handle_s& a, const am_Handle_s& b) const - { - return (a.handle < b.handle); - } - }; - - /** - * creates a handle and adds it to the list of handles - * @param handleData the data that should be saves together with the handle - * @param type the type of handle to be created - * @return the handle - */ - am_Handle_s createHandle(const am_handleData_c& handleData, const am_Handle_e type); - void unloadLibraries(void); //!< unloads all loaded plugins - - typedef std::map DomainInterfaceMap; //!< maps domains to interfaces - typedef std::map SinkInterfaceMap; //!< maps sinks to interfaces - typedef std::map SourceInterfaceMap; //!< maps sources to interfaces - typedef std::map CrossfaderInterfaceMap; //!< maps crossfaders to interfaces - typedef std::map ConnectionInterfaceMap; //!< maps connections to interfaces - typedef std::map HandleInterfaceMap; //!< maps handles to interfaces - typedef std::map HandlesMap; //!< maps handleData to handles - - int16_t mHandleCount; //!< is used to create handles - HandlesMap mlistActiveHandles; //!< list of all currently "running" handles. - std::vector mListLibraryHandles; //!< list of all loaded pluginInterfaces - std::vector mListInterfaces; //!< list of busname/interface relation - ConnectionInterfaceMap mMapConnectionInterface; //!< map of connection to interfaces - CrossfaderInterfaceMap mMapCrossfaderInterface; //!< map of crossfaders to interface - DomainInterfaceMap mMapDomainInterface; //!< map of domains to interfaces - SinkInterfaceMap mMapSinkInterface; //!< map of sinks to interfaces - SourceInterfaceMap mMapSourceInterface; //!< map of sources to interfaces - HandleInterfaceMap mMapHandleInterface; //!< map of handles to interfaces - RoutingReceiver *mRoutingReceiver; -}; - -} - -#endif /* ROUTINGSENDER_H_ */ diff --git a/AudioManagerDaemon/include/TAmPluginTemplate.h b/AudioManagerDaemon/include/TAmPluginTemplate.h new file mode 100644 index 0000000..e525ce3 --- /dev/null +++ b/AudioManagerDaemon/include/TAmPluginTemplate.h @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file TAmPluginTemplate.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef PLUGINTEMPLATE_H_ +#define PLUGINTEMPLATE_H_ + +#include +#include +#include "shared/CAmDltWrapper.h" + +namespace am +{ + +/** + * This template tries to load a library and cast ot to a class + * @param libname the full path to the library to be loaded + * @return returns the pointer to the class to be loaded + */ +template T* getCreateFunction(const std::string& libname, void*& libraryHandle) +{ + + logInfo("getCreateFunction : Trying to load library with name: ",libname); + + // cut off directories + char* fileWithPath = const_cast(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"; + + // open library + dlerror(); // Clear any existing error + libraryHandle = dlopen(libname.c_str(), RTLD_LAZY); + const char* dlopen_error = dlerror(); + if (!libraryHandle || dlopen_error) + { + logError("getCreateFunction : dlopen failed",dlopen_error); + return 0; + } + + // get entry point from shared lib + dlerror(); // Clear any existing error + + union + { + void* voidPointer; + T* typedPointer; + } functionPointer; + + // Note: direct cast is not allowed by ISO C++. e.g. + // T* createFunction = reinterpret_cast(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) + { + logError("getCreateFunction: Failed to load shared lib entry point",dlsym_error); + } + else + { + logInfo("getCreateFunction : loaded successfully plugin", createFunctionName); + } + return createFunction; +} + +} + +#endif /* PLUGINTEMPLATE_H_ */ diff --git a/AudioManagerDaemon/include/TelnetServer.h b/AudioManagerDaemon/include/TelnetServer.h deleted file mode 100644 index f95bd84..0000000 --- a/AudioManagerDaemon/include/TelnetServer.h +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file TelnetServer.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef TELNETSERVER_H_ -#define TELNETSERVER_H_ - -#include "SocketHandler.h" -#include "CAmTelnetMenuHelper.h" -#include -#include - -namespace am -{ - -class DatabaseHandler; -class CommandSender; -class RoutingSender; -class ControlSender; -class CommandReceiver; -class RoutingReceiver; -class ControlReceiver; -class Router; -class CAmTelnetMenuHelper; - -class TelnetServer -{ -public: - TelnetServer(SocketHandler *iSocketHandler, - CommandSender *iCommandSender, - CommandReceiver *iCommandReceiver, - RoutingSender *iRoutingSender, - RoutingReceiver *iRoutingReceiver, - ControlSender *iControlSender, - ControlReceiver *iControlReceiver, - DatabaseHandler *iDatabasehandler, - Router *iRouter, - unsigned int servPort, - unsigned int maxConnections); - - ~TelnetServer(); - void connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void* userData); - void disconnectClient(int filedescriptor); - void receiveData(const pollfd pfd, const sh_pollHandle_t handle, void* userData); - bool dispatchData(const sh_pollHandle_t handle, void* userData); - bool check(const sh_pollHandle_t handle, void* userData); - shPollFired_T telnetConnectFiredCB; - shPollFired_T telnetReceiveFiredCB; - shPollDispatch_T telnetDispatchCB; - shPollCheck_T telnetCheckCB; -private: - - typedef void (*CommandPrototype)(std::vector& msg,int filedescriptor); - typedef std::map mMapCommand_t; - - void sliceCommand(const std::string& string,std::string& command,std::queue& msg); - mMapCommand_t createCommandMap(); - struct connection_s - { - int filedescriptor; - sh_pollHandle_t handle; - }; - - static TelnetServer* instance; - SocketHandler *mSocketHandler; - CommandSender *mCommandSender; - CommandReceiver *mCommandReceiver; - RoutingSender *mRoutingSender; - RoutingReceiver *mRoutingReceiver; - ControlSender *mControlSender; - ControlReceiver *mControlReceiver; - DatabaseHandler *mDatabasehandler; - Router *mRouter; - sh_pollHandle_t mConnecthandle; - std::queue mMsgList; - std::vector mListConnections; - int mConnectFD; - unsigned int mServerPort; - unsigned int mMaxConnections; - CAmTelnetMenuHelper mTelnetMenuHelper; - -}; - -} /* namespace am */ -#endif /* TELNETSERVER_H_ */ diff --git a/AudioManagerDaemon/include/mainpage.h b/AudioManagerDaemon/include/mainpage.h deleted file mode 100644 index 8d8fdab..0000000 --- a/AudioManagerDaemon/include/mainpage.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * \mainpage - * - * - * \image html genivilogo.png - * - * \author Christian Mueller (christian.ei.mueller@bmw.de) - * - * \par Copyright - * Copyright Copyright (C) 2011,2012 GENIVI Alliance\n - * Copyright Copyright (C) 2011,2012 BMW AG - * - * \par License - * Contributions are licensed to the GENIVI Alliance under one or more Contribution License Agreements. - * This file is licensed under the terms of the Mozilla Public License 2.0.\n - * A copy of the license text has been included in the “LICENSE” file in the root directory of the source distribution. - * You can also obtain a copy of the license text at\n - * http://mozilla.org/MPL/2.0/. - * - * \par More information - * can be found at https://collab.genivi.org/wiki/display/genivi/GENIVI+Home \n - * - * \par About AudioManager - * The AudioManager is a Deamon that manages all Audio Connections in a GENIVI headunit. - * It is a managing instance that uses so called RoutingAdaptors to control AudioDomains that then do the "real" connections. - * \n\n\n - * - * - * \section architecture Architecture Overview - * - * The architecture concept bases on the partition of management (logic) and routing (action). Sinks and sources are clustered into independent parts which are capable of exchanging audio with each other (AudioDomains). Between these AudioDomains, Audio can be interchanged via Gateways. \n - * Since the routing and the management shall be independent from the actual used system, it is realized as an OwnedComponent, the AudioManager. Each AudioDomain has a Routing Adapter which implements some necessary logic and is the interface between the AudioManager and the AudioDomains. - * - * \section domains Audio Domains - * - * An Audio Domain consists of sinks and sources that can exchange audio with each other. To make the most out of the concept, AudioDomains shall be chosen in such a way that they are implemented by already existing audio routing engines. - * - * The AudioManager assumes that there are no restrictions in interconnection of sinks and sources. One or more sources can be connected to one sink and one or more sinks can be connected to one source. Since real hardware or software might end up in having restrictions, the knowledge of this must exist in the AudioManager and handled by him accordingly. This shall be accomplished via a plug-in mechanism. An AudioDomain is not tied to a hardware or software implementation. It can be software or hardware or even a combination of both. \n - * - * Examples for possible audio domains:\n - * PulseAudio, Alsa, Jack, DSP, FPGA, MOST, In-chip switching matrix\n - * - * The clustering and usage of the AudioDomains will vary from each product. Care must be taken while choosing the right AudioDomains in regards to system load (due to resampling), latency and of course flexibility.\n - * In special implementations of the AudioDomain, it is capable of operation a certain time without interaction to the AudioManager. This is needed to fulfill the requirements for Early & Late Audio, more information can be found below. - * - * \section routing_adaptor Routing Adapter - * - * Via this adapter, the interconnection from the AudioManager to the AudioDomains is accomplished. An AudioDomain shall have exactly one RoutingAdapter. In the terms of GENIVI, a RoutingAdapter is an AbstractComponent, this means that we define an API and a certain behavior in UML models but do not maintain components itself. Existing implementations from Proof of Concepts are shipped as example Adapters "as is" but cannot be seen as maintained components.\n - * The implementation of a routing adapter can and will vary from each project to another since the combination of sinks and sources, the used hardware etc has influence on the adapters. Besides interchanging and abstracting information between the AudioManager and the sinks and sources, the Adapters also need to implement some business logic in order to interact with the AudioManager. This includes for example the registering of components, managing the current state, error handling etc.\n - * In the special case of an EarlyDomain, the routing adapter also has to manage start-up and rundown including persistence for his domain while the AudioManager is not started or already stopped. During this periods of time, these special adapters have to be able to fulfill basic tasks like changing volumes, for example (this implies that the Adapter is implemented on a different piece of hardware, e.g. vehicle processor). - * - * \section Gateway - * - * Gateways are used to let audio flow between two domains. They always have a direction and can only transport one stream at a time. Several gateways connecting the same domains together can exist in parallel so that more than one source can be connected to more than one sink from the same domains at the same time.\n - * The representation of a Gateway in the domain which originates the audio is a sink. In the receiving domain, the gateway appears as a source. The AudioManager knows about the Gateways, in terms of connection, it handles it as simple sources and sinks. - * - * \section AudioManagerDaemon - * - * The AudioManager is the central managing instance of the Audio architecture. It is designed as an OwnedComponent, this means that the software is maintained within GENIVI as open source component. The AudioManager consists of 4 central components.\n - * - * GOwnedComponent: AudioManager Daemon\n - * - * This component is owned and maintained by Genivi. It is the central audio framework component. There can be only one daemon in a system (singleton). - * - * \subsection controlinterface Control Interface Plugin - * - * This describes the interface towards the Controlling Instances of the AudioManagerDaemon. This is the HMI and interrupt sources that use this interface to start their interrupt and stop it again. The interface shall be asynchronous. Via this interface all user interactions are handled. - * - * \subsection routinginterface Routing Interface Plugin - * - * This interface is used by the AudioManager to control the RoutingAdapters and communicate with them. The communication is based on two interfaces, one is provided by the AudioManager for communication from the adapters towards the AudioManager and one for the opposite direction. The design of the AudioManager shall be done in such a way that several Interfaces are supported at the same time via a plug-in mechanism. The plug-ins are (either statically - due to performance reasons or dynamically) loaded at start-up. Due to this architecture, the number of buses and routing adapters that are supported are as low as possible for each system and as high as needed without the need of changing the AudioManager itself. The AudioManager expects a bus-like structure behind each plug-in, so that a plug-in can implement a bus interface and proxy the messages to the routing adapters - the AudioManager will be capable of addressing more than one adapter one each plug-in. The interface shall is asynchronous for all timely critical commands. - * - * \section interfaces Interfaces - * the calls to the interfaces of the AudioManagerDaemon are generally not threadsafe ! - * Nevertheless if such calls from a different thread-context are needed, you may use the defered-call pattern that utilizes the mainloop (Sockethandler) to get self called in the next loop of the mainloop. For more infomation please check the audiomanger wiki page. - * - * \section deferred The deferred call pattern - * Create a unix pipe or socket and add the file descriptor to the Sockethandler. Whenever a call needs to be deferred you can store the necessary information protected by a mutex in a queue and write to the socket or pipe. This will lead to a callback in the next loop of the mainloop - when getting called by the callback that was registered at the Sockethandler execute your call with the information stored away. - * - * - * \section sources_sinks Sources & Sinks - * \subsection Visibility - * Sources and sinks can either be visible or not. If they are visible, the HMI is informed about their existence and can use them. \n - * Invisible Sources and Sinks either are system only relevant (e.g. an audio processing that has a source and a sink) or belong to a gateway. - * - * \subsection Availability - * It can be the case, that sources and sinks are present in the system but cannot be used at the moment. This is indicated via the availability. A sample use-case for this feature is CD drive that shall only be available if a CD is inserted. - * - * \section Interrupts - * \subsection llinterrupts Low level interrupts - * \todo write low level Interrupts description - * - * \subsection Interrupts - * \todo write Interrupts description - * - * \section Persistency - * It is the job of the AudioManagerController to handle the persistency. It is planned to expose an interface via the ControlInterface to accomplish this but the GENIVI persistance is not ready yet. \n - * - * - * \section speed Speed dependent volume - * The adjustments for the speed are done product specific in the controller. The speed information itself is retrieved by the AudioManagerDaemon, sampled and quantified and forwarded to the controller.\n - * Turning speed controlled volume on/off and possible settings are achieved via SinkSoundProperty settings. - * - * \section Lipsync - * It is the job of the AudioManager to retrieve all latency timing information from each connection, to aggregate this information and provide a latency information on a per MainConnection Basis. It is not the task of the AudioManager to actually delay or speed up video or audio signals to achieve a lipsync. The actual correction shall be done in the videoplayer with the information provided by the AudioManager. - * The time information is always reported by the routingadaptors for each connection. Delays that are introduced in a sink or a gateway are counting for the connection that connects to this sink or gateway.\n - * After the buildup of a connection the first timing information needs to be sent within 5 seconds, the timing information from the routing adaptors need to be sent via 4 seconds. If the latency for a connection is variable and changes over lifetime of the connection, the routing adaptors shall resend the value and the audiomanger will correct the over all latency.\n - * @author Christian Mueller - * @created 25-Feb-2012 3:54:06 PM - */ - -#ifndef MAINPAGE_H_ -#define MAINPAGE_H_ - -#endif /* MAINPAGE_H_ */ diff --git a/AudioManagerDaemon/src/CAmCommandReceiver.cpp b/AudioManagerDaemon/src/CAmCommandReceiver.cpp new file mode 100644 index 0000000..c6f760c --- /dev/null +++ b/AudioManagerDaemon/src/CAmCommandReceiver.cpp @@ -0,0 +1,224 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CommandReveiver.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmCommandReceiver.h" +#include "CAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "shared/CAmDltWrapper.h" +#include +#include +#include + +namespace am +{ + +CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : + mDatabaseHandler(iDatabaseHandler), // + mControlSender(iControlSender), // + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) + +{ + assert(mDatabaseHandler!=NULL); + assert(mSocketHandler!=NULL); + assert(mControlSender!=NULL); +} + +CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : + mDatabaseHandler(iDatabaseHandler), // + mControlSender(iControlSender), // + mDBusWrapper(iDBusWrapper), // + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) +{ + assert(mDatabaseHandler!=NULL); + assert(mSocketHandler!=NULL); + assert(mControlSender!=NULL); + assert(mDBusWrapper!=NULL); +} + +CAmCommandReceiver::~CAmCommandReceiver() +{ +} + +am_Error_e CAmCommandReceiver::connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) +{ + logInfo("CommandReceiver::connect got called, sourceID=", sourceID, "sinkID=", sinkID); + return mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID); +} + +am_Error_e CAmCommandReceiver::disconnect(const am_mainConnectionID_t mainConnectionID) +{ + logInfo("CommandReceiver::disconnect got called, mainConnectionID=", mainConnectionID); + return mControlSender->hookUserDisconnectionRequest(mainConnectionID); +} + +am_Error_e CAmCommandReceiver::setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ + logInfo("CommandReceiver::setVolume got called, sinkID=", sinkID, "volume=", volume); + return mControlSender->hookUserVolumeChange(sinkID, volume); +} + +am_Error_e CAmCommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep) +{ + logInfo("CommandReceiver::volumeStep got called, sinkID=", sinkID, "volumeStep=", volumeStep); + return mControlSender->hookUserVolumeStep(sinkID, volumeStep); +} + +am_Error_e CAmCommandReceiver::setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + logInfo("CommandReceiver::setSinkMuteState got called, sinkID=", sinkID, "muteState=", muteState); + return mControlSender->hookUserSetSinkMuteState(sinkID, muteState); +} + +am_Error_e CAmCommandReceiver::setMainSinkSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + logInfo("CommandReceiver::setMainSinkSoundProperty got called, sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value); + return mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty); +} + +am_Error_e CAmCommandReceiver::setMainSourceSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + logInfo("CommandReceiver::setMainSourceSoundProperty got called, sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value); + return mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty); +} + +am_Error_e CAmCommandReceiver::setSystemProperty(const am_SystemProperty_s & property) +{ + logInfo("CommandReceiver::setSystemProperty got called", "type=", property.type, "soundPropertyValue=", property.value); + return mControlSender->hookUserSetSystemProperty(property); +} + +am_Error_e CAmCommandReceiver::getListMainConnections(std::vector & listConnections) const +{ + return mDatabaseHandler->getListVisibleMainConnections(listConnections); + +} + +am_Error_e CAmCommandReceiver::getListMainSinks(std::vector& listMainSinks) const +{ + return mDatabaseHandler->getListMainSinks(listMainSinks); +} + +am_Error_e CAmCommandReceiver::getListMainSources(std::vector& listMainSources) const +{ + return mDatabaseHandler->getListMainSources(listMainSources); +} + +am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const +{ + return mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties); +} + +am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const +{ + return mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties); +} + +am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector & listSourceClasses) const +{ + return mDatabaseHandler->getListSourceClasses(listSourceClasses); +} + +am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector & listSinkClasses) const +{ + return mDatabaseHandler->getListSinkClasses(listSinkClasses); +} + +am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector & listSystemProperties) const +{ + return mDatabaseHandler->getListSystemProperties(listSystemProperties); +} + +am_Error_e CAmCommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const +{ + return mDatabaseHandler->getTimingInformation(mainConnectionID, delay); +} + +am_Error_e CAmCommandReceiver::getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const +{ +#ifdef WITH_DBUS_WRAPPER + dbusConnectionWrapper = mDBusWrapper; + return E_OK; +#else + return E_UNKNOWN; +#endif /*WITH_DBUS_WRAPPER*/ +} + +am_Error_e CAmCommandReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const +{ + socketHandler = mSocketHandler; + return E_OK; +} + +void CAmCommandReceiver::getInterfaceVersion(std::string & version) const +{ + version = CommandReceiveVersion; +} + +void CAmCommandReceiver::confirmCommandReady(const uint16_t handle) +{ + mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); + if (mWaitStartup && mListStartupHandles.empty()) + mControlSender->confirmCommandReady(); +} + +void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle) +{ + mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); + if (mWaitRundown && mListRundownHandles.empty()) + mControlSender->confirmCommandRundown(); +} + +uint16_t CAmCommandReceiver::getStartupHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListStartupHandles.push_back(handle); + return handle; +} + +uint16_t CAmCommandReceiver::getRundownHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListRundownHandles.push_back(handle); + return handle; +} + +void CAmCommandReceiver::waitOnStartup(bool startup) +{ + mWaitStartup = startup; +} + +void CAmCommandReceiver::waitOnRundown(bool rundown) +{ + mWaitRundown = rundown; +} + +} diff --git a/AudioManagerDaemon/src/CAmCommandSender.cpp b/AudioManagerDaemon/src/CAmCommandSender.cpp new file mode 100644 index 0000000..0ada15c --- /dev/null +++ b/AudioManagerDaemon/src/CAmCommandSender.cpp @@ -0,0 +1,286 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmCommandSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmCommandSender.h" +#include +#include +#include +#include "CAmCommandReceiver.h" +#include "TAmPluginTemplate.h" +#include "shared/CAmDltWrapper.h" + +namespace am +{ + +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 + +//!< macro to call all interfaces +#define CALL_ALL_INTERFACES(...) \ + std::vector::iterator iter = mListInterfaces.begin(); \ + std::vector::iterator iterEnd = mListInterfaces.end(); \ + for (; iter__VA_ARGS__; \ + } + +CAmCommandSender::CAmCommandSender(const std::vector& listOfPluginDirectories) : + mListInterfaces(), // + mListLibraryHandles(), // + mListLibraryNames(), // + mCommandReceiver() +{ + std::vector sharedLibraryNameList; + std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); + std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); + + // search communicator plugins in configured directories + for (; dirIter < dirIterEnd; ++dirIter) + { + const char* directoryName = dirIter->c_str(); + logInfo("Searching for CommandPlugins in", *dirIter); + DIR *directory = opendir(directoryName); + + if (!directory) + { + logError("Error opening directory ", *dirIter); + continue; + } + + // iterate content of directory + struct dirent *itemInDirectory = 0; + while ((itemInDirectory = readdir(directory))) + { + unsigned char entryType = itemInDirectory->d_type; + std::string entryName = itemInDirectory->d_name; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + if (regularFile && sharedLibExtension) + { + std::string name(directoryName); + sharedLibraryNameList.push_back(name + "/" + entryName); + } + } + closedir(directory); + } + + // iterate all communicator plugins and start them + std::vector::iterator iter = sharedLibraryNameList.begin(); + std::vector::iterator iterEnd = sharedLibraryNameList.end(); + + for (; iter < iterEnd; ++iter) + { + logInfo("Loading CommandSender plugin", *iter); + IAmCommandSend* (*createFunc)(); + void* tempLibHandle = NULL; + createFunc = getCreateFunction(*iter, tempLibHandle); + + if (!createFunc) + { + logInfo("Entry point of CommandPlugin not found", *iter); + continue; + } + + IAmCommandSend* commander = createFunc(); + + if (!commander) + { + logInfo("CommandPlugin initialization failed. Entry Function not callable"); + continue; + } + + //check libversion + std::string version; + commander->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) + { + logInfo("CommandInterface initialization failed. Version of Interface to old"); + continue; + } + + mListInterfaces.push_back(commander); + mListLibraryHandles.push_back(tempLibHandle); + mListLibraryNames.push_back(iter->c_str()); + } +} + +CAmCommandSender::~CAmCommandSender() +{ + unloadLibraries(); +} + +am_Error_e CAmCommandSender::startupInterfaces(CAmCommandReceiver *iCommandReceiver) +{ + mCommandReceiver = iCommandReceiver; + am_Error_e returnError = E_OK; + + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + am_Error_e error = (*iter)->startupInterface(iCommandReceiver); + if (error != E_OK) + { + returnError = error; + } + } + return returnError; +} + +void CAmCommandSender::cbNumberOfSinkClassesChanged() +{ + CALL_ALL_INTERFACES(cbNumberOfSinkClassesChanged()) +} + +void CAmCommandSender::cbNumberOfSourceClassesChanged() +{ + CALL_ALL_INTERFACES(cbNumberOfSourceClassesChanged()) +} + +void CAmCommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) +{ + CALL_ALL_INTERFACES(cbMainConnectionStateChanged(connectionID,connectionState)) +} + +void CAmCommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) +{ + CALL_ALL_INTERFACES(cbMainSinkSoundPropertyChanged(sinkID,SoundProperty)) +} + +void CAmCommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) +{ + CALL_ALL_INTERFACES(cbMainSourceSoundPropertyChanged(sourceID,SoundProperty)) +} + +void CAmCommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + CALL_ALL_INTERFACES(cbSinkAvailabilityChanged(sinkID,availability)) +} + +void CAmCommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + CALL_ALL_INTERFACES(cbSourceAvailabilityChanged(sourceID,availability)) +} + +void CAmCommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ + CALL_ALL_INTERFACES(cbVolumeChanged(sinkID,volume)) +} + +void CAmCommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + CALL_ALL_INTERFACES(cbSinkMuteStateChanged(sinkID,muteState)) +} + +void CAmCommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty) +{ + CALL_ALL_INTERFACES(cbSystemPropertyChanged(SystemProperty)) +} + +void CAmCommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) +{ + CALL_ALL_INTERFACES(cbTimingInformationChanged(mainConnection,time)) +} + +void CAmCommandSender::cbNewMainConnection(const am_MainConnectionType_s mainConnection) +{ + CALL_ALL_INTERFACES(cbNewMainConnection(mainConnection)) +} + +void CAmCommandSender::cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) +{ + CALL_ALL_INTERFACES(cbRemovedMainConnection(mainConnection)) +} + +void CAmCommandSender::cbNewSink(const am_SinkType_s sink) +{ + CALL_ALL_INTERFACES(cbNewSink(sink)) +} + +void CAmCommandSender::cbRemovedSink(const am_sinkID_t sink) +{ + CALL_ALL_INTERFACES(cbRemovedSink(sink)) +} + +void CAmCommandSender::cbNewSource(const am_SourceType_s source) +{ + CALL_ALL_INTERFACES(cbNewSource(source)) +} + +void CAmCommandSender::cbRemovedSource(const am_sourceID_t source) +{ + CALL_ALL_INTERFACES(cbRemovedSource(source)) +} + +void CAmCommandSender::setCommandReady() +{ + mCommandReceiver->waitOnStartup(false); + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandReady(mCommandReceiver->getStartupHandle()); + } + mCommandReceiver->waitOnStartup(true); +} + +void CAmCommandSender::setCommandRundown() +{ + mCommandReceiver->waitOnRundown(false); + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandRundown(mCommandReceiver->getRundownHandle()); + } + mCommandReceiver->waitOnRundown(true); +} + +void CAmCommandSender::getInterfaceVersion(std::string & version) const +{ + version = CommandSendVersion; +} + +am_Error_e am::CAmCommandSender::getListPlugins(std::vector & interfaces) const +{ + interfaces = mListLibraryNames; + return E_OK; +} + +void CAmCommandSender::unloadLibraries(void) +{ + std::vector::iterator iterator = mListLibraryHandles.begin(); + for (; iterator < mListLibraryHandles.end(); ++iterator) + { + dlclose(*iterator); + } + mListLibraryHandles.clear(); +} +} diff --git a/AudioManagerDaemon/src/CAmControlReceiver.cpp b/AudioManagerDaemon/src/CAmControlReceiver.cpp new file mode 100644 index 0000000..6d68089 --- /dev/null +++ b/AudioManagerDaemon/src/CAmControlReceiver.cpp @@ -0,0 +1,513 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmControlReceiver.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 +#include +#include "CAmControlReceiver.h" +#include "CAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "CAmCommandSender.h" +#include "CAmRouter.h" +#include "shared/CAmDltWrapper.h" +#include + +namespace am { + +CAmControlReceiver::CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter) : + mDatabaseHandler(iDatabaseHandler), // + mRoutingSender(iRoutingSender), // + mCommandSender(iCommandSender), // + mSocketHandler(iSocketHandler), // + mRouter(iRouter) +{ + assert(mDatabaseHandler!=NULL); + assert(mRoutingSender!=NULL); + assert(mCommandSender!=NULL); + assert(mSocketHandler!=NULL); + assert(mRouter!=NULL); +} + +CAmControlReceiver::~CAmControlReceiver() +{ +} + +am_Error_e CAmControlReceiver::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) +{ + return mRouter->getRoute(onlyfree, sourceID, sinkID, returnList); +} + +am_Error_e CAmControlReceiver::connect(am_Handle_s & handle, am_connectionID_t & connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID) +{ + logInfo("CAmControlReceiver::connect got called, connectionFormat=", format, "sourceID=", sourceID, "sinkID=", sinkID); + + am_Connection_s tempConnection; + tempConnection.sinkID = sinkID; + tempConnection.sourceID = sourceID; + tempConnection.connectionFormat = format; + tempConnection.connectionID = 0; + + //todo: enter function to find out what happends if the same connection is in the course of being build up. + if (mDatabaseHandler->existConnection(tempConnection)) + return E_ALREADY_EXISTS; //todo:enter the correct connectionID here? + + mDatabaseHandler->enterConnectionDB(tempConnection, connectionID); + return mRoutingSender->asyncConnect(handle, connectionID, sourceID, sinkID, format); +} + +am_Error_e CAmControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID) +{ + logInfo("CAmControlReceiver::disconnect got called, connectionID=", connectionID); + + if (!mDatabaseHandler->existConnectionID(connectionID)) + return E_NON_EXISTENT; //todo: check with EA model and correct + return mRoutingSender->asyncDisconnect(handle, connectionID); +} + +am_Error_e CAmControlReceiver::crossfade(am_Handle_s & handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime) +{ + logInfo("CAmControlReceiver::crossfade got called, hotSource=", hotSource, "crossfaderID=", crossfaderID, "rampType=", rampType, "rampTime=", rampTime); + + if (!mDatabaseHandler->existcrossFader(crossfaderID)) + return E_NON_EXISTENT; + return mRoutingSender->asyncCrossFade(handle, crossfaderID, hotSource, rampType, rampTime); +} + +am_Error_e CAmControlReceiver::setSourceState(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SourceState_e state) +{ + logInfo("CAmControlReceiver::setSourceState got called, sourceID=", sourceID, "state=", state); + + am_SourceState_e sourceState; + if (mDatabaseHandler->getSoureState(sourceID, sourceState) != E_OK) + return E_UNKNOWN; + if (sourceState == state) + return E_NO_CHANGE; + return mRoutingSender->asyncSetSourceState(handle, sourceID, state); +} + +am_Error_e CAmControlReceiver::setSinkVolume(am_Handle_s & handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + logInfo("CAmControlReceiver::setSinkVolume got called, sinkID=", sinkID, "volume=", volume, "ramp=", ramp, "time=", time); + + am_volume_t tempVolume; + if (mDatabaseHandler->getSinkVolume(sinkID, tempVolume) != E_OK) + return E_UNKNOWN; + if (tempVolume == volume) + return E_NO_CHANGE; + return mRoutingSender->asyncSetSinkVolume(handle, sinkID, volume, ramp, time); +} + +am_Error_e CAmControlReceiver::setSourceVolume(am_Handle_s & handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time) +{ + logInfo("CAmControlReceiver::setSourceVolume got called, sourceID=", sourceID, "volume=", volume, "ramp=", rampType, "time=", time); + + am_volume_t tempVolume; + if (mDatabaseHandler->getSourceVolume(sourceID, tempVolume) != E_OK) + return E_UNKNOWN; + if (tempVolume == volume) + return E_NO_CHANGE; + return mRoutingSender->asyncSetSourceVolume(handle, sourceID, volume, rampType, time); +} + +am_Error_e CAmControlReceiver::setSinkSoundProperty(am_Handle_s & handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) +{ + logInfo("CAmControlReceiver::setSinkSoundProperty got called, sinkID=", sinkID, "soundProperty.Type=", soundProperty.type, "soundProperty.value=", soundProperty.value); + + uint16_t value; + if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, soundProperty.type, value) != E_OK) + return E_UNKNOWN; + if (value == soundProperty.value) + return E_NO_CHANGE; + return mRoutingSender->asyncSetSinkSoundProperty(handle, sinkID, soundProperty); +} + +am_Error_e CAmControlReceiver::setSinkSoundProperties(am_Handle_s & handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) +{ + logInfo("CAmControlReceiver::setSinkSoundProperties got called, sinkID=", sinkID); + + uint16_t value; + bool noChange = true; + std::vector::const_iterator it = listSoundProperties.begin(); + for (; it != listSoundProperties.end(); ++it) + { + if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, it->type, value) != E_OK) + return (E_UNKNOWN); + if (value != it->value) + noChange = false; + } + if (noChange) + return (E_NO_CHANGE); + return (mRoutingSender->asyncSetSinkSoundProperties(handle, listSoundProperties, sinkID)); +} + +am_Error_e CAmControlReceiver::setSourceSoundProperty(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) +{ + logInfo("CAmControlReceiver::setSourceSoundProperty got called, sourceID=", sourceID, "soundProperty.Type=", soundProperty.type, "soundProperty.value=", soundProperty.value); + + uint16_t value; + if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, soundProperty.type, value) != E_OK) + return E_UNKNOWN; + if (value == soundProperty.value) + return E_NO_CHANGE; + return mRoutingSender->asyncSetSourceSoundProperty(handle, sourceID, soundProperty); +} + +am_Error_e CAmControlReceiver::setSourceSoundProperties(am_Handle_s & handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) +{ + logInfo("CAmControlReceiver::setSourceSoundProperties got called, sourceID=", sourceID); + + uint16_t value; + bool noChange = true; + std::vector::const_iterator it = listSoundProperties.begin(); + for (; it != listSoundProperties.end(); ++it) + { + if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, it->type, value) != E_OK) + return (E_UNKNOWN); + if (value != it->value) + noChange = false; + } + if (noChange) + return (E_NO_CHANGE); + return (mRoutingSender->asyncSetSourceSoundProperties(handle, listSoundProperties, sourceID)); +} + +am_Error_e CAmControlReceiver::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + logInfo("CAmControlReceiver::setDomainState got called, domainID=", domainID, "domainState=", domainState); + + am_DomainState_e tempState = DS_UNKNOWN; + if (mDatabaseHandler->getDomainState(domainID, tempState) != E_OK) + return E_UNKNOWN; + if (tempState == domainState) + return E_NO_CHANGE; + return mRoutingSender->setDomainState(domainID, domainState); +} + +am_Error_e CAmControlReceiver::abortAction(const am_Handle_s handle) +{ + logInfo("CAmControlReceiver::abortAction got called, handle.type=", handle.handle, "handle.handleType=", handle.handleType); + + return mRoutingSender->asyncAbort(handle); +} + +am_Error_e CAmControlReceiver::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + return mDatabaseHandler->enterDomainDB(domainData, domainID); +} + +am_Error_e CAmControlReceiver::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID) +{ + return mDatabaseHandler->enterMainConnectionDB(mainConnectionData, connectionID); +} + +am_Error_e CAmControlReceiver::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + return mDatabaseHandler->enterSinkDB(sinkData, sinkID); +} + +am_Error_e CAmControlReceiver::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + return mDatabaseHandler->enterCrossfaderDB(crossfaderData, crossfaderID); +} + +am_Error_e CAmControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + return mDatabaseHandler->enterGatewayDB(gatewayData, gatewayID); +} + +am_Error_e CAmControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + return mDatabaseHandler->enterSourceDB(sourceData, sourceID); +} + +am_Error_e CAmControlReceiver::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) +{ + return mDatabaseHandler->enterSinkClassDB(sinkClass, sinkClassID); +} + +am_Error_e CAmControlReceiver::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) +{ + return mDatabaseHandler->enterSourceClassDB(sourceClassID, sourceClass); +} + +am_Error_e CAmControlReceiver::enterSystemPropertiesListDB(const std::vector & listSystemProperties) +{ + return mDatabaseHandler->enterSystemProperties(listSystemProperties); +} + +am_Error_e CAmControlReceiver::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) +{ + return mDatabaseHandler->changeMainConnectionRouteDB(mainconnectionID, listConnectionID); +} + +am_Error_e CAmControlReceiver::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) +{ + return mDatabaseHandler->changeMainConnectionStateDB(mainconnectionID, connectionState); +} + +am_Error_e CAmControlReceiver::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) +{ + return mDatabaseHandler->changeSinkMainVolumeDB(mainVolume, sinkID); +} + +am_Error_e CAmControlReceiver::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) +{ + return mDatabaseHandler->changeSinkAvailabilityDB(availability, sinkID); +} + +am_Error_e CAmControlReceiver::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) +{ + return mDatabaseHandler->changDomainStateDB(domainState, domainID); +} + +am_Error_e CAmControlReceiver::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) +{ + return mDatabaseHandler->changeSinkMuteStateDB(muteState, sinkID); +} + +am_Error_e CAmControlReceiver::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sinkID); +} + +am_Error_e CAmControlReceiver::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sourceID); +} + +am_Error_e CAmControlReceiver::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) +{ + return mDatabaseHandler->changeSourceAvailabilityDB(availability, sourceID); +} + +am_Error_e CAmControlReceiver::changeSystemPropertyDB(const am_SystemProperty_s & property) +{ + return mDatabaseHandler->changeSystemPropertyDB(property); +} + +am_Error_e CAmControlReceiver::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) +{ + return mDatabaseHandler->removeMainConnectionDB(mainConnectionID); +} + +am_Error_e CAmControlReceiver::removeSinkDB(const am_sinkID_t sinkID) +{ + return mDatabaseHandler->removeSinkDB(sinkID); +} + +am_Error_e CAmControlReceiver::removeSourceDB(const am_sourceID_t sourceID) +{ + return mDatabaseHandler->removeSourceDB(sourceID); +} + +am_Error_e CAmControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID) +{ + return mDatabaseHandler->removeGatewayDB(gatewayID); +} + +am_Error_e CAmControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) +{ + return mDatabaseHandler->removeCrossfaderDB(crossfaderID); +} + +am_Error_e CAmControlReceiver::removeDomainDB(const am_domainID_t domainID) +{ + return mDatabaseHandler->removeDomainDB(domainID); +} + +am_Error_e CAmControlReceiver::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const +{ + return mDatabaseHandler->getSourceClassInfoDB(sourceID, classInfo); +} + +am_Error_e CAmControlReceiver::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const +{ + return mDatabaseHandler->getSinkClassInfoDB(sinkID, sinkClass); +} + +am_Error_e CAmControlReceiver::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const +{ + return mDatabaseHandler->getSinkInfoDB(sinkID, sinkData); +} + +am_Error_e CAmControlReceiver::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const +{ + return mDatabaseHandler->getSourceInfoDB(sourceID, sourceData); +} + +am_Error_e CAmControlReceiver::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const +{ + return mDatabaseHandler->getMainConnectionInfoDB(mainConnectionID, mainConnectionData); +} + +am_Error_e CAmControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const +{ + return mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData); +} + +am_Error_e CAmControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const +{ + return mDatabaseHandler->getCrossfaderInfoDB(crossfaderID, crossfaderData); +} + +am_Error_e CAmControlReceiver::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const +{ + return mDatabaseHandler->getListSinksOfDomain(domainID, listSinkID); +} + +am_Error_e CAmControlReceiver::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const +{ + return mDatabaseHandler->getListSourcesOfDomain(domainID, listSourceID); +} + +am_Error_e CAmControlReceiver::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const +{ + return mDatabaseHandler->getListCrossfadersOfDomain(domainID, listGatewaysID); +} + +am_Error_e CAmControlReceiver::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const +{ + return mDatabaseHandler->getListGatewaysOfDomain(domainID, listGatewaysID); +} + +am_Error_e CAmControlReceiver::getListMainConnections(std::vector & listMainConnections) const +{ + return mDatabaseHandler->getListMainConnections(listMainConnections); +} + +am_Error_e CAmControlReceiver::getListDomains(std::vector & listDomains) const +{ + return mDatabaseHandler->getListDomains(listDomains); +} + +am_Error_e CAmControlReceiver::getListConnections(std::vector & listConnections) const +{ + return mDatabaseHandler->getListConnections(listConnections); +} + +am_Error_e CAmControlReceiver::getListSinks(std::vector & listSinks) const +{ + return mDatabaseHandler->getListSinks(listSinks); +} + +am_Error_e CAmControlReceiver::getListSources(std::vector & listSources) const +{ + return mDatabaseHandler->getListSources(listSources); +} + +am_Error_e CAmControlReceiver::getListSourceClasses(std::vector & listSourceClasses) const +{ + return mDatabaseHandler->getListSourceClasses(listSourceClasses); +} + +am_Error_e CAmControlReceiver::getListHandles(std::vector & listHandles) const +{ + return mRoutingSender->getListHandles(listHandles); +} + +am_Error_e CAmControlReceiver::getListCrossfaders(std::vector & listCrossfaders) const +{ + return mDatabaseHandler->getListCrossfaders(listCrossfaders); +} + +am_Error_e CAmControlReceiver::getListGateways(std::vector & listGateways) const +{ + return mDatabaseHandler->getListGateways(listGateways); +} + +am_Error_e CAmControlReceiver::getListSinkClasses(std::vector & listSinkClasses) const +{ + return mDatabaseHandler->getListSinkClasses(listSinkClasses); +} + +am_Error_e CAmControlReceiver::getListSystemProperties(std::vector & listSystemProperties) const +{ + return mDatabaseHandler->getListSystemProperties(listSystemProperties); +} + +am_Error_e CAmControlReceiver::changeSinkClassInfoDB(const am_SinkClass_s & classInfo) +{ + return mDatabaseHandler->changeSinkClassInfoDB(classInfo); +} + +am_Error_e CAmControlReceiver::changeSourceClassInfoDB(const am_SourceClass_s & classInfo) +{ + return mDatabaseHandler->changeSourceClassInfoDB(classInfo); +} + +am_Error_e CAmControlReceiver::removeSinkClassDB(const am_sinkClass_t sinkClassID) +{ + return mDatabaseHandler->removeSinkClassDB(sinkClassID); +} + +am_Error_e CAmControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceClassID) +{ + return mDatabaseHandler->removeSourceClassDB(sourceClassID); +} + +void CAmControlReceiver::setCommandReady() +{ + logInfo("CAmControlReceiver::setCommandReady got called"); + mCommandSender->setCommandReady(); +} + +void CAmControlReceiver::setRoutingReady() +{ + logInfo("CAmControlReceiver::setRoutingReady got called"); + mRoutingSender->setRoutingReady(); +} + +void CAmControlReceiver::confirmControllerReady() +{ + //todo: one time implement here system interaction with NSM +} + +void CAmControlReceiver::confirmControllerRundown() +{ + //todo: one time implement here system interaction with NSM +} + +am_Error_e CAmControlReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) +{ + socketHandler = mSocketHandler; + return E_OK; +} + +void CAmControlReceiver::setCommandRundown() +{ + logInfo("CAmControlReceiver::setCommandRundown got called"); + mCommandSender->setCommandRundown(); +} + +void CAmControlReceiver::setRoutingRundown() +{ + logInfo("CAmControlReceiver::setRoutingRundown got called"); + mRoutingSender->setRoutingRundown(); +} + +void CAmControlReceiver::getInterfaceVersion(std::string & version) const +{ + version = ControlReceiveVersion; +} +} + diff --git a/AudioManagerDaemon/src/CAmControlSender.cpp b/AudioManagerDaemon/src/CAmControlSender.cpp new file mode 100644 index 0000000..cc26c90 --- /dev/null +++ b/AudioManagerDaemon/src/CAmControlSender.cpp @@ -0,0 +1,314 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmControlSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmControlSender.h" +#include "TAmPluginTemplate.h" +#include "shared/CAmDltWrapper.h" +#include +#include +#include +#include +#include + +namespace am { + +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 + +CAmControlSender::CAmControlSender(std::string controlPluginFile) : + mlibHandle(NULL), // + mController(NULL) +{ + std::ifstream isfile(controlPluginFile.c_str()); + if (!isfile) + { + logError("ControlSender::ControlSender: Controller plugin not found:", controlPluginFile); + } + else if (!controlPluginFile.empty()) + { + IAmControlSend* (*createFunc)(); + createFunc = getCreateFunction(controlPluginFile, mlibHandle); + assert(createFunc!=NULL); + mController = createFunc(); + + //check libversion + std::string version; + mController->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) + { + logError("ControlSender::ControlSender: Interface Version of Controller too old, exiting now"); + throw std::runtime_error("Interface Version of Controller too old"); + } + } + else + { + logError("ControlSender::ControlSender: No controller loaded !"); + } +} + +CAmControlSender::~CAmControlSender() +{ + if (mlibHandle) + dlclose(mlibHandle); +} + +am_Error_e CAmControlSender::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) +{ + return mController->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID); +} + +am_Error_e CAmControlSender::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) +{ + return mController->hookUserDisconnectionRequest(connectionID); +} + +am_Error_e CAmControlSender::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) +{ + return mController->hookUserSetMainSinkSoundProperty(sinkID, soundProperty); +} + +am_Error_e CAmControlSender::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) +{ + return mController->hookUserSetMainSourceSoundProperty(sourceID, soundProperty); +} + +am_Error_e CAmControlSender::hookUserSetSystemProperty(const am_SystemProperty_s & property) +{ + return mController->hookUserSetSystemProperty(property); +} + +am_Error_e CAmControlSender::hookUserVolumeChange(const am_sinkID_t sinkID, const am_mainVolume_t newVolume) +{ + return mController->hookUserVolumeChange(sinkID, newVolume); +} + +am_Error_e CAmControlSender::hookUserVolumeStep(const am_sinkID_t sinkID, const int16_t increment) +{ + return mController->hookUserVolumeStep(sinkID, increment); +} + +am_Error_e CAmControlSender::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + return mController->hookUserSetSinkMuteState(sinkID, muteState); +} + +am_Error_e CAmControlSender::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + return mController->hookSystemRegisterDomain(domainData, domainID); +} + +am_Error_e CAmControlSender::hookSystemDeregisterDomain(const am_domainID_t domainID) +{ + return mController->hookSystemDeregisterDomain(domainID); +} + +void CAmControlSender::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) +{ + return mController->hookSystemDomainRegistrationComplete(domainID); +} + +am_Error_e CAmControlSender::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + return mController->hookSystemRegisterSink(sinkData, sinkID); +} + +am_Error_e CAmControlSender::hookSystemDeregisterSink(const am_sinkID_t sinkID) +{ + return mController->hookSystemDeregisterSink(sinkID); +} + +am_Error_e CAmControlSender::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + return mController->hookSystemRegisterSource(sourceData, sourceID); +} + +am_Error_e CAmControlSender::hookSystemDeregisterSource(const am_sourceID_t sourceID) +{ + return mController->hookSystemDeregisterSource(sourceID); +} + +am_Error_e CAmControlSender::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + return mController->hookSystemRegisterGateway(gatewayData, gatewayID); +} + +am_Error_e CAmControlSender::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) +{ + return mController->hookSystemDeregisterGateway(gatewayID); +} + +am_Error_e CAmControlSender::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + return mController->hookSystemRegisterCrossfader(crossfaderData, crossfaderID); +} + +am_Error_e CAmControlSender::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) +{ + return mController->hookSystemDeregisterCrossfader(crossfaderID); +} + +void CAmControlSender::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + mController->hookSystemSinkVolumeTick(handle, sinkID, volume); +} + +void CAmControlSender::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + mController->hookSystemSourceVolumeTick(handle, sourceID, volume); +} + +void CAmControlSender::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + mController->hookSystemInterruptStateChange(sourceID, interruptState); +} + +void CAmControlSender::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + mController->hookSystemSinkAvailablityStateChange(sinkID, availability); +} + +void CAmControlSender::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + mController->hookSystemSourceAvailablityStateChange(sourceID, availability); +} + +void CAmControlSender::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) +{ + mController->hookSystemDomainStateChange(domainID, state); +} + +void CAmControlSender::hookSystemReceiveEarlyData(const std::vector & data) +{ + mController->hookSystemReceiveEarlyData(data); +} + +void CAmControlSender::hookSystemSpeedChange(const am_speed_t speed) +{ + mController->hookSystemSpeedChange(speed); +} + +void CAmControlSender::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) +{ + mController->hookSystemTimingInformationChanged(mainConnectionID, time); +} + +void CAmControlSender::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) +{ + mController->cbAckConnect(handle, errorID); +} + +void CAmControlSender::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) +{ + mController->cbAckDisconnect(handle, errorID); +} + +void CAmControlSender::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) +{ + mController->cbAckCrossFade(handle, hostsink, error); +} + +void CAmControlSender::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + mController->cbAckSetSinkVolumeChange(handle, volume, error); +} + +void CAmControlSender::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + mController->cbAckSetSourceVolumeChange(handle, volume, error); +} + +void CAmControlSender::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + mController->cbAckSetSourceState(handle, error); +} + +void CAmControlSender::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + mController->cbAckSetSourceSoundProperty(handle, error); +} + +am_Error_e CAmControlSender::startupController(IAmControlReceive *controlreceiveinterface) +{ + return mController->startupController(controlreceiveinterface); +} + +void CAmControlSender::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + mController->cbAckSetSinkSoundProperty(handle, error); +} + +void CAmControlSender::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + mController->cbAckSetSinkSoundProperties(handle, error); +} + +void CAmControlSender::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + mController->cbAckSetSourceSoundProperties(handle, error); +} + +void CAmControlSender::setControllerReady() +{ + mController->setControllerReady(); +} + +void CAmControlSender::setControllerRundown() +{ + mController->setControllerRundown(); +} + +am_Error_e am::CAmControlSender::getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector & listPrioConnectionFormats) +{ + return mController->getConnectionFormatChoice(sourceID, sinkID, listRoute, listPossibleConnectionFormats, listPrioConnectionFormats); +} + +void CAmControlSender::getInterfaceVersion(std::string & version) const +{ + version = ControlSendVersion; +} + +void CAmControlSender::confirmCommandReady() +{ + mController->confirmCommandReady(); +} + +void CAmControlSender::confirmRoutingReady() +{ + mController->confirmRoutingReady(); +} + +void CAmControlSender::confirmCommandRundown() +{ + mController->confirmCommandRundown(); +} + +void CAmControlSender::confirmRoutingRundown() +{ + mController->confirmRoutingRundown(); +} +} diff --git a/AudioManagerDaemon/src/CAmDatabaseHandler.cpp b/AudioManagerDaemon/src/CAmDatabaseHandler.cpp new file mode 100644 index 0000000..b9da10e --- /dev/null +++ b/AudioManagerDaemon/src/CAmDatabaseHandler.cpp @@ -0,0 +1,4402 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDatabaseHandler.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmDatabaseHandler.h" +#include "CAmDatabaseObserver.h" +#include +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" +#include "CAmRouter.h" + +#define DOMAIN_TABLE "Domains" +#define SOURCE_CLASS_TABLE "SourceClasses" +#define SINK_CLASS_TABLE "SinkClasses" +#define SOURCE_TABLE "Sources" +#define SINK_TABLE "Sinks" +#define GATEWAY_TABLE "Gateways" +#define CROSSFADER_TABLE "Crossfaders" +#define CONNECTION_TABLE "Connections" +#define MAINCONNECTION_TABLE "MainConnections" +#define INTERRUPT_TABLE "Interrupts" +#define MAIN_TABLE "MainTable" +#define SYSTEM_TABLE "SystemProperties" + +namespace am +{ + +const std::string databaseTables[] = +{ " Domains (domainID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), busname VARCHAR(50), nodename VARCHAR(50), early BOOL, complete BOOL, state INTEGER, reserved BOOL);", // + " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // + " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // + " Sources (sourceID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domainID INTEGER, name VARCHAR(50), sourceClassID INTEGER, sourceState INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, interruptState INTEGER, reserved BOOL);", // + " Sinks (sinkID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), domainID INTEGER, sinkClassID INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, muteState INTEGER, mainVolume INTEGER, reserved BOOL);", // + " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", // + " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", // + " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", // + " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", // + " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" }; + +/** + * template to converts T to std::string + * @param i the value to be converted + * @return the string + */ +template +inline std::string i2s(T const& x) +{ + std::ostringstream o; + o << x; + return o.str(); +} + +CAmDatabaseHandler::CAmDatabaseHandler(std::string databasePath) : + mDatabase(NULL), // + mPath(databasePath), // + mDatabaseObserver(NULL), // + mFirstStaticSink(true), // + mFirstStaticSource(true), // + mFirstStaticGateway(true), // + mFirstStaticSinkClass(true), // + mFirstStaticSourceClass(true), // + mFirstStaticCrossfader(true), // + mListConnectionFormat() +{ + + std::ifstream infile(mPath.c_str()); + + if (infile) + { + remove(mPath.c_str()); + logInfo("DatabaseHandler::DatabaseHandler Knocked down database"); + } + + bool dbOpen = openDatabase(); + if (!dbOpen) + { + logInfo("DatabaseHandler::DatabaseHandler problems opening the database!"); + } + + createTables(); +} + +CAmDatabaseHandler::~CAmDatabaseHandler() +{ + logInfo("Closed Database"); + sqlite3_close(mDatabase); +} + +am_Error_e CAmDatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + assert(domainData.domainID==0); + assert(!domainData.name.empty()); + assert(!domainData.busname.empty()); + assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX); + + //first check for a reserved domain + sqlite3_stmt* query = NULL, *queryFinal; + int eCode = 0; + std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0)); + } + else if (eCode == SQLITE_DONE) + { + + command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)"; + } + else + { + logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); + sqlite3_bind_text(queryFinal, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC); + sqlite3_bind_text(queryFinal, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC); + sqlite3_bind_text(queryFinal, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC); + sqlite3_bind_int(queryFinal, 4, domainData.early); + sqlite3_bind_int(queryFinal, 5, domainData.complete); + sqlite3_bind_int(queryFinal, 6, domainData.state); + sqlite3_bind_int(queryFinal, 7, 0); + + if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) + { + logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + domainID = sqlite3_last_insert_rowid(mDatabase); + logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID); + + am_Domain_s domain = domainData; + domain.domainID = domainID; + if (mDatabaseObserver) + mDatabaseObserver->newDomain(domain); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID) +{ + assert(mainConnectionData.mainConnectionID==0); + assert(mainConnectionData.connectionState>=CS_UNKNOWN && mainConnectionData.connectionState<=CS_MAX); + assert(mainConnectionData.sinkID!=0); + assert(mainConnectionData.sourceID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + int16_t delay = 0; + std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, mainConnectionData.sourceID); + sqlite3_bind_int(query, 2, mainConnectionData.sinkID); + sqlite3_bind_int(query, 3, mainConnectionData.connectionState); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + connectionID = sqlite3_last_insert_rowid(mDatabase); + + //now check the connectionTable for all connections in the route. IF connectionID exist + command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator elementIterator = mainConnectionData.listConnectionID.begin(); + for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator) + { + sqlite3_bind_int(query, 1, *elementIterator); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + int16_t temp_delay = sqlite3_column_int(query, 1); + if (temp_delay != -1 && delay != -1) + delay += temp_delay; + else + delay = -1; + } + else + { + logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + //now we create a table with references to the connections; + command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)"); + assert(this->sqQuery(command)); + + command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin()); + for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator) + { + sqlite3_bind_int(query, 1, *listConnectionIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); + + if (mDatabaseObserver) + { + am_MainConnectionType_s mainConnection; + mainConnection.mainConnectionID = connectionID; + mainConnection.connectionState = mainConnectionData.connectionState; + mainConnection.delay = delay; + mainConnection.sinkID = mainConnectionData.sinkID; + mainConnection.sourceID = mainConnectionData.sourceID; + mDatabaseObserver->newMainConnection(mainConnection); + mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState); + } + + //finally, we update the delay value for the maintable + if (delay == 0) + delay = -1; + return changeDelayMainConnection(delay, connectionID); +} + +am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + assert(sinkData.sinkID=MS_UNKNOWN && sinkData.muteState<=MS_MAX); + + sqlite3_stmt *query = NULL, *queryFinal = NULL; + int eCode = 0; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + command = "UPDATE " + std::string(SINK_TABLE) + " SET name=?, domainID=?, sinkClassID=?, volume=?, visible=?, availability=?, availabilityReason=?, muteState=?, mainVolume=?, reserved=? WHERE sinkID=" + i2s(sqlite3_column_int(query, 0)); + } + else if (eCode == SQLITE_DONE) + { + //if sinkID is zero and the first Static Sink was already entered, the ID is created + if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name)) + { + command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)"; + } + else + { + //check if the ID already exists + if (existSinkNameOrID(sinkData.sinkID, sinkData.name)) + { + sqlite3_finalize(query); + return E_ALREADY_EXISTS; + } + command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; + } + } + else + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); + sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); + sqlite3_bind_int(queryFinal, 2, sinkData.domainID); + sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID); + sqlite3_bind_int(queryFinal, 4, sinkData.volume); + sqlite3_bind_int(queryFinal, 5, sinkData.visible); + sqlite3_bind_int(queryFinal, 6, sinkData.available.availability); + sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason); + sqlite3_bind_int(queryFinal, 8, sinkData.muteState); + sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume); + sqlite3_bind_int(queryFinal, 10, 0); + + //if the ID is not created, we add it to the query + if (sinkData.sinkID != 0) + { + sqlite3_bind_int(queryFinal, 11, sinkData.sinkID); + } + + //if the first static sink is entered, we need to set it onto the boundary + else if (mFirstStaticSink) + { + sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY); + mFirstStaticSink = false; + } + + if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(queryFinal); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + //now read back the sinkID + command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkID = sqlite3_column_int(query, 0); + } + else + { + sinkID = 0; + logError("DatabaseHandler::existSink database error!:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_finalize(query); + + //now we need to create the additional tables: + command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)"); + assert(this->sqQuery(command)); + command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //fill ConnectionFormats + command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin(); + for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator) + { + sqlite3_bind_int(query, 1, *connectionFormatIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + //Fill SinkSoundProperties + command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin(); + for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator) + { + sqlite3_bind_int(query, 1, SoundPropertyIterator->type); + sqlite3_bind_int(query, 2, SoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if (sinkData.visible == true) + { + command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //Fill MainSinkSoundProperties + command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin(); + for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) + { + sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); + sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + } + + logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID); + am_Sink_s sink = sinkData; + sink.sinkID = sinkID; + if (mDatabaseObserver != NULL) + mDatabaseObserver->newSink(sink); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + assert(crossfaderData.crossfaderID=HS_UNKNOWN && crossfaderData.hotSink<=HS_MAX); + assert(!crossfaderData.name.empty()); + assert(existSink(crossfaderData.sinkID_A)); + assert(existSink(crossfaderData.sinkID_B)); + assert(existSource(crossfaderData.sourceID)); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + //if gatewayData is zero and the first Static Sink was already entered, the ID is created + if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader) + { + command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)"; + } + else + { + //check if the ID already exists + if (existcrossFader(crossfaderData.crossfaderID)) + return E_ALREADY_EXISTS; + command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)"; + } + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC); + sqlite3_bind_int(query, 2, crossfaderData.sinkID_A); + sqlite3_bind_int(query, 3, crossfaderData.sinkID_B); + sqlite3_bind_int(query, 4, crossfaderData.sourceID); + sqlite3_bind_int(query, 5, crossfaderData.hotSink); + + //if the ID is not created, we add it to the query + if (crossfaderData.crossfaderID != 0) + { + sqlite3_bind_int(query, 6, crossfaderData.crossfaderID); + } + + //if the first static sink is entered, we need to set it onto the boundary + else if (mFirstStaticCrossfader) + { + sqlite3_bind_int(query, 6, DYNAMIC_ID_BOUNDARY); + mFirstStaticCrossfader = false; + } + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterCrossfaderDB SQLITE Finalize error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + + //now read back the crossfaderID + command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + crossfaderID = sqlite3_column_int(query, 0); + } + else + { + crossfaderID = 0; + logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_finalize(query); + + logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID); + + am_Crossfader_s crossfader(crossfaderData); + crossfader.crossfaderID = crossfaderID; + if (mDatabaseObserver) + mDatabaseObserver->newCrossfader(crossfader); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + assert(gatewayData.gatewayIDsqQuery(command)); + command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)"); + assert(this->sqQuery(command)); + + //fill ConnectionFormats + command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin(); + for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator) + { + sqlite3_bind_int(query, 1, *connectionFormatIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + connectionFormatIterator = gatewayData.listSinkFormats.begin(); + for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator) + { + sqlite3_bind_int(query, 1, *connectionFormatIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID); + am_Gateway_s gateway = gatewayData; + gateway.gatewayID = gatewayID; + if (mDatabaseObserver) + mDatabaseObserver->newGateway(gateway); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + assert(sourceData.sourceID=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX); + + sqlite3_stmt* query = NULL, *queryFinal = NULL; + ; + int eCode = 0; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + command = "UPDATE " + std::string(SOURCE_TABLE) + " SET name=?, domainID=?, sourceClassID=?, sourceState=?, volume=?, visible=?, availability=?, availabilityReason=?, interruptState=?, reserved=? WHERE sourceID=" + i2s(sqlite3_column_int(query, 0)); + } + else if (eCode == SQLITE_DONE) + { + //if sinkID is zero and the first Static Sink was already entered, the ID is created + if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name)) + { + command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)"; + } + else + { + //check if the ID already exists + if (existSourceNameOrID(sourceData.sourceID, sourceData.name)) + { + sqlite3_finalize(query); + return E_ALREADY_EXISTS; + } + command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; + } + } + else + { + logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); + sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); + sqlite3_bind_int(queryFinal, 2, sourceData.domainID); + sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID); + sqlite3_bind_int(queryFinal, 4, sourceData.sourceState); + sqlite3_bind_int(queryFinal, 5, sourceData.volume); + sqlite3_bind_int(queryFinal, 6, sourceData.visible); + sqlite3_bind_int(queryFinal, 7, sourceData.available.availability); + sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason); + sqlite3_bind_int(queryFinal, 9, sourceData.interruptState); + sqlite3_bind_int(queryFinal, 10, 0); + + //if the ID is not created, we add it to the query + if (sourceData.sourceID != 0) + { + sqlite3_bind_int(queryFinal, 11, sourceData.sourceID); + } + + //if the first static sink is entered, we need to set it onto the boundary + else if (mFirstStaticSource) + { + sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY); + mFirstStaticSource = false; + } + + if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); + sqlite3_finalize(queryFinal); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode); + sqlite3_finalize(queryFinal); + return E_DATABASE_ERROR; + } + + //now read back the sinkID + command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceID = sqlite3_column_int(query, 0); + } + else + { + sourceID = 0; + logError("DatabaseHandler::existSink database error!:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_finalize(query); + + //now we need to create the additional tables: + command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)"); + assert(this->sqQuery(command)); + command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //fill ConnectionFormats + command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin(); + for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator) + { + sqlite3_bind_int(query, 1, *connectionFormatIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + //Fill SinkSoundProperties + command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin(); + for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator) + { + sqlite3_bind_int(query, 1, SoundPropertyIterator->type); + sqlite3_bind_int(query, 2, SoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if (sourceData.visible == true) + { + command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //Fill MainSinkSoundProperties + command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin(); + for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) + { + sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); + sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + } + + logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); + + am_Source_s source = sourceData; + source.sourceID = sourceID; + if (mDatabaseObserver) + mDatabaseObserver->newSource(source); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) +{ + assert(mainconnectionID!=0); + if (!existMainConnection(mainconnectionID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + int16_t delay = 0; + command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator elementIterator = listConnectionID.begin(); + for (; elementIterator < listConnectionID.end(); ++elementIterator) + { + sqlite3_bind_int(query, 1, *elementIterator); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + int16_t temp_delay = sqlite3_column_int(query, 1); + if (temp_delay != -1 && delay != -1) + delay += temp_delay; + else + delay = -1; + } + else + { + logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:", eCode); + + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //now we delete the data in the table + command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID); + assert(this->sqQuery(command)); + + command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator listConnectionIterator(listConnectionID.begin()); + for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator) + { + sqlite3_bind_int(query, 1, *listConnectionIterator); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) +{ + assert(mainconnectionID!=0); + assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existMainConnection(mainconnectionID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, connectionState); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); + + if (mDatabaseObserver) + mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, mainVolume); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); + + if (mDatabaseObserver) + mDatabaseObserver->volumeChanged(sinkID, mainVolume); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); + assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, availability.availability); + sqlite3_bind_int(query, 2, availability.availabilityReason); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + }assert(sinkID!=0); + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); + + if (mDatabaseObserver && sourceVisible(sinkID)) + mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) +{ + assert(domainID!=0); + assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, domainState); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, muteState); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + }assert(sinkID!=0); + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); + + if (mDatabaseObserver) + mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX); + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, soundProperty.value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + }assert(sinkID!=0); + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); + if (mDatabaseObserver) + mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX); + assert(sourceID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, soundProperty.value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); + + if (mDatabaseObserver) + mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); + assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, availability.availability); + sqlite3_bind_int(query, 2, availability.availabilityReason); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); + + if (mDatabaseObserver && sourceVisible(sourceID)) + mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property) +{ + assert(property.type>=SYP_UNKNOWN && property.type<=SYP_MAX); + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, property.value); + sqlite3_bind_int(query, 2, property.type); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSystemPropertyDB changed system property"); + + if (mDatabaseObserver) + mDatabaseObserver->systemPropertyChanged(property); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) +{ + assert(mainConnectionID!=0); + + if (!existMainConnection(mainConnectionID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); + std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + if (!sqQuery(command1)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID); + if (mDatabaseObserver) + { + mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); + mDatabaseObserver->removedMainConnection(mainConnectionID); + } + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeSinkDB(const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + + bool visible = sinkVisible(sinkID); + + std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); + std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID); + std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID); + std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + if (!sqQuery(command1)) + return E_DATABASE_ERROR; + if (!sqQuery(command2)) + return E_DATABASE_ERROR; + if (!sqQuery(command3)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); + + if (mDatabaseObserver != NULL) + mDatabaseObserver->removedSink(sinkID, visible); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeSourceDB(const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + + bool visible = sourceVisible(sourceID); + + std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); + std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID); + std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID); + std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + if (!sqQuery(command1)) + return E_DATABASE_ERROR; + if (!sqQuery(command2)) + return E_DATABASE_ERROR; + if (!sqQuery(command3)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); + if (mDatabaseObserver) + mDatabaseObserver->removedSource(sourceID, visible); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID) +{ + assert(gatewayID!=0); + + if (!existGateway(gatewayID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID); + if (mDatabaseObserver) + mDatabaseObserver->removeGateway(gatewayID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) +{ + assert(crossfaderID!=0); + + if (!existcrossFader(crossfaderID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeDomainDB removed:", crossfaderID); + if (mDatabaseObserver) + mDatabaseObserver->removeCrossfader(crossfaderID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeDomainDB(const am_domainID_t domainID) +{ + assert(domainID!=0); + + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeDomainDB removed:", domainID); + if (mDatabaseObserver) + mDatabaseObserver->removeDomain(domainID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID) +{ + assert(sinkClassID!=0); + + if (!existSinkClass(sinkClassID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID); + std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + if (!sqQuery(command1)) + return E_DATABASE_ERROR; + + logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID); + if (mDatabaseObserver) + mDatabaseObserver->numberOfSinkClassesChanged(); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID) +{ + assert(sourceClassID!=0); + + if (!existSourceClass(sourceClassID)) + { + return E_NON_EXISTENT; + } + std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID); + std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + if (!sqQuery(command1)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID); + if (mDatabaseObserver) + mDatabaseObserver->numberOfSourceClassesChanged(); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::removeConnection(const am_connectionID_t connectionID) +{ + assert(connectionID!=0); + + std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID); + if (!sqQuery(command)) + return E_DATABASE_ERROR; + logInfo("DatabaseHandler::removeConnection removed:", connectionID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_ClassProperty_s propertyTemp; + std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID)); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + classInfo.sourceClassID = sqlite3_column_int(query, 0); + } + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID)); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + classInfo.name = std::string((const char*) sqlite3_column_text(query, 0)); + } + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + //read out Properties + command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0); + propertyTemp.value = sqlite3_column_int(query, 1); + classInfo.listClassProperties.push_back(propertyTemp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const +{ + + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + + sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; + int eCode = 0; + am_ConnectionFormat_e tempConnectionFormat; + am_SoundProperty_s tempSoundProperty; + am_MainSoundProperty_s tempMainSoundProperty; + std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 and sinkID=" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkData.name = std::string((const char*) sqlite3_column_text(query, 0)); + sinkData.domainID = sqlite3_column_int(query, 1); + sinkData.sinkClassID = sqlite3_column_int(query, 2); + sinkData.volume = sqlite3_column_int(query, 3); + sinkData.visible = sqlite3_column_int(query, 4); + sinkData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5); + sinkData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6); + sinkData.muteState = (am_MuteState_e) sqlite3_column_int(query, 7); + sinkData.mainVolume = sqlite3_column_int(query, 8); + sinkData.sinkID = sqlite3_column_int(query, 9); + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + sinkData.listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out sound properties + std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); + while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) + { + tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); + tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); + sinkData.listSoundProperties.push_back(tempSoundProperty); + } + + if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out MainSoundProperties + std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); + while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) + { + tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); + tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); + sinkData.listMainSoundProperties.push_back(tempMainSoundProperty); + } + + if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + } + + else if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + + sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; + int eCode = 0; + am_ConnectionFormat_e tempConnectionFormat; + am_SoundProperty_s tempSoundProperty; + am_MainSoundProperty_s tempMainSoundProperty; + std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceData.name = std::string((const char*) sqlite3_column_text(query, 0)); + sourceData.domainID = sqlite3_column_int(query, 1); + sourceData.sourceClassID = sqlite3_column_int(query, 2); + sourceData.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3); + sourceData.volume = sqlite3_column_int(query, 4); + sourceData.visible = sqlite3_column_int(query, 5); + sourceData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6); + sourceData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7); + sourceData.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8); + sourceData.sourceID = sqlite3_column_int(query, 9); + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + sourceData.listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out sound properties + std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); + while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) + { + tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); + tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); + sourceData.listSoundProperties.push_back(tempSoundProperty); + } + + if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out MainSoundProperties + std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); + while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) + { + tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); + tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); + sourceData.listMainSoundProperties.push_back(tempMainSoundProperty); + } + + if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + } + else if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e am::CAmDatabaseHandler::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const +{ + assert(mainConnectionID!=0); + if (!existMainConnection(mainConnectionID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt *query = NULL, *query1 = NULL; + int eCode = 0; + am_MainConnection_s temp; + std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); + std::string command1 = "SELECT connectionID FROM MainConnectionRoute"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + mainConnectionData.mainConnectionID = sqlite3_column_int(query, 0); + mainConnectionData.sourceID = sqlite3_column_int(query, 1); + mainConnectionData.sinkID = sqlite3_column_int(query, 2); + mainConnectionData.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); + mainConnectionData.delay = sqlite3_column_int(query, 4); + std::string statement = command1 + i2s(mainConnectionID); + sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL); + while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) + { + mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0)); + } + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getMainConnectionInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) +{ + assert(sinkClass.sinkClassID!=0); + assert(!sinkClass.listClassProperties.empty()); + + sqlite3_stmt* query = NULL; + int eCode = 0; + + //check if the ID already exists + if (!existSinkClass(sinkClass.sinkClassID)) + return E_NON_EXISTENT; + + //fill ConnectionFormats + std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); + for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) + { + sqlite3_bind_int(query, 1, Iterator->value); + sqlite3_bind_int(query, 2, Iterator->classProperty); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) +{ + assert(sourceClass.sourceClassID!=0); + assert(!sourceClass.listClassProperties.empty()); + + sqlite3_stmt* query = NULL; + int eCode = 0; + + //check if the ID already exists + if (!existSourceClass(sourceClass.sourceClassID)) + return E_NON_EXISTENT; + + //fill ConnectionFormats + std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator Iterator = sourceClass.listClassProperties.begin(); + for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) + { + sqlite3_bind_int(query, 1, Iterator->value); + sqlite3_bind_int(query, 2, Iterator->classProperty); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_ClassProperty_s propertyTemp; + std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID)); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkClass.sinkClassID = sqlite3_column_int(query, 0); + } + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID)); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0)); + } + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + //read out Properties + command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0); + propertyTemp.value = sqlite3_column_int(query, 1); + sinkClass.listClassProperties.push_back(propertyTemp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const +{ + assert(gatewayID!=0); + if (!existGateway(gatewayID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; + int eCode = 0; + am_ConnectionFormat_e tempConnectionFormat; + std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0)); + gatewayData.sinkID = sqlite3_column_int(query, 1); + gatewayData.sourceID = sqlite3_column_int(query, 2); + gatewayData.domainSinkID = sqlite3_column_int(query, 3); + gatewayData.domainSourceID = sqlite3_column_int(query, 4); + gatewayData.controlDomainID = sqlite3_column_int(query, 5); + gatewayData.gatewayID = sqlite3_column_int(query, 6); + + //convertionMatrix: + ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); + iter = mListConnectionFormat.find(gatewayData.gatewayID); + if (iter == mListConnectionFormat.end()) + { + logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"); + return E_DATABASE_ERROR; + } + gatewayData.convertionMatrix = iter->second; + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL); + while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0); + gatewayData.listSourceFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + //read out sound properties + commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL); + while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0); + gatewayData.listSinkFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; + +} + +am_Error_e CAmDatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const +{ + assert(crossfaderID!=0); + if (!existcrossFader(crossfaderID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0)); + crossfaderData.sinkID_A = sqlite3_column_int(query, 1); + crossfaderData.sinkID_B = sqlite3_column_int(query, 2); + crossfaderData.sourceID = sqlite3_column_int(query, 3); + crossfaderData.hotSink = static_cast(sqlite3_column_int(query, 4)); + crossfaderData.crossfaderID = sqlite3_column_int(query, 5); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getCrossfaderInfoDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const +{ + assert(domainID!=0); + listSinkID.clear(); + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_sinkID_t temp; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID)); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp = sqlite3_column_int(query, 0); + listSinkID.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const +{ + assert(domainID!=0); + listSourceID.clear(); + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_sourceID_t temp; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID); + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp = sqlite3_column_int(query, 0); + listSourceID.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listCrossfader) const +{ + assert(domainID!=0); + listCrossfader.clear(); + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_crossfaderID_t temp; + + std::string command = "SELECT c.crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " c," + std::string(SOURCE_TABLE) + " s WHERE c.sourceID=s.sourceID AND s.domainID=" + i2s(domainID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp = sqlite3_column_int(query, 0); + listCrossfader.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; + +} + +am_Error_e CAmDatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const +{ + assert(domainID!=0); + listGatewaysID.clear(); + if (!existDomain(domainID)) + { + return E_NON_EXISTENT; + } + sqlite3_stmt* query = NULL; + int eCode = 0; + am_gatewayID_t temp; + + std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp = sqlite3_column_int(query, 0); + listGatewaysID.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListMainConnections(std::vector & listMainConnections) const +{ + listMainConnections.clear(); + sqlite3_stmt *query = NULL, *query1 = NULL; + int eCode = 0; + am_MainConnection_s temp; + std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE); + std::string command1 = "SELECT connectionID FROM MainConnectionRoute"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.mainConnectionID = sqlite3_column_int(query, 0); + temp.sourceID = sqlite3_column_int(query, 1); + temp.sinkID = sqlite3_column_int(query, 2); + temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); + temp.delay = sqlite3_column_int(query, 4); + std::string statement = command1 + i2s(temp.mainConnectionID); + sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL); + while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) + { + temp.listConnectionID.push_back(sqlite3_column_int(query1, 0)); + } + listMainConnections.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListMainConnections SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListDomains(std::vector & listDomains) const +{ + listDomains.clear(); + sqlite3_stmt* query = NULL; + int eCode = 0; + am_Domain_s temp; + std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.domainID = sqlite3_column_int(query, 0); + temp.name = std::string((const char*) sqlite3_column_text(query, 1)); + temp.busname = std::string((const char*) sqlite3_column_text(query, 2)); + temp.nodename = std::string((const char*) sqlite3_column_text(query, 3)); + temp.early = sqlite3_column_int(query, 4); + temp.complete = sqlite3_column_int(query, 5); + temp.state = (am_DomainState_e) sqlite3_column_int(query, 6); + listDomains.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListDomains SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListDomains SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListConnections(std::vector & listConnections) const +{ + listConnections.clear(); + sqlite3_stmt* query = NULL; + int eCode = 0; + am_Connection_s temp; + std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.connectionID = sqlite3_column_int(query, 0); + temp.sourceID = sqlite3_column_int(query, 1); + temp.sinkID = sqlite3_column_int(query, 2); + temp.delay = sqlite3_column_int(query, 3); + temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4); + listConnections.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListConnections SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListConnections SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSinks(std::vector & listSinks) const +{ + listSinks.clear(); + sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; + int eCode = 0; + am_Sink_s temp; + am_ConnectionFormat_e tempConnectionFormat; + am_SoundProperty_s tempSoundProperty; + am_MainSoundProperty_s tempMainSoundProperty; + std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.name = std::string((const char*) sqlite3_column_text(query, 0)); + temp.domainID = sqlite3_column_int(query, 1); + temp.sinkClassID = sqlite3_column_int(query, 2); + temp.volume = sqlite3_column_int(query, 3); + temp.visible = sqlite3_column_int(query, 4); + temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5); + temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6); + temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7); + temp.mainVolume = sqlite3_column_int(query, 8); + temp.sinkID = sqlite3_column_int(query, 9); + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + temp.listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out sound properties + std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID); + sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); + while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) + { + tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); + tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); + temp.listSoundProperties.push_back(tempSoundProperty); + } + + if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out MainSoundProperties + std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID); + sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); + while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) + { + tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); + tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); + temp.listMainSoundProperties.push_back(tempMainSoundProperty); + } + + if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + listSinks.push_back(temp); + temp.listConnectionFormats.clear(); + temp.listMainSoundProperties.clear(); + temp.listSoundProperties.clear(); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSinks SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSources(std::vector & listSources) const +{ + listSources.clear(); + sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; + int eCode = 0; + am_Source_s temp; + am_ConnectionFormat_e tempConnectionFormat; + am_SoundProperty_s tempSoundProperty; + am_MainSoundProperty_s tempMainSoundProperty; + std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.name = std::string((const char*) sqlite3_column_text(query, 0)); + temp.domainID = sqlite3_column_int(query, 1); + temp.sourceClassID = sqlite3_column_int(query, 2); + temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3); + temp.volume = sqlite3_column_int(query, 4); + temp.visible = sqlite3_column_int(query, 5); + temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6); + temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7); + temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8); + temp.sourceID = sqlite3_column_int(query, 9); + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + temp.listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out sound properties + std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID); + sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); + while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) + { + tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); + tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); + temp.listSoundProperties.push_back(tempSoundProperty); + } + + if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out MainSoundProperties + std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID); + sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); + while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) + { + tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); + tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); + temp.listMainSoundProperties.push_back(tempMainSoundProperty); + } + + if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + listSources.push_back(temp); + temp.listConnectionFormats.clear(); + temp.listMainSoundProperties.clear(); + temp.listSoundProperties.clear(); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSources SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSourceClasses(std::vector & listSourceClasses) const +{ + listSourceClasses.clear(); + + sqlite3_stmt* query = NULL, *subQuery = NULL; + int eCode = 0, eCode1; + am_SourceClass_s classTemp; + am_ClassProperty_s propertyTemp; + + std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE); + std::string command2; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + classTemp.sourceClassID = sqlite3_column_int(query, 0); + classTemp.name = std::string((const char*) sqlite3_column_text(query, 1)); + + //read out Properties + command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID); + sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL); + + while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW) + { + propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0); + propertyTemp.value = sqlite3_column_int(subQuery, 1); + classTemp.listClassProperties.push_back(propertyTemp); + } + + if (eCode1 != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1); + + return E_DATABASE_ERROR; + } + + if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode1); + + return E_DATABASE_ERROR; + } + listSourceClasses.push_back(classTemp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListCrossfaders(std::vector & listCrossfaders) const +{ + listCrossfaders.clear(); + sqlite3_stmt* query = NULL; + int eCode = 0; + am_Crossfader_s tempData; + std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + tempData.name = std::string((const char*) sqlite3_column_text(query, 0)); + tempData.sinkID_A = sqlite3_column_int(query, 1); + tempData.sinkID_B = sqlite3_column_int(query, 2); + tempData.sourceID = sqlite3_column_int(query, 3); + tempData.hotSink = static_cast(sqlite3_column_int(query, 4)); + tempData.crossfaderID = sqlite3_column_int(query, 5); + listCrossfaders.push_back(tempData); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode); + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListCrossfaders SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListGateways(std::vector & listGateways) const +{ + listGateways.clear(); + sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; + int eCode = 0; + am_Gateway_s temp; + am_ConnectionFormat_e tempConnectionFormat; + + std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.name = std::string((const char*) sqlite3_column_text(query, 0)); + temp.sinkID = sqlite3_column_int(query, 1); + temp.sourceID = sqlite3_column_int(query, 2); + temp.domainSinkID = sqlite3_column_int(query, 3); + temp.domainSourceID = sqlite3_column_int(query, 4); + temp.controlDomainID = sqlite3_column_int(query, 5); + temp.gatewayID = sqlite3_column_int(query, 6); + + //convertionMatrix: + ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); + iter = mListConnectionFormat.find(temp.gatewayID); + if (iter == mListConnectionFormat.end()) + { + logError("DatabaseHandler::getListGateways database error with convertionFormat"); + + return E_DATABASE_ERROR; + } + temp.convertionMatrix = iter->second; + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL); + while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0); + temp.listSourceFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //read out sound properties + commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL); + while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0); + temp.listSinkFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + listGateways.push_back(temp); + temp.listSinkFormats.clear(); + temp.listSourceFormats.clear(); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListGateways SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSinkClasses(std::vector & listSinkClasses) const +{ + listSinkClasses.clear(); + + sqlite3_stmt* query = NULL, *subQuery = NULL; + int eCode = 0; + am_SinkClass_s classTemp; + am_ClassProperty_s propertyTemp; + + std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE); + std::string command2; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + classTemp.sinkClassID = sqlite3_column_int(query, 0); + classTemp.name = std::string((const char*) sqlite3_column_text(query, 1)); + + //read out Properties + command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID); + sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL); + + while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW) + { + propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0); + propertyTemp.value = sqlite3_column_int(subQuery, 1); + classTemp.listClassProperties.push_back(propertyTemp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + listSinkClasses.push_back(classTemp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListVisibleMainConnections(std::vector & listConnections) const +{ + listConnections.clear(); + sqlite3_stmt *query = NULL; + int eCode = 0; + am_MainConnectionType_s temp; + + std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.mainConnectionID = sqlite3_column_int(query, 0); + temp.sourceID = sqlite3_column_int(query, 1); + temp.sinkID = sqlite3_column_int(query, 2); + temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); + temp.delay = sqlite3_column_int(query, 4); + listConnections.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListMainSinks(std::vector & listMainSinks) const +{ + listMainSinks.clear(); + sqlite3_stmt* query = NULL; + int eCode = 0; + am_SinkType_s temp; + + std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.name = std::string((const char*) sqlite3_column_text(query, 0)); + temp.sinkID = sqlite3_column_int(query, 1); + temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2); + temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3); + temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4); + temp.volume = sqlite3_column_int(query, 5); + temp.sinkClassID = sqlite3_column_int(query, 6); + listMainSinks.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSinks SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListMainSources(std::vector & listMainSources) const +{ + listMainSources.clear(); + sqlite3_stmt* query = NULL; + int eCode = 0; + am_SourceType_s temp; + std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.name = std::string((const char*) sqlite3_column_text(query, 0)); + temp.sourceClassID = sqlite3_column_int(query, 1); + temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2); + temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3); + temp.sourceID = sqlite3_column_int(query, 4); + + listMainSources.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSources SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences + listSoundProperties.clear(); + + sqlite3_stmt* query = NULL; + int eCode = 0; + am_MainSoundProperty_s temp; + std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0); + temp.value = sqlite3_column_int(query, 1); + listSoundProperties.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences + listSourceProperties.clear(); + + sqlite3_stmt* query = NULL; + int eCode = 0; + am_MainSoundProperty_s temp; + std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0); + temp.value = sqlite3_column_int(query, 1); + listSourceProperties.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getListSystemProperties(std::vector & listSystemProperties) const +{ + listSystemProperties.clear(); + + sqlite3_stmt* query = NULL; + int eCode = 0; + am_SystemProperty_s temp; + std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0); + temp.value = sqlite3_column_int(query, 1); + listSystemProperties.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e am::CAmDatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const +{ + listConnectionFormats.clear(); + sqlite3_stmt *qConnectionFormat = NULL; + int eCode = 0; + am_ConnectionFormat_e tempConnectionFormat; + std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e am::CAmDatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const +{ + listConnectionFormats.clear(); + sqlite3_stmt* qConnectionFormat = NULL; + int eCode = 0; + am_ConnectionFormat_e tempConnectionFormat; + + //read out the connectionFormats + std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); + while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) + { + tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); + listConnectionFormats.push_back(tempConnectionFormat); + } + + if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) + { + logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e am::CAmDatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const +{ + ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); + iter = mListConnectionFormat.find(gatewayID); + if (iter == mListConnectionFormat.end()) + { + logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat"); + + return (E_DATABASE_ERROR); + } + listConnectionFormat = iter->second; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const +{ + assert(mainConnectionID!=0); + delay = -1; + sqlite3_stmt *query = NULL; + int eCode = 0; + + std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + delay = sqlite3_column_int(query, 0); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getTimingInformation SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + if (delay == -1) + return E_NOT_POSSIBLE; + + return E_OK; +} + +bool CAmDatabaseHandler::sqQuery(const std::string& query) +{ + sqlite3_stmt* statement; + int eCode = 0; + if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK) + { + logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode); + return false; + } + return true; +} + +bool CAmDatabaseHandler::openDatabase() +{ + if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) + { + logInfo("DatabaseHandler::openDatabase opened database"); + return true; + } + logError("DatabaseHandler::openDatabase failed to open database"); + return false; +} + +am_Error_e CAmDatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) +{ + assert(connectionID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, delay); + sqlite3_bind_int(query, 2, connectionID); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + sqlite3_finalize(query); + return E_OK; + } + command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, delay); + sqlite3_bind_int(query, 2, connectionID); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + if (mDatabaseObserver) + mDatabaseObserver->timingInformationChanged(connectionID, delay); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID) +{ + assert(connection.connectionID==0); + assert(connection.sinkID!=0); + assert(connection.sourceID!=0); + //connection format is not checked, because it's project specific + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, connection.sinkID); + sqlite3_bind_int(query, 2, connection.sourceID); + sqlite3_bind_int(query, 3, connection.delay); + sqlite3_bind_int(query, 4, connection.connectionFormat); + sqlite3_bind_int(query, 5, true); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + connectionID = sqlite3_last_insert_rowid(mDatabase); + + logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) +{ + assert(sinkClass.sinkClassIDsqQuery(command)); + + //fill ConnectionFormats + command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); + for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) + { + sqlite3_bind_int(query, 1, Iterator->classProperty); + sqlite3_bind_int(query, 2, Iterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass"); + if (mDatabaseObserver) + mDatabaseObserver->numberOfSinkClassesChanged(); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) +{ + assert(sourceClass.sourceClassID::const_iterator Iterator = sourceClass.listClassProperties.begin(); + for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) + { + sqlite3_bind_int(query, 1, Iterator->classProperty); + sqlite3_bind_int(query, 2, Iterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass"); + + if (mDatabaseObserver) + mDatabaseObserver->numberOfSourceClassesChanged(); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::enterSystemProperties(const std::vector & listSystemProperties) +{ + assert(!listSystemProperties.empty()); + sqlite3_stmt* query = NULL; + int eCode = 0; + std::vector::const_iterator listIterator = listSystemProperties.begin(); + std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE); + sqQuery(command); + + command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + for (; listIterator < listSystemProperties.end(); ++listIterator) + { + sqlite3_bind_int(query, 1, listIterator->type); + sqlite3_bind_int(query, 2, listIterator->value); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + sqlite3_reset(query); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::enterSystemProperties entered system properties"); + return E_OK; +} + +bool CAmDatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existMainConnection database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSource(const am_sourceID_t sourceID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSource database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + sqlite3_bind_int(query, 2, sourceID); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSource database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSourceName(const std::string & name) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSource database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSink(const am_sinkID_t sinkID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSink database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + sqlite3_bind_int(query, 2, sinkID); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSink database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSinkName(const std::string & name) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSink database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existDomain(const am_domainID_t domainID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existDomain database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existGateway database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +am_Error_e CAmDatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const +{ + assert(sourceID!=0); + + sqlite3_stmt* query = NULL; + std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); + int eCode = 0; + am_Error_e returnVal = E_DATABASE_ERROR; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + domainID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else + { + logError("DatabaseHandler::getDomainOfSource database error!:", eCode); + } + sqlite3_finalize(query); + return (returnVal); +} + +am_Error_e am::CAmDatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const +{ + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); + int eCode = 0; + am_Error_e returnVal = E_DATABASE_ERROR; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + domainID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else + { + logError("DatabaseHandler::getDomainOfSink database error!:", eCode); + } + sqlite3_finalize(query); + return (returnVal); +} + +bool CAmDatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSinkClass database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID); + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existSinkClass database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +am_Error_e CAmDatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) +{ + assert(connectionID!=0); + + sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs; + int eCode = 0, eCode1 = 0; + std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, delay); + sqlite3_bind_int(query, 2, connectionID); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + //now we need to find all mainConnections that use the changed connection and update their timing + + int tempMainConnectionID; + //first get all route tables for all mainconnections + command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL); + + while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW) + { + //now check if the connection ID is in this table + std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0)); + std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID); + sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL); + if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW) + { + //if the connection ID is in, recalculate the mainconnection delay + std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID; + changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID); + } + else if (eCode1 != SQLITE_DONE) + { + logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1); + + return E_DATABASE_ERROR; + } + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK) + { + logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID) +{ + assert(connectionID!=0); + + sqlite3_stmt *query = NULL; + int eCode = 0; + std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?"; + + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, connectionID); + + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + return E_OK; +} + +am_timeSync_t CAmDatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const +{ + assert(mainConnectionID!=0); + sqlite3_stmt* query = NULL; + std::string command = "SELECT sum(Connections.delay),min(Connections.delay) FROM " + std::string(CONNECTION_TABLE) + ",MainConnectionRoute" + i2s(mainConnectionID) + " WHERE MainConnectionRoute" + i2s(mainConnectionID) + ".connectionID = Connections.connectionID"; + int eCode = 0; + am_timeSync_t delay = 0; + am_timeSync_t min = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + delay = sqlite3_column_int(query, 0); + min = sqlite3_column_int(query, 1); + } + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + if (min < 0) + delay = -1; + return delay; + +} + +void CAmDatabaseHandler::registerObserver(CAmDatabaseObserver *iObserver) +{ + assert(iObserver!=NULL); + mDatabaseObserver = iObserver; +} + +bool CAmDatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const +{ + assert(sourceID!=0); + sqlite3_stmt* query = NULL; + std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); + int eCode = 0; + bool returnVal = false; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + returnVal = (bool) sqlite3_column_int(query, 0); + } + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::sourceVisible database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID); + int eCode = 0; + bool returnVal = false; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + returnVal = sqlite3_column_int(query, 0); + } + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::sinkVisible database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existConnection(const am_Connection_s connection) +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, connection.sinkID); + sqlite3_bind_int(query, 2, connection.sourceID); + sqlite3_bind_int(query, 3, connection.connectionFormat); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existMainConnection database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existConnectionID(const am_connectionID_t connectionID) +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, connectionID); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existMainConnection database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +bool CAmDatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const +{ + sqlite3_stmt* query = NULL; + std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?"; + int eCode = 0; + bool returnVal = true; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, crossfaderID); + if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + returnVal = false; + else if (eCode != SQLITE_ROW) + { + returnVal = false; + logError("DatabaseHandler::existMainConnection database error!:", eCode); + } + sqlite3_finalize(query); + return returnVal; +} + +am_Error_e CAmDatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const +{ + assert(sourceID!=0); + sqlite3_stmt* query = NULL; + sourceState = SS_UNKNNOWN; + std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); + int eCode = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceState = (am_SourceState_e) sqlite3_column_int(query, 0); + } + else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + logError("DatabaseHandler::getSoureState database error!:", eCode); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) +{ + assert(sourceID!=0); + assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX); + sqlite3_stmt* query = NULL; + std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID); + int eCode = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, sourceState); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSourceState SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const +{ + assert(sinkID!=0); + sqlite3_stmt* query = NULL; + volume = -1; + std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); + int eCode = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + volume = sqlite3_column_int(query, 0); + } + else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + logError("DatabaseHandler::getSinkVolume database error!:", eCode); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const +{ + assert(sourceID!=0); + sqlite3_stmt* query = NULL; + volume = -1; + std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); + int eCode = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + volume = sqlite3_column_int(query, 0); + } + else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + logError("DatabaseHandler::getSourceVolume database error!:", eCode); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + value = sqlite3_column_int(query, 0); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + value = sqlite3_column_int(query, 0); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const +{ + assert(domainID!=0); + sqlite3_stmt* query = NULL; + state = DS_UNKNOWN; + std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID); + int eCode = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + state = (am_DomainState_e) sqlite3_column_int(query, 0); + } + else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) + { + logError("DatabaseHandler::getDomainState database error!:", eCode); + } + sqlite3_finalize(query); + return E_OK; + +} + +am_Error_e CAmDatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID) +{ + sqlite3_stmt* query = NULL, *queryInsert = NULL; + std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; + int eCode = 0, eCode1 = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + domainID = sqlite3_column_int(query, 0); + } + else if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::peekDomain database error!:", eCode); + return E_DATABASE_ERROR; + } + else + { + command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); + sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); + sqlite3_bind_int(queryInsert, 2, 1); //reservation flag + if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) + { + logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1); + return E_DATABASE_ERROR; + } + + if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) + { + logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); + return E_DATABASE_ERROR; + } + domainID = sqlite3_last_insert_rowid(mDatabase); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID) +{ + sqlite3_stmt* query = NULL, *queryInsert = NULL; + std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?"; + int eCode = 0, eCode1 = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkID = sqlite3_column_int(query, 0); + } + else if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::peekSink database error!:", eCode); + return E_DATABASE_ERROR; + } + else + { + if (mFirstStaticSink) + { + command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")"; + mFirstStaticSink = false; + } + else + { + command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)"; + } + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); + sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); + sqlite3_bind_int(queryInsert, 2, 1); //reservation flag + if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) + { + logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); + return E_DATABASE_ERROR; + } + + if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) + { + logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); + return E_DATABASE_ERROR; + } + sinkID = sqlite3_last_insert_rowid(mDatabase); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID) +{ + sqlite3_stmt* query = NULL, *queryInsert = NULL; + std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?"; + int eCode = 0, eCode1 = 0; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceID = sqlite3_column_int(query, 0); + } + else if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::peekSink database error!:", eCode); + return E_DATABASE_ERROR; + } + else + { + if (mFirstStaticSource) + { + command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")"; + mFirstStaticSource = false; + } + else + { + command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)"; + } + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); + sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); + sqlite3_bind_int(queryInsert, 2, 1); //reservation flag + if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) + { + logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); + return E_DATABASE_ERROR; + } + + if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) + { + logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); + return E_DATABASE_ERROR; + } + sourceID = sqlite3_last_insert_rowid(mDatabase); + } + sqlite3_finalize(query); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) +{ + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, volume); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) +{ + assert(sourceID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, volume); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX); + assert(sourceID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSource(sourceID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, soundProperty.value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX); + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existSink(sinkID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, soundProperty.value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode); + return E_DATABASE_ERROR; + }assert(sinkID!=0); + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:", eCode); + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); + + return E_OK; +} + +am_Error_e CAmDatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) +{ + assert(crossfaderID!=0); + assert(hotsink>=HS_UNKNOWN && hotsink>=HS_MAX); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + + if (!existcrossFader(crossfaderID)) + { + return E_NON_EXISTENT; + } + command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, hotsink); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode); + + return E_DATABASE_ERROR; + } + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:", eCode); + + return E_DATABASE_ERROR; + } + + logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink); + return E_OK; +} + +am_Error_e CAmDatabaseHandler::getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector& flatTree) +{ + sqlite3_stmt* query = NULL; + int eCode = 0; + size_t i = 0; + std::string command; + am_domainID_t rootID = tree.returnRootDomainID(); + CAmRoutingTreeItem *parent = tree.returnRootItem(); + + if (onlyfree) + { + command = "SELECT g.domainSourceID,g.gatewayID FROM " + std::string(GATEWAY_TABLE) + " g WHERE domainSinkID=? AND NOT EXISTS (SELECT NULL FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = g.sinkID OR c.sourceID = g.sourceID )"; + } + else + { + command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?"; + } + + do + { + if (i != 0) + { + parent = flatTree.at(i - 1); + rootID = parent->returnDomainID(); + } + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_int(query, 1, rootID); + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent)); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode); + + return (E_DATABASE_ERROR); + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::getRoutingTree SQLITE Finalize error code:", eCode); + + return (E_DATABASE_ERROR); + } + i++; + } while (flatTree.size() > (i - 1)); + + return (E_OK); +} + +am_Error_e am::CAmDatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID) +{ + if (name.empty()) + return E_NON_EXISTENT; + + am_Error_e returnVal = E_NON_EXISTENT; + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkClassID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else if (eCode != SQLITE_DONE) + { + sinkClassID = 0; + logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::peekSinkClassID SQLITE Finalize error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + return returnVal; +} + +am_Error_e am::CAmDatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID) +{ + if (name.empty()) + return E_NON_EXISTENT; + + am_Error_e returnVal = E_NON_EXISTENT; + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceClassID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else if (eCode != SQLITE_DONE) + { + sourceClassID = 0; + logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::peekSourceClassID SQLITE Finalize error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + return returnVal; +} + +void CAmDatabaseHandler::createTables() +{ + for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++) + { + assert(sqQuery("CREATE TABLE " + databaseTables[i])); + } +} +} diff --git a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp new file mode 100644 index 0000000..9bbc275 --- /dev/null +++ b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp @@ -0,0 +1,207 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDatabaseObserver.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 statiasyncCally or dynamiasyncCally 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 "CAmDatabaseObserver.h" +#include +#include +#include +#include +#include +#include "CAmCommandSender.h" +#include "CAmRoutingSender.h" +#include "CAmTelnetServer.h" +#include "shared/CAmDltWrapper.h" +#include "shared/CAmSerializer.h" + +namespace am { + +CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : + mCommandSender(iCommandSender), // + mRoutingSender(iRoutingSender), // + mSerializer(iSocketHandler) // +{ + assert(mCommandSender!=0); + assert(mRoutingSender!=0); + assert(iSocketHandler!=0); +} + +CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler, CAmTelnetServer *iTelnetServer) : + mCommandSender(iCommandSender), // + mRoutingSender(iRoutingSender), // + mTelnetServer(iTelnetServer), // + mSerializer(iSocketHandler) // +{ + assert(mTelnetServer!=0); + assert(mCommandSender!=0); + assert(mRoutingSender!=0); + assert(iSocketHandler!=0); +} + +CAmDatabaseObserver::~CAmDatabaseObserver() +{ +} + +void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewMainConnection, mainConnection); +} + +void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedMainConnection, mainConnection); +} + +void CAmDatabaseObserver::newSink(const am_Sink_s& sink) +{ + mRoutingSender->addSinkLookup(sink); + if (sink.visible) + { + am_SinkType_s s; + s.availability = sink.available; + s.muteState = sink.muteState; + s.name = sink.name; + s.sinkClassID = sink.sinkClassID; + s.sinkID = sink.sinkID; + s.volume = sink.mainVolume; + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewSink, s); + } +} + +void CAmDatabaseObserver::newSource(const am_Source_s& source) +{ + mRoutingSender->addSourceLookup(source); + if (source.visible) + { + am_SourceType_s s; + s.availability = source.available; + s.name = source.name; + s.sourceClassID = source.sourceClassID; + s.sourceID = source.sourceID; + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewSource, s); + } +} + +void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) +{ + mRoutingSender->addDomainLookup(domain); +} + +void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) +{ + (void) gateway; + //todo: implement something +} + +void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) +{ + mRoutingSender->addCrossfaderLookup(crossfader); +} + +void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) +{ + mRoutingSender->removeSinkLookup(sinkID); + + if (visible) + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedSink, sinkID); +} + +void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) +{ + mRoutingSender->removeSourceLookup(sourceID); + + if (visible) + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedSource, sourceID); +} + +void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) +{ + mRoutingSender->removeDomainLookup(domainID); +} + +void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) +{ + (void) gatewayID; + //todo: implement something? +} + +void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) +{ + mRoutingSender->removeCrossfaderLookup(crossfaderID); +} + +void CAmDatabaseObserver::numberOfSinkClassesChanged() +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNumberOfSinkClassesChanged); +} + +void CAmDatabaseObserver::numberOfSourceClassesChanged() +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNumberOfSourceClassesChanged); +} + +void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainConnectionStateChanged, connectionID, connectionState); +} + +void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainSinkSoundPropertyChanged, sinkID, SoundProperty); +} + +void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainSourceSoundPropertyChanged, sourceID, SoundProperty); +} + +void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSinkAvailabilityChanged, sinkID, availability); +} + +void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSourceAvailabilityChanged, sourceID, availability); +} + +void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbVolumeChanged, sinkID, volume); +} + +void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSinkMuteStateChanged, sinkID, muteState); +} + +void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSystemPropertyChanged, SystemProperty); +} + +void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbTimingInformationChanged, mainConnection, time); +} +} diff --git a/AudioManagerDaemon/src/CAmDbusWrapper.cpp b/AudioManagerDaemon/src/CAmDbusWrapper.cpp new file mode 100644 index 0000000..082d62f --- /dev/null +++ b/AudioManagerDaemon/src/CAmDbusWrapper.cpp @@ -0,0 +1,434 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmSocketHandler.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "shared/CAmDbusWrapper.h" +#include +#include +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +#define ROOT_INTROSPECT_XML \ +DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ +"" \ +"" \ +"" \ +" " \ +"" \ +"" \ + +CAmDbusWrapper* CAmDbusWrapper::mpReference = NULL; + +CAmDbusWrapper::CAmDbusWrapper(CAmSocketHandler* socketHandler) : + pDbusDispatchCallback(this, &CAmDbusWrapper::dbusDispatchCallback), // + pDbusFireCallback(this, &CAmDbusWrapper::dbusFireCallback), // + pDbusCheckCallback(this, &CAmDbusWrapper::dbusCheckCallback), // + pDbusTimerCallback(this, &CAmDbusWrapper::dbusTimerCallback), // + mpDbusConnection(0), // + mDBusError(), // + mListNodes(), // + mpListTimerhandles(), // + mpSocketHandler(socketHandler) +{ + assert(mpSocketHandler!=0); + + dbus_error_init(&mDBusError); + logInfo("DBusWrapper::DBusWrapper Opening DBus connection"); + mpDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError); + if (dbus_error_is_set(&mDBusError)) + { + logError("DBusWrapper::DBusWrapper Error while getting the DBus"); + dbus_error_free(&mDBusError); + } + if (NULL == mpDbusConnection) + { + logError("DBusWrapper::DBusWrapper DBus Connection is null"); + } + + //then we need to adopt the dbus to our mainloop: + //first, we are old enought to live longer then the connection: + dbus_connection_set_exit_on_disconnect(mpDbusConnection, FALSE); + + //we do not need the manual dispatching, since it is not allowed to call from a different thread. So leave it uncommented: + //dbus_connection_set_dispatch_status_function + + //add watch functions: + dbus_bool_t watch = dbus_connection_set_watch_functions(mpDbusConnection, addWatch, removeWatch, toogleWatch, this, NULL); + if (!watch) + { + logError("DBusWrapper::DBusWrapper Registering of watch functions failed"); + } + + //add timer functions: + dbus_bool_t timer = dbus_connection_set_timeout_functions(mpDbusConnection, addTimeout, removeTimeout, toggleTimeout, this, NULL); + if (!timer) + { + logError("DBusWrapper::DBusWrapper Registering of timer functions failed"); + } + + //register callback for Introspectio + mObjectPathVTable.message_function = CAmDbusWrapper::cbRootIntrospection; + dbus_connection_register_object_path(mpDbusConnection, DBUS_SERVICE_OBJECT_PATH, &mObjectPathVTable, this); + int ret = dbus_bus_request_name(mpDbusConnection, DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_DO_NOT_QUEUE, &mDBusError); + if (dbus_error_is_set(&mDBusError)) + { + logError("DBusWrapper::DBusWrapper Name Error",mDBusError.message); + dbus_error_free(&mDBusError); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?",ret); + exit(1); + } +} + +CAmDbusWrapper::~CAmDbusWrapper() +{ + //close the connection again + logInfo("DBusWrapper::~DBusWrapper Closing DBus connection"); + dbus_connection_unref(mpDbusConnection); + + //clean up all timerhandles we created but did not delete before + std::vector::iterator it = mpListTimerhandles.begin(); + for (; it != mpListTimerhandles.end(); ++it) + { + delete *it; + } +} + +void CAmDbusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata) +{ + logInfo("DBusWrapper::~registerCallback register callback:",path); + + std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path; + dbus_error_init(&mDBusError); + mpDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError); + dbus_connection_register_object_path(mpDbusConnection, completePath.c_str(), vtable, userdata); + if (dbus_error_is_set(&mDBusError)) + { + logError("DBusWrapper::registerCallack error: ",mDBusError.message); + dbus_error_free(&mDBusError); + } + mListNodes.push_back(path); +} + +DBusHandlerResult CAmDbusWrapper::cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference) +{ + logInfo("DBusWrapper::~cbRootIntrospection called:"); + + mpReference = (CAmDbusWrapper*) reference; + std::list nodesList = mpReference->mListNodes; + DBusMessage * reply; + DBusMessageIter args; + dbus_uint32_t serial = 0; + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) + { + std::list::iterator nodeIter = nodesList.begin(); + const char *xml = ROOT_INTROSPECT_XML; + std::stringstream introspect; + introspect << std::string(xml); + for (; nodeIter != nodesList.end(); ++nodeIter) + { + introspect << ""; + } + introspect << ""; + + 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)) + { + logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"); + } + + // send the reply && flush the connection + if (!dbus_connection_send(conn, reply, &serial)) + { + logError("DBusWrapper::~cbRootIntrospection 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; + } +} + +void CAmDbusWrapper::getDBusConnection(DBusConnection *& connection) const +{ + connection = mpDbusConnection; +} + +dbus_bool_t CAmDbusWrapper::addWatch(DBusWatch *watch, void *userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + return mpReference->addWatchDelegate(watch, userData); +} + +dbus_bool_t CAmDbusWrapper::addWatchDelegate(DBusWatch * watch, void* userData) +{ + (void) userData; + int16_t event = 0; + sh_pollHandle_t handle = 0; + uint flags = dbus_watch_get_flags(watch); + + /* no watch flags for disabled watches */ + if (dbus_watch_get_enabled(watch)) + { + if (flags & DBUS_WATCH_READABLE) + event |= POLLIN; + if (flags & DBUS_WATCH_WRITABLE) + event |= POLLOUT; + } + + logInfo("DBusWrapper::addWatchDelegate entered new watch, fd=",dbus_watch_get_unix_fd(watch),"event flag=",event); + am_Error_e error = mpSocketHandler->addFDPoll(dbus_watch_get_unix_fd(watch), event, NULL, &pDbusFireCallback, &pDbusCheckCallback, &pDbusDispatchCallback, watch, handle); + + //if everything is alright, add the watch and the handle to our map so we know this relationship + if (error == E_OK && handle != 0) + { + mMapHandleWatch.insert(std::make_pair(watch, handle)); + return true; + } + logError("DBusWrapper::addWatchDelegate entering watch failed"); + return (true); +} + +void CAmDbusWrapper::removeWatch(DBusWatch *watch, void *userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + mpReference->removeWatchDelegate(watch, userData); +} + +void CAmDbusWrapper::removeWatchDelegate(DBusWatch *watch, void *userData) +{ + (void) userData; + std::map::iterator iterator = mMapHandleWatch.begin(); + iterator = mMapHandleWatch.find(watch); + if (iterator != mMapHandleWatch.end()) + mpSocketHandler->removeFDPoll(iterator->second); + logInfo("DBusWrapper::removeWatch removed watch with handle",iterator->second); + mMapHandleWatch.erase(iterator); +} + +void CAmDbusWrapper::toogleWatch(DBusWatch *watch, void *userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + mpReference->toogleWatchDelegate(watch, userData); +} + +void CAmDbusWrapper::toogleWatchDelegate(DBusWatch *watch, void *userData) +{ + (void) userData; + int16_t event = 0; + dbus_watch_get_unix_fd(watch); + uint flags = dbus_watch_get_flags(watch); + /* no watch flags for disabled watches */ + if (dbus_watch_get_enabled(watch)) + { + if (flags & DBUS_WATCH_READABLE) + event |= POLLIN; + if (flags & DBUS_WATCH_WRITABLE) + event |= POLLOUT; + } + std::map::iterator iterator = mMapHandleWatch.begin(); + iterator = mMapHandleWatch.find(watch); + if (iterator != mMapHandleWatch.end()) + mpSocketHandler->updateEventFlags(iterator->second, event); + logInfo("DBusWrapper::toogleWatchDelegate watch was toggeled"); +} + +dbus_bool_t CAmDbusWrapper::addTimeout(DBusTimeout *timeout, void* userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + return mpReference->addTimeoutDelegate(timeout, userData); +} + +dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData) +{ + if (!dbus_timeout_get_enabled(timeout)) + return false; + + //calculate the timeout in timeval + timespec pollTimeout; + int localTimeout = dbus_timeout_get_interval(timeout); + pollTimeout.tv_sec = localTimeout / 1000; + pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; + + //prepare handle and callback. new is eval, but there is no other choice because we need the pointer! + sh_timerHandle_t* handle = new sh_timerHandle_t; + mpListTimerhandles.push_back(handle); + CAmShTimerCallBack* buffer = &pDbusTimerCallback; + + //add the timer to the pollLoop + mpSocketHandler->addTimer(pollTimeout, buffer, *handle, timeout); + + //save the handle with dbus context + dbus_timeout_set_data(timeout, handle, NULL); + + //save timeout in Socket context + userData = timeout; + logInfo("DBusWrapper::addTimeoutDelegate a timeout was added"); + return true; +} + +void CAmDbusWrapper::removeTimeout(DBusTimeout *timeout, void* userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + mpReference->removeTimeoutDelegate(timeout, userData); +} + +void CAmDbusWrapper::removeTimeoutDelegate(DBusTimeout *timeout, void* userData) +{ + (void) userData; + //get the pointer to the handle and remove the timer + sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); + mpSocketHandler->removeTimer(*handle); + + //now go throught the timerlist and remove the pointer, free memory + std::vector::iterator it = mpListTimerhandles.begin(); + for (; it != mpListTimerhandles.end(); ++it) + { + if (*it == handle) + { + mpListTimerhandles.erase(it); + break; + } + } + delete handle; + logInfo("DBusWrapper::removeTimeoutDelegate a timeout was removed"); +} + +void CAmDbusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData) +{ + mpReference = (CAmDbusWrapper*) userData; + assert(mpReference!=0); + mpReference->toggleTimeoutDelegate(timeout, userData); +} + +bool am::CAmDbusWrapper::dbusDispatchCallback(const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + bool returnVal = true; + dbus_connection_ref(mpDbusConnection); + if (dbus_connection_dispatch(mpDbusConnection) == DBUS_DISPATCH_COMPLETE) + returnVal = false; + dbus_connection_unref(mpDbusConnection); +// logInfo("DBusWrapper::dbusDispatchCallback was called"); + return returnVal; +} + +bool am::CAmDbusWrapper::dbusCheckCallback(const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + bool returnVal = false; + dbus_connection_ref(mpDbusConnection); + if (dbus_connection_get_dispatch_status(mpDbusConnection) == DBUS_DISPATCH_DATA_REMAINS) + returnVal = true; + dbus_connection_unref(mpDbusConnection); +// logInfo("DBusWrapper::dbusCheckCallback was called"); + return returnVal; +} + +void am::CAmDbusWrapper::dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + assert(userData!=NULL); + uint flags = 0; + + if (pollfd.revents & POLLIN) + flags |= DBUS_WATCH_READABLE; + if (pollfd.revents & POLLOUT) + flags |= DBUS_WATCH_WRITABLE; + if (pollfd.revents & POLLHUP) + flags |= DBUS_WATCH_HANGUP; + if (pollfd.revents & POLLERR) + flags |= DBUS_WATCH_ERROR; + + DBusWatch *watch = (DBusWatch*) userData; + + dbus_connection_ref(mpDbusConnection); + dbus_watch_handle(watch, flags); + dbus_connection_unref(mpDbusConnection); +// logInfo("DBusWrapper::dbusFireCallback was called"); +} + +void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) +{ + (void) userData; + //get the pointer to the handle and remove the timer + sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); + + //stop or restart? + if (dbus_timeout_get_enabled(timeout)) + { + //calculate the timeout in timeval + timespec pollTimeout; + int localTimeout = dbus_timeout_get_interval(timeout); + pollTimeout.tv_sec = localTimeout / 1000; + pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; + mpSocketHandler->restartTimer(*handle, pollTimeout); + } + else + { + mpSocketHandler->stopTimer(*handle); + }logInfo("DBusWrapper::toggleTimeoutDelegate was called"); +} + +void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) +{ + assert(userData!=NULL); + if (dbus_timeout_get_enabled((DBusTimeout*) userData)) + { + timespec ts; + ts.tv_nsec = -1; + ts.tv_sec = -1; + mpSocketHandler->restartTimer(handle, ts); + } + dbus_timeout_handle((DBusTimeout*) userData); + logInfo("DBusWrapper::dbusTimerCallback was called"); +} +} + diff --git a/AudioManagerDaemon/src/CAmDltWrapper.cpp b/AudioManagerDaemon/src/CAmDltWrapper.cpp new file mode 100644 index 0000000..968f911 --- /dev/null +++ b/AudioManagerDaemon/src/CAmDltWrapper.cpp @@ -0,0 +1,219 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDltWrapper.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "shared/CAmDltWrapper.h" +#include +#include +#include + +namespace am +{ + +CAmDltWrapper* CAmDltWrapper::mpDLTWrapper = NULL; + +CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug) +{ + if (!mpDLTWrapper) + mpDLTWrapper = new CAmDltWrapper(enableNoDLTDebug); +#ifndef WITH_DLT + if(enableNoDLTDebug) + mpDLTWrapper->enableNoDLTDebug(true); +#endif + return mpDLTWrapper; +} + +void CAmDltWrapper::unregisterContext(DltContext & handle) +{ +#ifdef WITH_DLT + dlt_unregister_context(&handle); +#endif +} + +CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) : +#ifndef WITH_DLT + mEnableNoDLTDebug(enableNoDLTDebug), +#endif + mDltContext(), // + mDltContextData() +{ + (void) enableNoDLTDebug; +#ifndef WITH_DLT + std::cout << "[DLT] Running without DLT-support" << std::endl; +#endif +} + +void CAmDltWrapper::registerApp(const char *appid, const char *description) +{ +#ifdef WITH_DLT + dlt_register_app(appid, description); + //register a default context + dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass"); +#endif +} + +void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description) +{ +#ifdef WITH_DLT + dlt_register_context(&handle, contextid, description); +#else + memcpy(&mDltContext.contextID,contextid,4); + strlen(description); + const size_t str_len = strlen(description); + if(str_len < 2000) + { + mDltContextData.context_description = new char[str_len + 1]; + (void) strcpy(mDltContextData.context_description,description); + } +#endif +} + +void CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context) +{ + if (!context) + context = &mDltContext; +#ifdef WITH_DLT + dlt_user_log_write_start(context, &mDltContextData, loglevel); +#endif + +} + +void CAmDltWrapper::send() +{ +#ifdef WITH_DLT + dlt_user_log_write_finish(&mDltContextData); +#else + if(mEnableNoDLTDebug) + std::cout << "[" << mDltContext.contextID << "] " << std::string(mDltContextData.buffer) << std::endl; + + mDltContextData.size = 0; +#endif +} + +void CAmDltWrapper::append(const int8_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_int8(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const uint8_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_uint8(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const int16_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_int16(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const uint16_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_uint16(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const int32_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_int32(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const uint32_t value) +{ +#ifdef WITH_DLT + dlt_user_log_write_uint32(&mDltContextData, value); +#else + appendNoDLT(value); +#endif +} + +void CAmDltWrapper::append(const char*& value) +{ +#ifdef WITH_DLT + dlt_user_log_write_string(&mDltContextData, value); +#else + memcpy((mDltContextData.buffer+mDltContextData.size),value,strlen(value)); + mDltContextData.size += strlen(value); +#endif +} + +void CAmDltWrapper::append(const std::string& value) +{ +#ifdef WITH_DLT + dlt_user_log_write_string(&mDltContextData, value.c_str()); +#else + memcpy((mDltContextData.buffer+mDltContextData.size),value.c_str(),value.size()); + mDltContextData.size += value.size(); +#endif +} + +void CAmDltWrapper::append(const bool value) +{ +#ifdef WITH_DLT + dlt_user_log_write_bool(&mDltContextData, static_cast(value)); +#else + appendNoDLT(value); +#endif +} + +#ifndef WITH_DLT +template void CAmDltWrapper::appendNoDLT(T value) +{ + if((mDltContextData.size + sizeof(value)) < DLT_USER_BUF_MAX_SIZE) + { + memcpy((mDltContextData.buffer+mDltContextData.size),&(value),sizeof(value)); + mDltContextData.size += sizeof(value); + } +} + +void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug) +{ + mEnableNoDLTDebug = enableNoDLTDebug; +} +#endif + +CAmDltWrapper::~CAmDltWrapper() +{ + if (mpDLTWrapper) + delete mpDLTWrapper; +} +} + diff --git a/AudioManagerDaemon/src/CAmRouter.cpp b/AudioManagerDaemon/src/CAmRouter.cpp new file mode 100644 index 0000000..265f77d --- /dev/null +++ b/AudioManagerDaemon/src/CAmRouter.cpp @@ -0,0 +1,354 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRouter.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmRouter.h" +#include +#include +#include +#include +#include "CAmDatabaseHandler.h" +#include "CAmControlSender.h" + +namespace am { + +CAmRouter::CAmRouter(CAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : + mDatabaseHandler(iDatabaseHandler), // + mControlSender(iSender) +{ + assert(mDatabaseHandler); + assert(mControlSender); +} + +am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) +{ + returnList.clear(); + //first find out in which domains the source and sink are + am_domainID_t sourceDomainID; + am_domainID_t sinkDomainID; + if (mDatabaseHandler->getDomainOfSource(sourceID, sourceDomainID) != E_OK) + return (E_NON_EXISTENT); + if (mDatabaseHandler->getDomainOfSink(sinkID, sinkDomainID) != E_OK) + return (E_NON_EXISTENT); + + if (sourceDomainID == sinkDomainID) //shortcut if the domains are the same... + { + //first get the list of possible connection formats + std::vector listFormats, listPriorityConnectionFormats; + listPossibleConnectionFormats(sourceID, sinkID, listFormats); + + //dummy route + am_Route_s route; + route.sinkID = sinkID; + route.sourceID = sourceID; + route.route.clear(); + + //get the prio of the Controller: + mControlSender->getConnectionFormatChoice(sourceID, sinkID, route, listFormats, listPriorityConnectionFormats); + + //no possible connection, so no route ! But we report OK since there is no fault ... + if (listPriorityConnectionFormats.empty()) + return E_OK; + + //return the first item as route: + am_RoutingElement_s routingElement; + routingElement.sourceID = sourceID; + routingElement.sinkID = sinkID; + routingElement.connectionFormat = listPriorityConnectionFormats[0]; + routingElement.domainID = sourceDomainID; + + //Now get a route: + am_Route_s actualRoute; + actualRoute.route.push_back(routingElement); + actualRoute.sourceID = sourceID; + actualRoute.sinkID = sinkID; + + //push it to the return list - we are done here ... + returnList.push_back(actualRoute); + return E_OK; + + } + CAmRoutingTree routingtree(sourceDomainID); //Build up a Tree from the Source_Domain to every other domain. + std::vector flattree; //This list is the flat tree + std::vector matchtree; + std::vector listGatewayID; //holds all gateway ids of the route + am_RoutingElement_s routingElement; + am_Route_s actualRoute; //holds the actual Route + am_sourceID_t lastSource = 0; + + mDatabaseHandler->getRoutingTree(onlyfree, routingtree, flattree); //Build up the tree out of the database as + + //we go through the returned flattree and look for our sink, after that flattree holds only treeItems that match + std::vector::iterator iterator = flattree.begin(); + for (; iterator != flattree.end(); ++iterator) + { + if ((*iterator)->returnDomainID() == sinkDomainID) + { + matchtree.push_back(*iterator); + } + } + + //No we need to trace back the routes for each entry in matchtree + iterator = matchtree.begin(); + for (; iterator != matchtree.end(); ++iterator) + { + std::vector actualRoutingElement; //intermediate list of current routing pairs + //getting the route for the actual item + routingtree.getRoute(*iterator, listGatewayID); //This gives only the Gateway IDs we need more + + //go throught the gatewayids and get more information + std::vector::iterator gatewayIterator = listGatewayID.begin(); + for (; gatewayIterator != listGatewayID.end(); ++gatewayIterator) + { + am_Gateway_s gatewayData; + if (mDatabaseHandler->getGatewayInfoDB(*gatewayIterator, gatewayData) != E_OK) + return (E_UNKNOWN); + + //at the beginning of the route, we connect first the source to the first gateway + if (gatewayIterator == listGatewayID.begin()) + { + routingElement.sourceID = sourceID; + routingElement.domainID = sourceDomainID; + } + else + { + routingElement.sourceID = lastSource; + routingElement.domainID = gatewayData.domainSinkID; + } + routingElement.sinkID = gatewayData.sinkID; + actualRoutingElement.push_back(routingElement); + lastSource = gatewayData.sourceID; + } + //at the end of the route, connect to the sink ! + routingElement.sourceID = lastSource; + routingElement.sinkID = sinkID; + routingElement.domainID = sinkDomainID; + actualRoutingElement.push_back(routingElement); + + //So now we got the route, what is missing are the connectionFormats... + + //Step through the routes and try to use always the best connectionFormat + std::vector::iterator routingInterator = actualRoutingElement.begin(); + gatewayIterator = listGatewayID.begin(); + if (findBestWay(sinkID, sourceID, actualRoutingElement, routingInterator, gatewayIterator) != E_OK) + { + continue; + } + + //add the route to the list of routes... + actualRoute.sourceID = sourceID; + actualRoute.sinkID = sinkID; + actualRoute.route = actualRoutingElement; + returnList.push_back(actualRoute); + } + return (E_OK); +} + +void CAmRouter::listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& listFormats) const +{ + std::vector listSourceFormats; + std::vector listSinkFormats; + mDatabaseHandler->getListSinkConnectionFormats(sinkID, listSinkFormats); + mDatabaseHandler->getListSourceConnectionFormats(sourceID, listSourceFormats); + std::sort(listSinkFormats.begin(), listSinkFormats.end()); //todo: this might be not needed if we use strictly sorted input + std::sort(listSourceFormats.begin(), listSourceFormats.end()); //todo: this might be not needed if we use strictly sorted input + std::insert_iterator > inserter(listFormats, listFormats.begin()); + set_intersection(listSourceFormats.begin(), listSourceFormats.end(), listSinkFormats.begin(), listSinkFormats.end(), inserter); +} + +am_Error_e CAmRouter::findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector & listRoute, std::vector::iterator routeIterator, std::vector::iterator gatewayIterator) +{ + am_Error_e returnError = E_NOT_POSSIBLE; + std::vector listConnectionFormats; + std::vector listMergeConnectionFormats; + std::vector listPriorityConnectionFormats; + std::vector::iterator nextIterator = routeIterator + 1; + //get best connection format + listPossibleConnectionFormats(routeIterator->sourceID, routeIterator->sinkID, listConnectionFormats); + + //if we have not just started, we need to take care about the gateways... + if (routeIterator != listRoute.begin()) + { + //since we have to deal with Gateways, there are restrictions what connectionFormat we can take. So we need to take the subset of connections that are restricted: + std::vector listRestrictedConnectionFormats; + std::insert_iterator > inserter(listMergeConnectionFormats, listMergeConnectionFormats.begin()); + std::vector::iterator tempIterator(routeIterator); + tempIterator--; + listRestrictedOutputFormatsGateways(*gatewayIterator, (tempIterator)->connectionFormat, listRestrictedConnectionFormats); + std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input + set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter); + gatewayIterator++; + } + else + { + listMergeConnectionFormats = listConnectionFormats; + } + + am_Route_s route; + route.sinkID = sinkID; + route.sourceID = sourceID; + route.route = listRoute; + + //let the controller decide: + mControlSender->getConnectionFormatChoice(routeIterator->sourceID, routeIterator->sinkID, route, listMergeConnectionFormats, listPriorityConnectionFormats); + + //we have the list sorted after prios - now we try one after the other with the next part of the route + std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); + + //here we need to check if we are at the end and stop + if (nextIterator == listRoute.end()) + { + if (!listPriorityConnectionFormats.empty()) + { + routeIterator->connectionFormat = listPriorityConnectionFormats.front(); + return E_OK; + } + else + return E_NOT_POSSIBLE; + } + + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + { + routeIterator->connectionFormat = *connectionFormatIterator; + if ((returnError = findBestWay(sinkID, sourceID, listRoute, nextIterator, gatewayIterator)) == E_OK) + { + break; + } + } + + return (returnError); +} + +void CAmRouter::listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_ConnectionFormat_e sinkConnectionFormat, std::vector & listFormats) const +{ + listFormats.clear(); + am_Gateway_s gatewayData; + mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData); + std::vector::const_iterator rowSinkIterator = gatewayData.listSinkFormats.begin(); + std::vector::const_iterator matrixIterator = gatewayData.convertionMatrix.begin(); + + //find the row number of the sink + rowSinkIterator = find(gatewayData.listSinkFormats.begin(), gatewayData.listSinkFormats.end(), sinkConnectionFormat); + int rowNumberSink = rowSinkIterator - gatewayData.listSinkFormats.begin(); + + //go through the convertionMatrix and find out if the conversion is possible, if yes, add connectionFormat ... + std::advance(matrixIterator, rowNumberSink); + + //iterate line-wise through the matrix and add more formats + do + { + if (*matrixIterator) + { + listFormats.push_back(gatewayData.listSourceFormats.at((matrixIterator - gatewayData.convertionMatrix.begin()) / gatewayData.listSinkFormats.size())); + } + std::advance(matrixIterator, gatewayData.listSinkFormats.size()); + } while (gatewayData.convertionMatrix.end() - matrixIterator > 0); +} + +CAmRouter::~CAmRouter() +{ +} + +CAmRoutingTreeItem::CAmRoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent) : + mDomainID(domainID), // + mGatewayID(gatewayID), // + mParentItem(parent) +{ + assert(mDomainID!=0); +} + +void CAmRoutingTreeItem::appendChild(CAmRoutingTreeItem *newChild) +{ + assert(newChild); + mListChildItems.push_back(newChild); +} + +void CAmRoutingTreeItem::returnChildItems(std::vector listChildItems) +{ + listChildItems = mListChildItems; +} + +am_domainID_t CAmRoutingTreeItem::returnDomainID() const +{ + return (mDomainID); +} + +am_gatewayID_t CAmRoutingTreeItem::returnGatewayID() const +{ + return (mGatewayID); +} + +CAmRoutingTreeItem* CAmRoutingTreeItem::returnParent() const +{ + return (mParentItem); +} + +CAmRoutingTreeItem::~CAmRoutingTreeItem() +{ +} + +CAmRoutingTree::CAmRoutingTree(const am_domainID_t rootDomainID) : + mRootItem(CAmRoutingTreeItem(rootDomainID)) +{ + assert(rootDomainID!=0); +} + +CAmRoutingTreeItem *CAmRoutingTree::insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent) +{ + CAmRoutingTreeItem *newTree = new CAmRoutingTreeItem(domainID, gatewayID, parent); + parent->appendChild(newTree); + mListChild.push_back(newTree); + return newTree; +} + +void CAmRoutingTree::getRoute(CAmRoutingTreeItem *targetItem, std::vector& listGateways) +{ + listGateways.clear(); + CAmRoutingTreeItem *parentItem = targetItem; + while (parentItem != &mRootItem) + { + listGateways.push_back(parentItem->returnGatewayID()); + parentItem = parentItem->returnParent(); + } + std::reverse(listGateways.begin(), listGateways.end()); +} + +am_domainID_t CAmRoutingTree::returnRootDomainID() const +{ + return (mRootItem.returnDomainID()); +} + +CAmRoutingTreeItem *CAmRoutingTree::returnRootItem() +{ + return (&mRootItem); +} + +CAmRoutingTree::~CAmRoutingTree() +{ + std::vector::iterator it = mListChild.begin(); + for (; it != mListChild.end(); ++it) + { + delete *it; + } +} +} diff --git a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp new file mode 100644 index 0000000..8f489fb --- /dev/null +++ b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp @@ -0,0 +1,382 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRoutingReceiver.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (christian.ei.mueller@bmw.de) + * + * \section LicenseCAmRoutingReceiver.h + * + * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause) + * Copyright (C) 2011, BMW AG Christian Mueller 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 . + * 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 "CAmRoutingReceiver.h" +#include +#include +#include "CAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "CAmControlSender.h" +#include "shared/CAmDltWrapper.h" +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : + mDatabaseHandler(iDatabaseHandler), // + mRoutingSender(iRoutingSender), // + mControlSender(iControlSender), // + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) +{ + assert(mDatabaseHandler!=NULL); + assert(mRoutingSender!=NULL); + assert(mControlSender!=NULL); + assert(mSocketHandler!=NULL); +} + +CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : + mDatabaseHandler(iDatabaseHandler), // + mRoutingSender(iRoutingSender), // + mControlSender(iControlSender), // + mSocketHandler(iSocketHandler), // + mDBusWrapper(iDBusWrapper), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) +{ + assert(mDatabaseHandler!=NULL); + assert(mRoutingSender!=NULL); + assert(mControlSender!=NULL); + assert(mSocketHandler!=NULL); + assert(mDBusWrapper!=NULL); +} + +CAmRoutingReceiver::~CAmRoutingReceiver() +{ +} + +void CAmRoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + mRoutingSender->removeHandle(handle); + if (error == E_OK) + { + mDatabaseHandler->changeConnectionFinal(connectionID); + } + else + { + mDatabaseHandler->removeConnection(connectionID); + } + mControlSender->cbAckConnect(handle, error); +} + +void CAmRoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + mRoutingSender->removeHandle(handle); + if (error == E_OK) + { + mDatabaseHandler->removeConnection(connectionID); + } + mControlSender->cbAckDisconnect(handle, error); +} + +void CAmRoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sinkID != 0) + { + //todo: check if volume in handleData is same than volume. React to it. + mDatabaseHandler->changeSinkVolume(handleData.sinkID, volume); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSinkVolumeChange(handle, volume, error); +} + +void CAmRoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sourceID != 0) + { + //todo: check if volume in handleData is same than volume. React to it. + mDatabaseHandler->changeSourceVolume(handleData.sourceID, volume); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSourceVolumeChange(handle, volume, error); +} + +void CAmRoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sourceID != 0) + { + //todo: check if volume in handleData is same than volume. React to it. + mDatabaseHandler->changeSourceState(handleData.sourceID, handleData.sourceState); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSourceState(handle, error); +} + +void CAmRoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sinkID != 0) + { + mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery, handleData.sinkID); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSinkSoundProperty(handle, error); + +} + +void am::CAmRoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sinkID != 0) + { + std::vector::const_iterator it = handleData.soundProperties->begin(); + for (; it != handleData.soundProperties->end(); ++it) + { + mDatabaseHandler->changeSinkSoundPropertyDB(*it, handleData.sinkID); + } + delete handleData.soundProperties; + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSinkSoundProperties(handle, error); +} + +void CAmRoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sourceID != 0) + { + mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery, handleData.sourceID); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSourceSoundProperty(handle, error); +} + +void am::CAmRoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sourceID != 0) + { + std::vector::const_iterator it = handleData.soundProperties->begin(); + for (; it != handleData.soundProperties->end(); ++it) + { + mDatabaseHandler->changeSourceSoundPropertyDB(*it, handleData.sourceID); + } + delete handleData.soundProperties; + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckSetSourceSoundProperties(handle, error); +} + +void CAmRoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.crossfaderID != 0) + { + //todo: check if volume in handleData is same than volume. React to it. + mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID, hotSink); + } + mRoutingSender->removeHandle(handle); + mControlSender->cbAckCrossFade(handle, hotSink, error); +} + +void CAmRoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + mControlSender->hookSystemSourceVolumeTick(handle, sourceID, volume); +} + +void CAmRoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + mControlSender->hookSystemSinkVolumeTick(handle, sinkID, volume); +} + +am_Error_e CAmRoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID) +{ + return mDatabaseHandler->peekDomain(name, domainID); + +} + +am_Error_e CAmRoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + return mControlSender->hookSystemRegisterDomain(domainData, domainID); +} + +am_Error_e CAmRoutingReceiver::deregisterDomain(const am_domainID_t domainID) +{ + return mControlSender->hookSystemDeregisterDomain(domainID); +} + +am_Error_e CAmRoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + return mControlSender->hookSystemRegisterGateway(gatewayData, gatewayID); +} + +am_Error_e CAmRoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID) +{ + return mControlSender->hookSystemDeregisterGateway(gatewayID); +} + +am_Error_e CAmRoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID) +{ + return mDatabaseHandler->peekSink(name, sinkID); +} + +am_Error_e CAmRoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + return mControlSender->hookSystemRegisterSink(sinkData, sinkID); +} + +am_Error_e CAmRoutingReceiver::deregisterSink(const am_sinkID_t sinkID) +{ + return mControlSender->hookSystemDeregisterSink(sinkID); +} + +am_Error_e CAmRoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID) +{ + return mDatabaseHandler->peekSource(name, sourceID); +} + +am_Error_e CAmRoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + return mControlSender->hookSystemRegisterSource(sourceData, sourceID); +} + +am_Error_e CAmRoutingReceiver::deregisterSource(const am_sourceID_t sourceID) +{ + return mControlSender->hookSystemDeregisterSource(sourceID); +} + +am_Error_e CAmRoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + return mControlSender->hookSystemRegisterCrossfader(crossfaderData, crossfaderID); +} + +am_Error_e CAmRoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID) +{ + return mControlSender->hookSystemDeregisterCrossfader(crossfaderID); +} + +void CAmRoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + return mControlSender->hookSystemInterruptStateChange(sourceID, interruptState); +} + +void CAmRoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID) +{ + mControlSender->hookSystemDomainRegistrationComplete(domainID); +} + +void CAmRoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + mControlSender->hookSystemSinkAvailablityStateChange(sinkID, availability); +} + +void CAmRoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + mControlSender->hookSystemSourceAvailablityStateChange(sourceID, availability); +} + +void CAmRoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + mControlSender->hookSystemDomainStateChange(domainID, domainState); +} + +void CAmRoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) +{ + mDatabaseHandler->changeConnectionTimingInformation(connectionID, delay); +} + +void CAmRoutingReceiver::sendChangedData(const std::vector & earlyData) +{ + mControlSender->hookSystemReceiveEarlyData(earlyData); +} + +am_Error_e CAmRoutingReceiver::peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) +{ + return mDatabaseHandler->peekSinkClassID(name, sinkClassID); +} + +am_Error_e CAmRoutingReceiver::peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) +{ + return mDatabaseHandler->peekSourceClassID(name, sourceClassID); +} + +am_Error_e CAmRoutingReceiver::getDBusConnectionWrapper(CAmDbusWrapper *& dbusConnectionWrapper) const +{ +#ifdef WITH_DBUS_WRAPPER + dbusConnectionWrapper = mDBusWrapper; + return E_OK; +#else + return E_UNKNOWN; +#endif +} + +am_Error_e CAmRoutingReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const +{ + socketHandler = mSocketHandler; + return E_OK; +} + +void CAmRoutingReceiver::getInterfaceVersion(std::string & version) const +{ + version = RoutingReceiveVersion; +} + +void CAmRoutingReceiver::confirmRoutingReady(const uint16_t handle) +{ + mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); + if (mWaitStartup && mListStartupHandles.empty()) + mControlSender->confirmRoutingReady(); +} + +void CAmRoutingReceiver::confirmRoutingRundown(const uint16_t handle) +{ + mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); + if (mWaitRundown && mListRundownHandles.empty()) + mControlSender->confirmCommandRundown(); +} + +uint16_t am::CAmRoutingReceiver::getStartupHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListStartupHandles.push_back(handle); + return handle; +} + +uint16_t am::CAmRoutingReceiver::getRundownHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListRundownHandles.push_back(handle); + return handle; +} + +void am::CAmRoutingReceiver::waitOnStartup(bool startup) +{ + mWaitStartup = startup; +} + +void am::CAmRoutingReceiver::waitOnRundown(bool rundown) +{ + mWaitRundown = rundown; +} +} diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp new file mode 100644 index 0000000..c134c3f --- /dev/null +++ b/AudioManagerDaemon/src/CAmRoutingSender.cpp @@ -0,0 +1,560 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmRoutingSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmRoutingSender.h" +#include +#include +#include +#include +#include +#include +#include "CAmRoutingReceiver.h" +#include "TAmPluginTemplate.h" +#include "shared/CAmDltWrapper.h" + +namespace am +{ + +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 + +#define CALL_ALL_INTERFACES(...) \ + std::vector::iterator iter = mListInterfaces.begin(); \ + std::vector::iterator iterEnd = mListInterfaces.end(); \ + for (; iter__VA_ARGS__; \ + } + +CAmRoutingSender::CAmRoutingSender(const std::vector& listOfPluginDirectories) : + mHandleCount(0), // + mlistActiveHandles(), // + mListInterfaces(), // + mMapConnectionInterface(), // + mMapCrossfaderInterface(), // + mMapDomainInterface(), // + mMapSinkInterface(), // + mMapSourceInterface(), // + mMapHandleInterface(), // + mRoutingReceiver() +{ + std::vector sharedLibraryNameList; + std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); + std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); + + // search communicator plugins in configured directories + for (; dirIter < dirIterEnd; ++dirIter) + { + const char* directoryName = dirIter->c_str(); + logInfo("Searching for HookPlugins in", directoryName); + DIR *directory = opendir(directoryName); + + if (!directory) + { + logError("RoutingSender::RoutingSender Error opening directory: ", directoryName); + continue; + } + + // iterate content of directory + struct dirent *itemInDirectory = 0; + while ((itemInDirectory = readdir(directory))) + { + unsigned char entryType = itemInDirectory->d_type; + std::string entryName = itemInDirectory->d_name; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + if (regularFile && sharedLibExtension) + { + logInfo("RoutingSender::RoutingSender adding file: ", entryName); + std::string name(directoryName); + sharedLibraryNameList.push_back(name + "/" + entryName); + } + else + { + logInfo("RoutingSender::RoutingSender PluginSearch ignoring file :", entryName); + } + } + + closedir(directory); + } + + // iterate all communicator plugins and start them + std::vector::iterator iter = sharedLibraryNameList.begin(); + std::vector::iterator iterEnd = sharedLibraryNameList.end(); + + for (; iter != iterEnd; ++iter) + { + logInfo("RoutingSender::RoutingSender try loading: ", *iter); + + IAmRoutingSend* (*createFunc)(); + void* tempLibHandle = NULL; + createFunc = getCreateFunction(*iter, tempLibHandle); + + if (!createFunc) + { + logError("RoutingSender::RoutingSender Entry point of RoutingPlugin not found"); + continue; + } + + IAmRoutingSend* router = createFunc(); + + if (!router) + { + logError("RoutingSender::RoutingSender RoutingPlugin initialization failed. Entry Function not callable"); + continue; + } + + InterfaceNamePairs routerInterface; + routerInterface.routingInterface = router; + + //check libversion + std::string version; + router->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) + { + logInfo("RoutingPlugin initialization failed. Version of Interface to old"); + continue; + } + + //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain.... + router->returnBusName(routerInterface.busName); + assert(!routerInterface.busName.empty()); + mListInterfaces.push_back(routerInterface); + mListLibraryHandles.push_back(tempLibHandle); + } +} + +CAmRoutingSender::~CAmRoutingSender() +{ + unloadLibraries(); + HandlesMap::iterator it = mlistActiveHandles.begin(); + + //clean up heap if existent + for (; it != mlistActiveHandles.end(); ++it) + { + if (it->first.handleType == H_SETSINKSOUNDPROPERTIES || it->first.handleType == H_SETSOURCESOUNDPROPERTIES) + { + delete it->second.soundProperties; + } + } +} + +am_Error_e CAmRoutingSender::startupInterfaces(CAmRoutingReceiver *iRoutingReceiver) +{ + mRoutingReceiver = iRoutingReceiver; + am_Error_e returnError = E_OK; + + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + am_Error_e error = (*iter).routingInterface->startupInterface(iRoutingReceiver); + if (error != E_OK) + { + returnError = error; + } + } + return returnError; +} + +am_Error_e CAmRoutingSender::asyncAbort(const am_Handle_s& handle) +{ + HandleInterfaceMap::iterator iter = mMapHandleInterface.begin(); + iter = mMapHandleInterface.find(handle.handle); + if (iter != mMapHandleInterface.end()) + { + return iter->second->asyncAbort(handle); + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) +{ + am_handleData_c handleData; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + handleData.connectionID = connectionID; + handle = createHandle(handleData, H_CONNECT); + mMapConnectionInterface.insert(std::make_pair(connectionID, iter->second)); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncConnect(handle, connectionID, sourceID, sinkID, connectionFormat); + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID) +{ + am_handleData_c handleData; + ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin(); + iter = mMapConnectionInterface.find(connectionID); + if (iter != mMapConnectionInterface.end()) + { + handleData.connectionID = connectionID; + handle = createHandle(handleData, H_DISCONNECT); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + am_Error_e returnVal = iter->second->asyncDisconnect(handle, connectionID); + mMapConnectionInterface.erase(iter); + return returnVal; + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + am_handleData_c handleData; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + handleData.sinkID = sinkID; + handleData.volume = volume; + handle = createHandle(handleData, H_SETSINKVOLUME); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSinkVolume(handle, sinkID, volume, ramp, time); + } + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + am_handleData_c handleData; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + handleData.sourceID = sourceID; + handleData.volume = volume; + handle = createHandle(handleData, H_SETSOURCEVOLUME); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSourceVolume(handle, sourceID, volume, ramp, time); + } + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state) +{ + am_handleData_c handleData; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + handleData.sourceID = sourceID; + handleData.sourceState = state; + handle = createHandle(handleData, H_SETSOURCESTATE); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSourceState(handle, sourceID, state); + } + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) +{ + am_handleData_c handleData; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + handleData.sinkID = sinkID; + handleData.soundPropery = soundProperty; + handle = createHandle(handleData, H_SETSINKSOUNDPROPERTY); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSinkSoundProperty(handle, sinkID, soundProperty); + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmRoutingSender::asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) +{ + am_handleData_c handleData; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + handleData.sourceID = sourceID; + handleData.soundPropery = soundProperty; + handle = createHandle(handleData, H_SETSOURCESOUNDPROPERTY); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSourceSoundProperty(handle, sourceID, soundProperty); + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmRoutingSender::asyncSetSourceSoundProperties(am_Handle_s& handle, const std::vector & listSoundProperties, const am_sourceID_t sourceID) +{ + am_handleData_c handleData; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + handleData.sourceID = sourceID; + handleData.soundProperties = new std::vector(listSoundProperties); + handle = createHandle(handleData, H_SETSOURCESOUNDPROPERTIES); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSourceSoundProperties(handle, sourceID, listSoundProperties); + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmRoutingSender::asyncSetSinkSoundProperties(am_Handle_s& handle, const std::vector & listSoundProperties, const am_sinkID_t sinkID) +{ + am_handleData_c handleData; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + handleData.sinkID = sinkID; + handleData.soundProperties = new std::vector(listSoundProperties); + handle = createHandle(handleData, H_SETSINKSOUNDPROPERTIES); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncSetSinkSoundProperties(handle, sinkID, listSoundProperties); + } + return (E_NON_EXISTENT); + +} + +am_Error_e CAmRoutingSender::asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) +{ + am_handleData_c handleData; + CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin(); + iter = mMapCrossfaderInterface.find(crossfaderID); + if (iter != mMapCrossfaderInterface.end()) + { + handleData.crossfaderID = crossfaderID; + handleData.hotSink = hotSink; + handle = createHandle(handleData, H_CROSSFADE); + mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); + return iter->second->asyncCrossFade(handle, crossfaderID, hotSink, rampType, time); + } + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); + iter = mMapDomainInterface.find(domainID); + if (iter != mMapDomainInterface.end()) + return iter->second->setDomainState(domainID, domainState); + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::addDomainLookup(const am_Domain_s& domainData) +{ + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + if ((*iter).busName.compare(domainData.busname) == 0) + { + mMapDomainInterface.insert(std::make_pair(domainData.domainID, (*iter).routingInterface)); + return E_OK; + } + } + + return E_UNKNOWN; +} + +am_Error_e CAmRoutingSender::addSourceLookup(const am_Source_s& sourceData) +{ + DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); + iter = mMapDomainInterface.find(sourceData.domainID); + if (iter != mMapDomainInterface.end()) + { + mMapSourceInterface.insert(std::make_pair(sourceData.sourceID, iter->second)); + return E_OK; + } + + return E_UNKNOWN; +} + +am_Error_e CAmRoutingSender::addSinkLookup(const am_Sink_s& sinkData) +{ + DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); + iter = mMapDomainInterface.find(sinkData.domainID); + if (iter != mMapDomainInterface.end()) + { + mMapSinkInterface.insert(std::make_pair(sinkData.sinkID, iter->second)); + return E_OK; + } + + return E_UNKNOWN; +} + +am_Error_e CAmRoutingSender::addCrossfaderLookup(const am_Crossfader_s& crossfaderData) +{ + DomainInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(crossfaderData.sourceID); + if (iter != mMapSourceInterface.end()) + { + mMapSourceInterface.insert(std::make_pair(crossfaderData.crossfaderID, iter->second)); + return E_OK; + } + + return E_UNKNOWN; +} + +am_Error_e CAmRoutingSender::removeDomainLookup(const am_domainID_t domainID) +{ + DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); + iter = mMapDomainInterface.find(domainID); + if (iter != mMapDomainInterface.end()) + { + mMapDomainInterface.erase(iter); + return E_OK; + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::removeSourceLookup(const am_sourceID_t sourceID) +{ + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + mMapSourceInterface.erase(iter); + return E_OK; + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::removeSinkLookup(const am_sinkID_t sinkID) +{ + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + mMapSinkInterface.erase(iter); + return E_OK; + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::removeCrossfaderLookup(const am_crossfaderID_t crossfaderID) +{ + CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin(); + iter = mMapCrossfaderInterface.find(crossfaderID); + if (iter != mMapCrossfaderInterface.end()) + { + mMapCrossfaderInterface.erase(iter); + return E_OK; + } + + return E_NON_EXISTENT; +} + +am_Error_e CAmRoutingSender::removeHandle(const am_Handle_s& handle) +{ + if (mlistActiveHandles.erase(handle)) + return E_OK; + return E_UNKNOWN; +} + +am_Error_e CAmRoutingSender::getListHandles(std::vector & listHandles) const +{ + listHandles.clear(); + HandlesMap::const_iterator it = mlistActiveHandles.begin(); + for (; it != mlistActiveHandles.end(); ++it) + { + listHandles.push_back(it->first); + } + return E_OK; +} + +am_Handle_s CAmRoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type) +{ + am_Handle_s handle; + handle.handle = ++mHandleCount; //todo: handle overflows here... + handle.handleType = type; + mlistActiveHandles.insert(std::make_pair(handle, handleData)); + return handle; +} + +CAmRoutingSender::am_handleData_c CAmRoutingSender::returnHandleData(const am_Handle_s handle) const +{ + HandlesMap::const_iterator it = mlistActiveHandles.begin(); + it = mlistActiveHandles.find(handle); + return (it->second); +} + +void CAmRoutingSender::setRoutingReady() +{ + mRoutingReceiver->waitOnStartup(false); + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingReady(mRoutingReceiver->getStartupHandle()); + } + mRoutingReceiver->waitOnStartup(true); +} + +void CAmRoutingSender::setRoutingRundown() +{ + mRoutingReceiver->waitOnRundown(false); + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingRundown(mRoutingReceiver->getStartupHandle()); + } + mRoutingReceiver->waitOnRundown(true); +} + +void CAmRoutingSender::unloadLibraries(void) +{ + std::vector::iterator iterator = mListLibraryHandles.begin(); + for (; iterator < mListLibraryHandles.end(); ++iterator) + { + dlclose(*iterator); + } + mListLibraryHandles.clear(); +} + +am_Error_e CAmRoutingSender::getListPlugins(std::vector& interfaces) const +{ + std::vector::const_iterator it = mListInterfaces.begin(); + for (; it != mListInterfaces.end(); ++it) + { + interfaces.push_back(it->busName); + } + return E_OK; +} + +void CAmRoutingSender::getInterfaceVersion(std::string & version) const +{ + version = RoutingSendVersion; +} +} diff --git a/AudioManagerDaemon/src/CAmSocketHandler.cpp b/AudioManagerDaemon/src/CAmSocketHandler.cpp new file mode 100644 index 0000000..2d5c7d7 --- /dev/null +++ b/AudioManagerDaemon/src/CAmSocketHandler.cpp @@ -0,0 +1,498 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmDbusWrapper.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "shared/CAmSocketHandler.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" + +//todo: implement time correction if timer was interrupted by call +//todo: change hitlist to a list that holds all information, because entering and removing items will be cheaper than with std::vector + +namespace am { + +CAmSocketHandler::CAmSocketHandler() : + mListPoll(), // + mListTimer(), // + mListActiveTimer(), // + mNextTimer(), // + mLastInsertedHandle(0), // + mLastInsertedPollHandle(0), // + mRecreatePollfds(true), // + mTimeout() +{ + mTimeout.tv_nsec = -1; + mTimeout.tv_sec = -1; + gDispatchDone = 0; +} + +CAmSocketHandler::~CAmSocketHandler() +{ +} + +//todo: maybe have some: give me more time returned? +/** + * start the block listening for filedescriptors. This is the mainloop. + */ +void CAmSocketHandler::start_listenting() +{ + gDispatchDone=0; + int16_t pollStatus; + std::list hitList; + + //init the timer + initTimer(); + + //prepare the signalmask + sigset_t sigmask; + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + sigaddset(&sigmask, SIGQUIT); + sigaddset(&sigmask, SIGTERM); + sigaddset(&sigmask, SIGHUP); + sigaddset(&sigmask, SIGQUIT); + + while (!gDispatchDone) + { + //first we go through the registered filedescriptors and check if someone needs preparation: + mListPoll_t::iterator prepIter = mListPoll.begin(); + CAmShPollPrepare *prep = NULL; + for (; prepIter != mListPoll.end(); ++prepIter) + { + if ((prep = prepIter->prepareCB) != NULL) + prep->Call(prepIter->handle, prepIter->userData); + } + + if (mRecreatePollfds) + { + mfdPollingArray.clear(); + //there was a change in the setup, so we need to recreate the fdarray from the list + std::for_each(mListPoll.begin(), mListPoll.end(), CAmShCopyPollfd(mfdPollingArray)); + mRecreatePollfds = false; + } + + //block until something is on a filedescriptor +#ifdef WITH_PPOLL + + timespec buffertime; + if ((pollStatus = ppoll(&mfdPollingArray[0], mfdPollingArray.size(), insertTime(buffertime), &sigmask)) < 0) + { + if (errno == EINTR) + { + //a signal was received, that means it's time to go... + pollStatus = 0; + } + else + { + logError("SocketHandler::start_listenting ppoll returned with error", errno); + exit(0); + } + } + +#else + //sigprocmask (SIG_SETMASK, &mask, &oldmask); + if((pollStatus=poll(&mfdPollingArray[0],mfdPollingArray.size(),timespec2ms(mTimeout)))<0) + { + + if(errno==EINTR) + { + //a signal was received, that means it's time to go... + //todo: add things to do here before going to sleep + exit(0); + } + logError("SocketHandler::start_listenting poll returned with error",errno); + exit(0); + } + //sigprocmask (SIG_SETMASK, &oldmask, NULL); +#endif + + if (pollStatus != 0) //only check filedescriptors if there was a change + { + //todo: here could be a timer that makes sure naughty plugins return! + + //freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines + mListPoll_t listPoll(mListPoll); + + //get all indexes of the fired events and save them int hitList + hitList.clear(); + std::vector::iterator it = mfdPollingArray.begin(); + do + { + it = std::find_if(it, mfdPollingArray.end(), onlyFiredEvents); + if (it != mfdPollingArray.end()) + hitList.push_back(std::distance(mfdPollingArray.begin(), it++)); + + } while (it != mfdPollingArray.end()); + + //stage 1, call firedCB for all matched events, but only if callback is not zero! + std::list::iterator hListIt = hitList.begin(); + for (; hListIt != hitList.end(); ++hListIt) + { + CAmShPollFired* fire = NULL; + if ((fire = listPoll.at(*hListIt).firedCB) != NULL) + fire->Call(mfdPollingArray.at(*hListIt), listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData); + } + + //stage 2, lets ask around if some dispatching is necessary, if not, they are taken from the hitlist + hListIt = hitList.begin(); + for (; hListIt != hitList.end(); ++hListIt) + { + CAmShPollCheck* check = NULL; + if ((check = listPoll.at(*hListIt).checkCB) != NULL) + { + if (!check->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) + { + hListIt = hitList.erase(hListIt); + } + } + } + + //stage 3, the ones left need to dispatch, we do this as long as there is something to dispatch.. + do + { + hListIt = hitList.begin(); + for (; hListIt != hitList.end(); ++hListIt) + { + CAmShPollDispatch *dispatch = NULL; + if ((dispatch = listPoll.at(*hListIt).dispatchCB) != NULL) + { + if (!dispatch->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) + { + hListIt = hitList.erase(hListIt); + } + } + else //there is no dispatch function, so we just remove the file from the list... + { + hListIt = hitList.erase(hListIt); + } + } + } while (!hitList.empty()); + + } + else //Timerevent + { + //this was a timer event, we need to take care about the timers + timerUp(); + } + } +} + +/** + * exits the loop + */ +void CAmSocketHandler::stop_listening() +{ + gDispatchDone = 1; +} + +/** + * Adds a filedescriptor to the polling loop + * @param fd this is a valid filedescriptor + * @param event the event flags + * @param callback the callback that shall be called if the filedescriptor poll succeeded + * @return E_OK if the descriptor was added, E_NON_EXISTENT if the fd is not valid + */ +am_Error_e CAmSocketHandler::addFDPoll(const int fd, const short event, CAmShPollPrepare *prepare, CAmShPollFired *fired, CAmShPollCheck *check, CAmShPollDispatch *dispatch, void *userData, sh_pollHandle_t & handle) +{ + if (!fdIsValid(fd)) + return E_NON_EXISTENT; + + sh_poll_s pollData; + pollData.pollfdValue.fd = fd; + pollData.handle = ++mLastInsertedPollHandle; + pollData.pollfdValue.events = event; + pollData.pollfdValue.revents = 0; + pollData.userData = userData; + pollData.prepareCB = prepare; + pollData.firedCB = fired; + pollData.checkCB = check; + pollData.dispatchCB = dispatch; + + //add new data to the list + mListPoll.push_back(pollData); + + mRecreatePollfds = true; + + handle = pollData.handle; + return E_OK; +} + +/** + * removes a filedescriptor from the poll loop + * @param fd the filedescriptor to be removed + * @return E_OK in case of sucess, E_NON_EXISTENT or E_UNKNOWN if the fd in not registered + */ +am_Error_e CAmSocketHandler::removeFDPoll(const sh_pollHandle_t handle) +{ + mListPoll_t::iterator iterator = mListPoll.begin(); + + for (; iterator != mListPoll.end(); ++iterator) + { + if (iterator->handle == handle) + { + iterator = mListPoll.erase(iterator); + mRecreatePollfds = true; + return E_OK; + } + } + return E_UNKNOWN; +} + +/** + * adds a timer to the list of timers. The callback will be fired when the timer is up. + * This is not a high precise timer, it is very coarse. It is meant to be used for timeouts when waiting + * for an answer via a filedescriptor. + * One time timer. If you need again a timer, you need to add a new timer in the callback of the old one. + * @param timeouts time until the callback is fired + * @param callback the callback + * @param handle the handle that is created for the timer is returned. Can be used to remove the timer + * @return E_OK in case of success + */ +am_Error_e CAmSocketHandler::addTimer(const timespec timeouts, CAmShTimerCallBack*& callback, sh_timerHandle_t& handle, void * userData) +{ + assert(!((timeouts.tv_sec==0) && (timeouts.tv_nsec==0))); + assert(callback!=NULL); + + sh_timer_s timerItem; + + //create a new handle for the timer + handle = ++mLastInsertedHandle; //todo: overflow ruling ! + timerItem.handle = handle; + timerItem.countdown = timeouts; + timerItem.timeout = timeouts; + timerItem.callback = callback; + timerItem.userData = userData; + + //add timer to the list + mListActiveTimer.push_back(timerItem); + mListTimer.push_back(timerItem); + + //very important: sort the list so that the smallest value is front + mListActiveTimer.sort(compareCountdown); + mTimeout = mListActiveTimer.front().countdown; + return E_OK; +} + +/** + * removes a timer from the list of timers + * @param handle the handle to the timer + * @return E_OK in case of success, E_UNKNOWN if timer was not found. + */ +am_Error_e CAmSocketHandler::removeTimer(const sh_timerHandle_t handle) +{ + assert(handle!=0); + + //stop the current timer + stopTimer(handle); + + std::list::iterator it = mListTimer.begin(); + for (; it != mListTimer.end(); ++it) + { + if (it->handle == handle) + { + it = mListTimer.erase(it); + return E_OK; + } + } + return E_UNKNOWN; +} + +/** + * restarts a timer and updates with a new interval + * @param handle handle to the timer + * @param timeouts new timout time + * @return E_OK on success, E_NON_EXISTENT if the handle was not found + */ +am_Error_e CAmSocketHandler::restartTimer(const sh_timerHandle_t handle, const timespec timeouts) +{ + sh_timer_s timerItem; + std::list::iterator it = mListTimer.begin(); + for (; it != mListTimer.end(); ++it) + { + if (it->handle == handle) + { + timerItem = *it; + break; + } + } + + if (timeouts.tv_nsec != -1 && timeouts.tv_sec != -1) + { + timerItem.timeout = timeouts; + } + + mListActiveTimer.push_back(timerItem); + + //very important: sort the list so that the smallest value is front + mListActiveTimer.sort(compareCountdown); + mTimeout = mListActiveTimer.front().countdown; + return E_OK; +} + +am_Error_e CAmSocketHandler::stopTimer(const sh_timerHandle_t handle) +{ + //go through the list and remove the timer with the handle + std::list::iterator it = mListActiveTimer.begin(); + for (; it != mListActiveTimer.end(); ++it) + { + if (it->handle == handle) + { + it = mListActiveTimer.erase(it); + if (!mListActiveTimer.empty()) + { + mTimeout = mListActiveTimer.front().countdown; + } + else + { + mTimeout.tv_nsec = -1; + mTimeout.tv_sec = -1; + } + return E_OK; + } + } + return E_NON_EXISTENT; +} + +/** + * updates the eventFlags of a poll + * @param fd the filedescriptor of the poll + * @param event the event flags + * @return E_OK on succsess, E_NON_EXISTENT if fd was not found + */ +am_Error_e CAmSocketHandler::updateEventFlags(const sh_pollHandle_t handle, const short events) +{ + mListPoll_t::iterator iterator = mListPoll.begin(); + + for (; iterator != mListPoll.end(); ++iterator) + { + if (iterator->handle == handle) + { + iterator->pollfdValue.events = events; + mRecreatePollfds = true; + return E_OK; + } + } + return E_UNKNOWN; +} + +/** + * checks if a filedescriptor is valid + * @param fd the filedescriptor + * @return true if the fd is valid + */ +bool CAmSocketHandler::fdIsValid(const int fd) const +{ + return (fcntl(fd, F_GETFL) != -1 || errno != EBADF); +} + +/** + * whenever a timer is up, this function needs to be called. + * Removes the fired timer, calls the callback and resets mTimeout + */ +void CAmSocketHandler::timerUp() +{ + //first fire the event + mListActiveTimer.front().callback->Call(mListActiveTimer.front().handle, mListActiveTimer.front().userData); + + //then remove the first timer, the one who fired + mListActiveTimer.pop_front(); + if (!mListActiveTimer.empty()) + { + //substract the old value from all timers in the list + std::for_each(mListActiveTimer.begin(), mListActiveTimer.end(), CAmShSubstractTime(mTimeout)); + mTimeout = mListActiveTimer.front().countdown; + } + else + { + mTimeout.tv_nsec = -1; + mTimeout.tv_sec = -1; + } +} + +/** + * init the timers + */ +void CAmSocketHandler::initTimer() +{ + if (!mListActiveTimer.empty()) + { + mTimeout = mListActiveTimer.front().countdown; + } + else + { + mTimeout.tv_nsec = -1; + mTimeout.tv_sec = -1; + } +} + +/** + * convert timespec to milliseconds + * @param time time in timespec + * @return time in milliseconds + */ +inline int CAmSocketHandler::timespec2ms(const timespec & time) +{ + return (time.tv_nsec == -1 && time.tv_sec == -1) ? -1 : time.tv_sec * 1000 + time.tv_nsec / 1000000; +} + +inline timespec* CAmSocketHandler::insertTime(timespec& buffertime) +{ + buffertime.tv_nsec = mTimeout.tv_nsec; + buffertime.tv_sec = mTimeout.tv_sec; + return (mTimeout.tv_nsec == -1 && mTimeout.tv_sec == -1) ? NULL : &buffertime; +} + +/** + * functor to easy substract from each countdown + * @param t value to substract from + */ +void CAmSocketHandler::CAmShSubstractTime::operator ()(sh_timer_s & t) const +{ + int val = 0; + if ((val = t.countdown.tv_nsec - param.tv_nsec) < 0) + { + t.countdown.tv_nsec = 1000000000 + val; + t.countdown.tv_sec--; + } + else + { + t.countdown.tv_nsec = val; + } + (t.countdown.tv_sec - param.tv_sec) < 0 ? 0 : (t.countdown.tv_sec -= param.tv_sec); +} + +void CAmSocketHandler::CAmShCopyPollfd::operator ()(const sh_poll_s & row) +{ + pollfd temp = row.pollfdValue; + temp.revents = 0; + mArray.push_back(temp); +} +} diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp index 9e052cc..92fb09d 100644 --- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp +++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp @@ -23,30 +23,30 @@ */ #include "CAmTelnetMenuHelper.h" -#include "TelnetServer.h" -#include "DatabaseHandler.h" -#include "ControlSender.h" -#include "CommandSender.h" -#include "RoutingSender.h" -#include "RoutingReceiver.h" -#include "CommandReceiver.h" -#include "ControlReceiver.h" -#include "Router.h" -#include "config.h" -#include "DLTWrapper.h" #include +#include "config.h" +#include "CAmRouter.h" +#include "CAmTelnetServer.h" +#include "CAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "CAmCommandSender.h" +#include "CAmRoutingSender.h" +#include "CAmRoutingReceiver.h" +#include "CAmCommandReceiver.h" +#include "CAmControlReceiver.h" +#include "shared/CAmDltWrapper.h" static const std::string COLOR_WELCOME("\033[1;33m\033[44m"); static const std::string COLOR_HEAD("\033[1m\033[42m"); static const std::string COLOR_DEFAULT("\033[0m"); -using namespace am; +namespace am { CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL; /****************************************************************************/ -CAmTelnetMenuHelper::CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, TelnetServer *iTelnetServer) +CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer) /****************************************************************************/ :mpTelenetServer(iTelnetServer), mpSocketHandler(iSocketHandler), mpCommandSender(iCommandSender), mpCommandReceiver(iCommandReceiver), mpRoutingSender(iRoutingSender), mpRoutingReceiver(iRoutingReceiver), mpControlSender(iControlSender), mpControlReceiver(iControlReceiver), mpDatabasehandler(iDatabasehandler), mpRouter(iRouter) { @@ -1296,7 +1296,7 @@ void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks"); } } - +} diff --git a/AudioManagerDaemon/src/CAmTelnetServer.cpp b/AudioManagerDaemon/src/CAmTelnetServer.cpp new file mode 100644 index 0000000..1274a8d --- /dev/null +++ b/AudioManagerDaemon/src/CAmTelnetServer.cpp @@ -0,0 +1,262 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmTelnetServer.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmTelnetServer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "CAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "shared/CAmDltWrapper.h" +#include "CAmTelnetMenuHelper.h" + +namespace am { + +CAmTelnetServer* CAmTelnetServer::instance = NULL; + +#define PRINT_BOOL(var) var ? output+="true\t\t" : output+="false\t\t"; + +CAmTelnetServer::CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, unsigned int servPort, unsigned int maxConnections) + :telnetConnectFiredCB(this,&CAmTelnetServer::connectSocket), + telnetReceiveFiredCB(this,&CAmTelnetServer::receiveData), + telnetDispatchCB(this,&CAmTelnetServer::dispatchData), + telnetCheckCB(this,&CAmTelnetServer::check), + mSocketHandler(iSocketHandler), + mCommandSender(iCommandSender), + mCommandReceiver(iCommandReceiver), + mRoutingSender(iRoutingSender), + mRoutingReceiver(iRoutingReceiver), + mControlSender(iControlSender), + mControlReceiver(iControlReceiver), + mDatabasehandler(iDatabasehandler), + mRouter(iRouter), + mConnecthandle(), + mMsgList(), + mListConnections(), + mConnectFD(NULL), + mServerPort(servPort), + mMaxConnections(maxConnections), + mTelnetMenuHelper(iSocketHandler,iCommandSender,iCommandReceiver,iRoutingSender,iRoutingReceiver,iControlSender,iControlReceiver,iDatabasehandler,iRouter,this) +{ + assert(mSocketHandler!=NULL); + assert(mCommandReceiver!=NULL); + assert(mCommandSender!=NULL); + assert(mControlSender!=NULL); + assert(mControlReceiver!=NULL); + assert(mRoutingSender!=NULL); + assert(mRoutingReceiver!=NULL); + assert(mDatabasehandler!=NULL); + assert(mRouter!=NULL); + assert(servPort!=0); + assert(mMaxConnections!=0); + + instance = this; + //mTelnetMenuHelper.setTelnetServer(this); + + int yes = 1; + struct sockaddr_in servAddr; + + //setup the port Listener + mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = INADDR_ANY; + servAddr.sin_port = htons(servPort); + bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr)); + + if (listen(mConnectFD,mMaxConnections) < 0) + { + logError("TelnetServer::TelnetServerk cannot listen ",errno); + } + else + logInfo("TelnetServer::TelnetServer started listening on port", mServerPort); + + int a=1; + ioctl (mConnectFD, FIONBIO, (char *) &a); + setsockopt (mConnectFD, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof (a)); + + short events = 0; + events |= POLLIN; + mSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle); +} + +CAmTelnetServer::~CAmTelnetServer() +{ +} + +void CAmTelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //first, accept the connection, create a new filedescriptor + struct sockaddr answer; + socklen_t len=sizeof(answer); + connection_s connection; + connection.handle = 0; + connection.filedescriptor = accept(pfd.fd, (struct sockaddr*)&answer, &len); + + // Notiy menuhelper + mTelnetMenuHelper.newSocketConnection(connection.filedescriptor); + + //set the correct event: + short event = 0; + event |=POLLIN; + + //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data + mSocketHandler->addFDPoll(connection.filedescriptor,event,NULL,&telnetReceiveFiredCB,&telnetCheckCB,&telnetDispatchCB,NULL,connection.handle); + mListConnections.push_back(connection); +} + +void CAmTelnetServer::disconnectClient(int filedescriptor) +{ + std::vector::iterator iter = mListConnections.begin(); + while(iter != mListConnections.end()) + { + if( filedescriptor == iter->filedescriptor ) + { + if( E_OK == mSocketHandler->removeFDPoll(iter->handle)) + { + mListConnections.erase(iter); + close(filedescriptor); + } + else + { + // TODO: Handle error + } + + break; + } + iter++; + } +} + +void CAmTelnetServer::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //initialize buffer + char buffer[100]; + //read until buffer is full or no more data is there + int read=recv(pollfd.fd,buffer,100,NULL); + if (read>1) + { + //read the message and store it in a queue - its a telnet connection so data will be sent on enter ! + std::string msg=std::string(buffer,read); + mMsgList.push(msg); + } +} + +bool CAmTelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData) +{ + (void) userData; + std::vector::iterator iterator=mListConnections.begin(); + for(;iterator!=mListConnections.end();++iterator) + { + if(iterator->handle==handle) break; + } + //if (iterator==mListConnections.end()) return false; + + std::string command; + std::queue MsgQueue; + if(!mMsgList.empty()) + { + sliceCommand(mMsgList.front(),command,MsgQueue); + mMsgList.pop(); + } + + mTelnetMenuHelper.enterCmdQueue(MsgQueue,iterator->filedescriptor); + + // must return false to stop endless polling + return false; + + /* + mMsgList.pop(); + mMapCommand_t::iterator commandIter=mMapCommands.find(command); + if (commandIter==mMapCommands.end()) + { + send(iterator->filedescriptor,"Command not found!\n",20,0); + } + else + { + commandIter->second(msg,iterator->filedescriptor); + //(*commandIter).second(msg,iterator->filedescriptor); + } + + //remove the message from the queue and return false if there is no more message to read. + if (mMsgList.size()!=0) return true; + return false; + */ +} + +bool CAmTelnetServer::check(const sh_pollHandle_t handle, void *userData) +{ + (void)handle; + (void)userData; + if (mMsgList.size() != 0) return true; + return false; +} + +void am::CAmTelnetServer::sliceCommand(const std::string & string, std::string & command, std::queue & MsgQueue) +{ + (void) command; + std::stringstream stream(string); + std::istream_iterator begin(stream); + std::istream_iterator end; + std::string cmd; + bool endOfStream = false; + + int c = 0; + + while(!endOfStream) + { + cmd = *begin; + MsgQueue.push(cmd); + begin++; + + if(begin == end ) + { + endOfStream = true; + } + c++; + } + + + /* + command = *begin++; + msg = std::vector(begin, end); + */ +} +} + + diff --git a/AudioManagerDaemon/src/CommandReceiver.cpp b/AudioManagerDaemon/src/CommandReceiver.cpp deleted file mode 100644 index 21e19d9..0000000 --- a/AudioManagerDaemon/src/CommandReceiver.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommandReveiver.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "CommandReceiver.h" -#include "DatabaseHandler.h" -#include "ControlSender.h" -#include "DLTWrapper.h" -#include -#include -#include - -using namespace am; - -CommandReceiver::CommandReceiver(DatabaseHandler *iDatabaseHandler, ControlSender *iControlSender, SocketHandler *iSocketHandler) : - mDatabaseHandler(iDatabaseHandler), // - mControlSender(iControlSender), // - mSocketHandler(iSocketHandler), // - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false) - -{ - assert(mDatabaseHandler!=NULL); - assert(mSocketHandler!=NULL); - assert(mControlSender!=NULL); -} - -CommandReceiver::CommandReceiver(DatabaseHandler *iDatabaseHandler, ControlSender *iControlSender, SocketHandler *iSocketHandler, DBusWrapper *iDBusWrapper) : - mDatabaseHandler(iDatabaseHandler), // - mControlSender(iControlSender), // - mDBusWrapper(iDBusWrapper), // - mSocketHandler(iSocketHandler), // - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false) -{ - assert(mDatabaseHandler!=NULL); - assert(mSocketHandler!=NULL); - assert(mControlSender!=NULL); - assert(mDBusWrapper!=NULL); -} - -CommandReceiver::~CommandReceiver() -{ -} - -am_Error_e CommandReceiver::connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) -{ - logInfo("CommandReceiver::connect got called, sourceID=", sourceID, "sinkID=", sinkID); - return mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID); -} - -am_Error_e CommandReceiver::disconnect(const am_mainConnectionID_t mainConnectionID) -{ - logInfo("CommandReceiver::disconnect got called, mainConnectionID=", mainConnectionID); - return mControlSender->hookUserDisconnectionRequest(mainConnectionID); -} - -am_Error_e CommandReceiver::setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ - logInfo("CommandReceiver::setVolume got called, sinkID=", sinkID, "volume=", volume); - return mControlSender->hookUserVolumeChange(sinkID, volume); -} - -am_Error_e CommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep) -{ - logInfo("CommandReceiver::volumeStep got called, sinkID=", sinkID, "volumeStep=", volumeStep); - return mControlSender->hookUserVolumeStep(sinkID, volumeStep); -} - -am_Error_e CommandReceiver::setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - logInfo("CommandReceiver::setSinkMuteState got called, sinkID=", sinkID, "muteState=", muteState); - return mControlSender->hookUserSetSinkMuteState(sinkID, muteState); -} - -am_Error_e CommandReceiver::setMainSinkSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - logInfo("CommandReceiver::setMainSinkSoundProperty got called, sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value); - return mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty); -} - -am_Error_e CommandReceiver::setMainSourceSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - logInfo("CommandReceiver::setMainSourceSoundProperty got called, sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value); - return mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty); -} - -am_Error_e CommandReceiver::setSystemProperty(const am_SystemProperty_s & property) -{ - logInfo("CommandReceiver::setSystemProperty got called", "type=", property.type, "soundPropertyValue=", property.value); - return mControlSender->hookUserSetSystemProperty(property); -} - -am_Error_e CommandReceiver::getListMainConnections(std::vector & listConnections) const -{ - return mDatabaseHandler->getListVisibleMainConnections(listConnections); - -} - -am_Error_e CommandReceiver::getListMainSinks(std::vector& listMainSinks) const -{ - return mDatabaseHandler->getListMainSinks(listMainSinks); -} - -am_Error_e CommandReceiver::getListMainSources(std::vector& listMainSources) const -{ - return mDatabaseHandler->getListMainSources(listMainSources); -} - -am_Error_e CommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const -{ - return mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties); -} - -am_Error_e CommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const -{ - return mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties); -} - -am_Error_e CommandReceiver::getListSourceClasses(std::vector & listSourceClasses) const -{ - return mDatabaseHandler->getListSourceClasses(listSourceClasses); -} - -am_Error_e CommandReceiver::getListSinkClasses(std::vector & listSinkClasses) const -{ - return mDatabaseHandler->getListSinkClasses(listSinkClasses); -} - -am_Error_e CommandReceiver::getListSystemProperties(std::vector & listSystemProperties) const -{ - return mDatabaseHandler->getListSystemProperties(listSystemProperties); -} - -am_Error_e CommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const -{ - return mDatabaseHandler->getTimingInformation(mainConnectionID, delay); -} - -am_Error_e CommandReceiver::getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const -{ -#ifdef WITH_DBUS_WRAPPER - dbusConnectionWrapper = mDBusWrapper; - return E_OK; -#else - return E_UNKNOWN; -#endif /*WITH_DBUS_WRAPPER*/ -} - -am_Error_e CommandReceiver::getSocketHandler(SocketHandler *& socketHandler) const -{ - socketHandler = mSocketHandler; - return E_OK; -} - -void CommandReceiver::getInterfaceVersion(std::string & version) const -{ - version = CommandReceiveVersion; -} - -void CommandReceiver::confirmCommandReady(const uint16_t handle) -{ - mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); - if (mWaitStartup && mListStartupHandles.empty()) - mControlSender->confirmCommandReady(); -} - -void CommandReceiver::confirmCommandRundown(const uint16_t handle) -{ - mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); - if (mWaitRundown && mListRundownHandles.empty()) - mControlSender->confirmCommandRundown(); -} - -uint16_t CommandReceiver::getStartupHandle() -{ - uint16_t handle = ++handleCount; //todo: handle overflow - mListStartupHandles.push_back(handle); - return handle; -} - -uint16_t CommandReceiver::getRundownHandle() -{ - uint16_t handle = ++handleCount; //todo: handle overflow - mListRundownHandles.push_back(handle); - return handle; -} - -void CommandReceiver::waitOnStartup(bool startup) -{ - mWaitStartup = startup; -} - -void CommandReceiver::waitOnRundown(bool rundown) -{ - mWaitRundown = rundown; -} - diff --git a/AudioManagerDaemon/src/CommandSender.cpp b/AudioManagerDaemon/src/CommandSender.cpp deleted file mode 100644 index c613a4e..0000000 --- a/AudioManagerDaemon/src/CommandSender.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommandSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "CommandSender.h" -#include -#include -#include -#include "CommandReceiver.h" -#include "PluginTemplate.h" -#include "DLTWrapper.h" - -using namespace am; - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 -#define REQUIRED_INTERFACE_VERSION_MINOR 0 - -//!< macro to call all interfaces -#define CALL_ALL_INTERFACES(...) \ - std::vector::iterator iter = mListInterfaces.begin(); \ - std::vector::iterator iterEnd = mListInterfaces.end(); \ - for (; iter__VA_ARGS__; \ - } - -CommandSender::CommandSender(const std::vector& listOfPluginDirectories) : - mListInterfaces(), // - mListLibraryHandles(), // - mListLibraryNames(), // - mCommandReceiver() -{ - std::vector sharedLibraryNameList; - std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); - std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); - - // search communicator plugins in configured directories - for (; dirIter < dirIterEnd; ++dirIter) - { - const char* directoryName = dirIter->c_str(); - logInfo("Searching for CommandPlugins in", *dirIter); - DIR *directory = opendir(directoryName); - - if (!directory) - { - logError("Error opening directory ", *dirIter); - continue; - } - - // iterate content of directory - struct dirent *itemInDirectory = 0; - while ((itemInDirectory = readdir(directory))) - { - unsigned char entryType = itemInDirectory->d_type; - std::string entryName = itemInDirectory->d_name; - - bool regularFile = (entryType == DT_REG || entryType == DT_LNK); - bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); - - if (regularFile && sharedLibExtension) - { - std::string name(directoryName); - sharedLibraryNameList.push_back(name + "/" + entryName); - } - } - closedir(directory); - } - - // iterate all communicator plugins and start them - std::vector::iterator iter = sharedLibraryNameList.begin(); - std::vector::iterator iterEnd = sharedLibraryNameList.end(); - - for (; iter < iterEnd; ++iter) - { - logInfo("Loading CommandSender plugin", *iter); - CommandSendInterface* (*createFunc)(); - void* tempLibHandle = NULL; - createFunc = getCreateFunction(*iter, tempLibHandle); - - if (!createFunc) - { - logInfo("Entry point of CommandPlugin not found", *iter); - continue; - } - - CommandSendInterface* commander = createFunc(); - - if (!commander) - { - logInfo("CommandPlugin initialization failed. Entry Function not callable"); - continue; - } - - //check libversion - std::string version; - commander->getInterfaceVersion(version); - uint16_t minorVersion, majorVersion; - std::istringstream(version.substr(0, 1)) >> majorVersion; - std::istringstream(version.substr(2, 1)) >> minorVersion; - - if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) - { - logInfo("CommandInterface initialization failed. Version of Interface to old"); - continue; - } - - mListInterfaces.push_back(commander); - mListLibraryHandles.push_back(tempLibHandle); - mListLibraryNames.push_back(iter->c_str()); - } -} - -CommandSender::~CommandSender() -{ - unloadLibraries(); -} - -am_Error_e CommandSender::startupInterfaces(CommandReceiver *iCommandReceiver) -{ - mCommandReceiver = iCommandReceiver; - am_Error_e returnError = E_OK; - - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - am_Error_e error = (*iter)->startupInterface(iCommandReceiver); - if (error != E_OK) - { - returnError = error; - } - } - return returnError; -} - -void CommandSender::cbNumberOfSinkClassesChanged() -{ - CALL_ALL_INTERFACES(cbNumberOfSinkClassesChanged()) -} - -void CommandSender::cbNumberOfSourceClassesChanged() -{ - CALL_ALL_INTERFACES(cbNumberOfSourceClassesChanged()) -} - -void CommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ - CALL_ALL_INTERFACES(cbMainConnectionStateChanged(connectionID,connectionState)) -} - -void CommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) -{ - CALL_ALL_INTERFACES(cbMainSinkSoundPropertyChanged(sinkID,SoundProperty)) -} - -void CommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) -{ - CALL_ALL_INTERFACES(cbMainSourceSoundPropertyChanged(sourceID,SoundProperty)) -} - -void CommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - CALL_ALL_INTERFACES(cbSinkAvailabilityChanged(sinkID,availability)) -} - -void CommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - CALL_ALL_INTERFACES(cbSourceAvailabilityChanged(sourceID,availability)) -} - -void CommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ - CALL_ALL_INTERFACES(cbVolumeChanged(sinkID,volume)) -} - -void CommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - CALL_ALL_INTERFACES(cbSinkMuteStateChanged(sinkID,muteState)) -} - -void CommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty) -{ - CALL_ALL_INTERFACES(cbSystemPropertyChanged(SystemProperty)) -} - -void CommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) -{ - CALL_ALL_INTERFACES(cbTimingInformationChanged(mainConnection,time)) -} - -void CommandSender::cbNewMainConnection(const am_MainConnectionType_s mainConnection) -{ - CALL_ALL_INTERFACES(cbNewMainConnection(mainConnection)) -} - -void CommandSender::cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) -{ - CALL_ALL_INTERFACES(cbRemovedMainConnection(mainConnection)) -} - -void CommandSender::cbNewSink(const am_SinkType_s sink) -{ - CALL_ALL_INTERFACES(cbNewSink(sink)) -} - -void CommandSender::cbRemovedSink(const am_sinkID_t sink) -{ - CALL_ALL_INTERFACES(cbRemovedSink(sink)) -} - -void CommandSender::cbNewSource(const am_SourceType_s source) -{ - CALL_ALL_INTERFACES(cbNewSource(source)) -} - -void CommandSender::cbRemovedSource(const am_sourceID_t source) -{ - CALL_ALL_INTERFACES(cbRemovedSource(source)) -} - -void CommandSender::setCommandReady() -{ - mCommandReceiver->waitOnStartup(false); - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - (*iter)->setCommandReady(mCommandReceiver->getStartupHandle()); - } - mCommandReceiver->waitOnStartup(true); -} - -void CommandSender::setCommandRundown() -{ - mCommandReceiver->waitOnRundown(false); - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - (*iter)->setCommandRundown(mCommandReceiver->getRundownHandle()); - } - mCommandReceiver->waitOnRundown(true); -} - -void CommandSender::getInterfaceVersion(std::string & version) const -{ - version = CommandSendVersion; -} - -am_Error_e am::CommandSender::getListPlugins(std::vector & interfaces) const -{ - interfaces = mListLibraryNames; - return E_OK; -} - -void CommandSender::unloadLibraries(void) -{ - std::vector::iterator iterator = mListLibraryHandles.begin(); - for (; iterator < mListLibraryHandles.end(); ++iterator) - { - dlclose(*iterator); - } - mListLibraryHandles.clear(); -} - diff --git a/AudioManagerDaemon/src/ControlReceiver.cpp b/AudioManagerDaemon/src/ControlReceiver.cpp deleted file mode 100644 index 8ef8d23..0000000 --- a/AudioManagerDaemon/src/ControlReceiver.cpp +++ /dev/null @@ -1,514 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file ControlReceiver.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 -#include -#include "ControlReceiver.h" -#include "DatabaseHandler.h" -#include "RoutingSender.h" -#include "CommandSender.h" -#include "Router.h" -#include "DLTWrapper.h" -#include - -using namespace am; - -ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender, SocketHandler *iSocketHandler, Router* iRouter) : - mDatabaseHandler(iDatabaseHandler), // - mRoutingSender(iRoutingSender), // - mCommandSender(iCommandSender), // - mSocketHandler(iSocketHandler), // - mRouter(iRouter) -{ - assert(mDatabaseHandler!=NULL); - assert(mRoutingSender!=NULL); - assert(mCommandSender!=NULL); - assert(mSocketHandler!=NULL); - assert(mRouter!=NULL); -} - -ControlReceiver::~ControlReceiver() -{ -} - -am_Error_e ControlReceiver::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) -{ - return mRouter->getRoute(onlyfree, sourceID, sinkID, returnList); -} - -am_Error_e ControlReceiver::connect(am_Handle_s & handle, am_connectionID_t & connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID) -{ - logInfo("ControlReceiver::connect got called, connectionFormat=", format, "sourceID=", sourceID, "sinkID=", sinkID); - - am_Connection_s tempConnection; - tempConnection.sinkID = sinkID; - tempConnection.sourceID = sourceID; - tempConnection.connectionFormat = format; - tempConnection.connectionID = 0; - - //todo: enter function to find out what happends if the same connection is in the course of being build up. - if (mDatabaseHandler->existConnection(tempConnection)) - return E_ALREADY_EXISTS; //todo:enter the correct connectionID here? - - mDatabaseHandler->enterConnectionDB(tempConnection, connectionID); - return mRoutingSender->asyncConnect(handle, connectionID, sourceID, sinkID, format); -} - -am_Error_e ControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID) -{ - logInfo("ControlReceiver::disconnect got called, connectionID=", connectionID); - - if (!mDatabaseHandler->existConnectionID(connectionID)) - return E_NON_EXISTENT; //todo: check with EA model and correct - return mRoutingSender->asyncDisconnect(handle, connectionID); -} - -am_Error_e ControlReceiver::crossfade(am_Handle_s & handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime) -{ - logInfo("ControlReceiver::crossfade got called, hotSource=", hotSource, "crossfaderID=", crossfaderID, "rampType=", rampType, "rampTime=", rampTime); - - if (!mDatabaseHandler->existcrossFader(crossfaderID)) - return E_NON_EXISTENT; - return mRoutingSender->asyncCrossFade(handle, crossfaderID, hotSource, rampType, rampTime); -} - -am_Error_e ControlReceiver::setSourceState(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SourceState_e state) -{ - logInfo("ControlReceiver::setSourceState got called, sourceID=", sourceID, "state=", state); - - am_SourceState_e sourceState; - if (mDatabaseHandler->getSoureState(sourceID, sourceState) != E_OK) - return E_UNKNOWN; - if (sourceState == state) - return E_NO_CHANGE; - return mRoutingSender->asyncSetSourceState(handle, sourceID, state); -} - -am_Error_e ControlReceiver::setSinkVolume(am_Handle_s & handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - logInfo("ControlReceiver::setSinkVolume got called, sinkID=", sinkID, "volume=", volume, "ramp=", ramp, "time=", time); - - am_volume_t tempVolume; - if (mDatabaseHandler->getSinkVolume(sinkID, tempVolume) != E_OK) - return E_UNKNOWN; - if (tempVolume == volume) - return E_NO_CHANGE; - return mRoutingSender->asyncSetSinkVolume(handle, sinkID, volume, ramp, time); -} - -am_Error_e ControlReceiver::setSourceVolume(am_Handle_s & handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time) -{ - logInfo("ControlReceiver::setSourceVolume got called, sourceID=", sourceID, "volume=", volume, "ramp=", rampType, "time=", time); - - am_volume_t tempVolume; - if (mDatabaseHandler->getSourceVolume(sourceID, tempVolume) != E_OK) - return E_UNKNOWN; - if (tempVolume == volume) - return E_NO_CHANGE; - return mRoutingSender->asyncSetSourceVolume(handle, sourceID, volume, rampType, time); -} - -am_Error_e ControlReceiver::setSinkSoundProperty(am_Handle_s & handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) -{ - logInfo("ControlReceiver::setSinkSoundProperty got called, sinkID=", sinkID, "soundProperty.Type=", soundProperty.type, "soundProperty.value=", soundProperty.value); - - uint16_t value; - if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, soundProperty.type, value) != E_OK) - return E_UNKNOWN; - if (value == soundProperty.value) - return E_NO_CHANGE; - return mRoutingSender->asyncSetSinkSoundProperty(handle, sinkID, soundProperty); -} - -am_Error_e ControlReceiver::setSinkSoundProperties(am_Handle_s & handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) -{ - logInfo("ControlReceiver::setSinkSoundProperties got called, sinkID=", sinkID); - - uint16_t value; - bool noChange = true; - std::vector::const_iterator it = listSoundProperties.begin(); - for (; it != listSoundProperties.end(); ++it) - { - if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, it->type, value) != E_OK) - return (E_UNKNOWN); - if (value != it->value) - noChange = false; - } - if (noChange) - return (E_NO_CHANGE); - return (mRoutingSender->asyncSetSinkSoundProperties(handle, listSoundProperties, sinkID)); -} - -am_Error_e ControlReceiver::setSourceSoundProperty(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) -{ - logInfo("ControlReceiver::setSourceSoundProperty got called, sourceID=", sourceID, "soundProperty.Type=", soundProperty.type, "soundProperty.value=", soundProperty.value); - - uint16_t value; - if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, soundProperty.type, value) != E_OK) - return E_UNKNOWN; - if (value == soundProperty.value) - return E_NO_CHANGE; - return mRoutingSender->asyncSetSourceSoundProperty(handle, sourceID, soundProperty); -} - -am_Error_e ControlReceiver::setSourceSoundProperties(am_Handle_s & handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) -{ - logInfo("ControlReceiver::setSourceSoundProperties got called, sourceID=", sourceID); - - uint16_t value; - bool noChange = true; - std::vector::const_iterator it = listSoundProperties.begin(); - for (; it != listSoundProperties.end(); ++it) - { - if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, it->type, value) != E_OK) - return (E_UNKNOWN); - if (value != it->value) - noChange = false; - } - if (noChange) - return (E_NO_CHANGE); - return (mRoutingSender->asyncSetSourceSoundProperties(handle, listSoundProperties, sourceID)); -} - -am_Error_e ControlReceiver::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - logInfo("ControlReceiver::setDomainState got called, domainID=", domainID, "domainState=", domainState); - - am_DomainState_e tempState = DS_UNKNOWN; - if (mDatabaseHandler->getDomainState(domainID, tempState) != E_OK) - return E_UNKNOWN; - if (tempState == domainState) - return E_NO_CHANGE; - return mRoutingSender->setDomainState(domainID, domainState); -} - -am_Error_e ControlReceiver::abortAction(const am_Handle_s handle) -{ - logInfo("ControlReceiver::abortAction got called, handle.type=", handle.handle, "handle.handleType=", handle.handleType); - - return mRoutingSender->asyncAbort(handle); -} - -am_Error_e ControlReceiver::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - return mDatabaseHandler->enterDomainDB(domainData, domainID); -} - -am_Error_e ControlReceiver::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID) -{ - return mDatabaseHandler->enterMainConnectionDB(mainConnectionData, connectionID); -} - -am_Error_e ControlReceiver::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - return mDatabaseHandler->enterSinkDB(sinkData, sinkID); -} - -am_Error_e ControlReceiver::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - return mDatabaseHandler->enterCrossfaderDB(crossfaderData, crossfaderID); -} - -am_Error_e ControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - return mDatabaseHandler->enterGatewayDB(gatewayData, gatewayID); -} - -am_Error_e ControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - return mDatabaseHandler->enterSourceDB(sourceData, sourceID); -} - -am_Error_e ControlReceiver::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) -{ - return mDatabaseHandler->enterSinkClassDB(sinkClass, sinkClassID); -} - -am_Error_e ControlReceiver::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) -{ - return mDatabaseHandler->enterSourceClassDB(sourceClassID, sourceClass); -} - -am_Error_e ControlReceiver::enterSystemPropertiesListDB(const std::vector & listSystemProperties) -{ - return mDatabaseHandler->enterSystemProperties(listSystemProperties); -} - -am_Error_e ControlReceiver::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) -{ - return mDatabaseHandler->changeMainConnectionRouteDB(mainconnectionID, listConnectionID); -} - -am_Error_e ControlReceiver::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) -{ - return mDatabaseHandler->changeMainConnectionStateDB(mainconnectionID, connectionState); -} - -am_Error_e ControlReceiver::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) -{ - return mDatabaseHandler->changeSinkMainVolumeDB(mainVolume, sinkID); -} - -am_Error_e ControlReceiver::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) -{ - return mDatabaseHandler->changeSinkAvailabilityDB(availability, sinkID); -} - -am_Error_e ControlReceiver::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) -{ - return mDatabaseHandler->changDomainStateDB(domainState, domainID); -} - -am_Error_e ControlReceiver::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) -{ - return mDatabaseHandler->changeSinkMuteStateDB(muteState, sinkID); -} - -am_Error_e ControlReceiver::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sinkID); -} - -am_Error_e ControlReceiver::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sourceID); -} - -am_Error_e ControlReceiver::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) -{ - return mDatabaseHandler->changeSourceAvailabilityDB(availability, sourceID); -} - -am_Error_e ControlReceiver::changeSystemPropertyDB(const am_SystemProperty_s & property) -{ - return mDatabaseHandler->changeSystemPropertyDB(property); -} - -am_Error_e ControlReceiver::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) -{ - return mDatabaseHandler->removeMainConnectionDB(mainConnectionID); -} - -am_Error_e ControlReceiver::removeSinkDB(const am_sinkID_t sinkID) -{ - return mDatabaseHandler->removeSinkDB(sinkID); -} - -am_Error_e ControlReceiver::removeSourceDB(const am_sourceID_t sourceID) -{ - return mDatabaseHandler->removeSourceDB(sourceID); -} - -am_Error_e ControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID) -{ - return mDatabaseHandler->removeGatewayDB(gatewayID); -} - -am_Error_e ControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) -{ - return mDatabaseHandler->removeCrossfaderDB(crossfaderID); -} - -am_Error_e ControlReceiver::removeDomainDB(const am_domainID_t domainID) -{ - return mDatabaseHandler->removeDomainDB(domainID); -} - -am_Error_e ControlReceiver::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const -{ - return mDatabaseHandler->getSourceClassInfoDB(sourceID, classInfo); -} - -am_Error_e ControlReceiver::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const -{ - return mDatabaseHandler->getSinkClassInfoDB(sinkID, sinkClass); -} - -am_Error_e ControlReceiver::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const -{ - return mDatabaseHandler->getSinkInfoDB(sinkID, sinkData); -} - -am_Error_e ControlReceiver::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const -{ - return mDatabaseHandler->getSourceInfoDB(sourceID, sourceData); -} - -am_Error_e ControlReceiver::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const -{ - return mDatabaseHandler->getMainConnectionInfoDB(mainConnectionID, mainConnectionData); -} - -am_Error_e ControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const -{ - return mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData); -} - -am_Error_e ControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const -{ - return mDatabaseHandler->getCrossfaderInfoDB(crossfaderID, crossfaderData); -} - -am_Error_e ControlReceiver::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const -{ - return mDatabaseHandler->getListSinksOfDomain(domainID, listSinkID); -} - -am_Error_e ControlReceiver::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const -{ - return mDatabaseHandler->getListSourcesOfDomain(domainID, listSourceID); -} - -am_Error_e ControlReceiver::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const -{ - return mDatabaseHandler->getListCrossfadersOfDomain(domainID, listGatewaysID); -} - -am_Error_e ControlReceiver::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const -{ - return mDatabaseHandler->getListGatewaysOfDomain(domainID, listGatewaysID); -} - -am_Error_e ControlReceiver::getListMainConnections(std::vector & listMainConnections) const -{ - return mDatabaseHandler->getListMainConnections(listMainConnections); -} - -am_Error_e ControlReceiver::getListDomains(std::vector & listDomains) const -{ - return mDatabaseHandler->getListDomains(listDomains); -} - -am_Error_e ControlReceiver::getListConnections(std::vector & listConnections) const -{ - return mDatabaseHandler->getListConnections(listConnections); -} - -am_Error_e ControlReceiver::getListSinks(std::vector & listSinks) const -{ - return mDatabaseHandler->getListSinks(listSinks); -} - -am_Error_e ControlReceiver::getListSources(std::vector & listSources) const -{ - return mDatabaseHandler->getListSources(listSources); -} - -am_Error_e ControlReceiver::getListSourceClasses(std::vector & listSourceClasses) const -{ - return mDatabaseHandler->getListSourceClasses(listSourceClasses); -} - -am_Error_e ControlReceiver::getListHandles(std::vector & listHandles) const -{ - return mRoutingSender->getListHandles(listHandles); -} - -am_Error_e ControlReceiver::getListCrossfaders(std::vector & listCrossfaders) const -{ - return mDatabaseHandler->getListCrossfaders(listCrossfaders); -} - -am_Error_e ControlReceiver::getListGateways(std::vector & listGateways) const -{ - return mDatabaseHandler->getListGateways(listGateways); -} - -am_Error_e ControlReceiver::getListSinkClasses(std::vector & listSinkClasses) const -{ - return mDatabaseHandler->getListSinkClasses(listSinkClasses); -} - -am_Error_e ControlReceiver::getListSystemProperties(std::vector & listSystemProperties) const -{ - return mDatabaseHandler->getListSystemProperties(listSystemProperties); -} - -am_Error_e ControlReceiver::changeSinkClassInfoDB(const am_SinkClass_s & classInfo) -{ - return mDatabaseHandler->changeSinkClassInfoDB(classInfo); -} - -am_Error_e ControlReceiver::changeSourceClassInfoDB(const am_SourceClass_s & classInfo) -{ - return mDatabaseHandler->changeSourceClassInfoDB(classInfo); -} - -am_Error_e ControlReceiver::removeSinkClassDB(const am_sinkClass_t sinkClassID) -{ - return mDatabaseHandler->removeSinkClassDB(sinkClassID); -} - -am_Error_e ControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceClassID) -{ - return mDatabaseHandler->removeSourceClassDB(sourceClassID); -} - -void ControlReceiver::setCommandReady() -{ - logInfo("ControlReceiver::setCommandReady got called"); - mCommandSender->setCommandReady(); -} - -void ControlReceiver::setRoutingReady() -{ - logInfo("ControlReceiver::setRoutingReady got called"); - mRoutingSender->setRoutingReady(); -} - -void ControlReceiver::confirmControllerReady() -{ - //todo: one time implement here system interaction with NSM -} - -void ControlReceiver::confirmControllerRundown() -{ - //todo: one time implement here system interaction with NSM -} - -am_Error_e ControlReceiver::getSocketHandler(SocketHandler *& socketHandler) -{ - socketHandler = mSocketHandler; - return E_OK; -} - -void ControlReceiver::setCommandRundown() -{ - logInfo("ControlReceiver::setCommandRundown got called"); - mCommandSender->setCommandRundown(); -} - -void ControlReceiver::setRoutingRundown() -{ - logInfo("ControlReceiver::setRoutingRundown got called"); - mRoutingSender->setRoutingRundown(); -} - -void ControlReceiver::getInterfaceVersion(std::string & version) const -{ - version = ControlReceiveVersion; -} - - - diff --git a/AudioManagerDaemon/src/ControlSender.cpp b/AudioManagerDaemon/src/ControlSender.cpp deleted file mode 100644 index 492244e..0000000 --- a/AudioManagerDaemon/src/ControlSender.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file ControlSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "ControlSender.h" -#include "PluginTemplate.h" -#include "DLTWrapper.h" -#include -#include -#include -#include -#include - -using namespace am; - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 -#define REQUIRED_INTERFACE_VERSION_MINOR 0 - -ControlSender::ControlSender(std::string controlPluginFile) : - mlibHandle(NULL), // - mController(NULL) -{ - std::ifstream isfile(controlPluginFile.c_str()); - if (!isfile) - { - logError("ControlSender::ControlSender: Controller plugin not found:", controlPluginFile); - } - else if (!controlPluginFile.empty()) - { - ControlSendInterface* (*createFunc)(); - createFunc = getCreateFunction(controlPluginFile, mlibHandle); - assert(createFunc!=NULL); - mController = createFunc(); - - //check libversion - std::string version; - mController->getInterfaceVersion(version); - uint16_t minorVersion, majorVersion; - std::istringstream(version.substr(0, 1)) >> majorVersion; - std::istringstream(version.substr(2, 1)) >> minorVersion; - - if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) - { - logError("ControlSender::ControlSender: Interface Version of Controller too old, exiting now"); - throw std::runtime_error("Interface Version of Controller too old"); - } - } - else - { - logError("ControlSender::ControlSender: No controller loaded !"); - } -} - -ControlSender::~ControlSender() -{ - if (mlibHandle) - dlclose(mlibHandle); -} - -am_Error_e ControlSender::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) -{ - return mController->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID); -} - -am_Error_e ControlSender::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) -{ - return mController->hookUserDisconnectionRequest(connectionID); -} - -am_Error_e ControlSender::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) -{ - return mController->hookUserSetMainSinkSoundProperty(sinkID, soundProperty); -} - -am_Error_e ControlSender::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) -{ - return mController->hookUserSetMainSourceSoundProperty(sourceID, soundProperty); -} - -am_Error_e ControlSender::hookUserSetSystemProperty(const am_SystemProperty_s & property) -{ - return mController->hookUserSetSystemProperty(property); -} - -am_Error_e ControlSender::hookUserVolumeChange(const am_sinkID_t sinkID, const am_mainVolume_t newVolume) -{ - return mController->hookUserVolumeChange(sinkID, newVolume); -} - -am_Error_e ControlSender::hookUserVolumeStep(const am_sinkID_t sinkID, const int16_t increment) -{ - return mController->hookUserVolumeStep(sinkID, increment); -} - -am_Error_e ControlSender::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - return mController->hookUserSetSinkMuteState(sinkID, muteState); -} - -am_Error_e ControlSender::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - return mController->hookSystemRegisterDomain(domainData, domainID); -} - -am_Error_e ControlSender::hookSystemDeregisterDomain(const am_domainID_t domainID) -{ - return mController->hookSystemDeregisterDomain(domainID); -} - -void ControlSender::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) -{ - return mController->hookSystemDomainRegistrationComplete(domainID); -} - -am_Error_e ControlSender::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - return mController->hookSystemRegisterSink(sinkData, sinkID); -} - -am_Error_e ControlSender::hookSystemDeregisterSink(const am_sinkID_t sinkID) -{ - return mController->hookSystemDeregisterSink(sinkID); -} - -am_Error_e ControlSender::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - return mController->hookSystemRegisterSource(sourceData, sourceID); -} - -am_Error_e ControlSender::hookSystemDeregisterSource(const am_sourceID_t sourceID) -{ - return mController->hookSystemDeregisterSource(sourceID); -} - -am_Error_e ControlSender::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - return mController->hookSystemRegisterGateway(gatewayData, gatewayID); -} - -am_Error_e ControlSender::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) -{ - return mController->hookSystemDeregisterGateway(gatewayID); -} - -am_Error_e ControlSender::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - return mController->hookSystemRegisterCrossfader(crossfaderData, crossfaderID); -} - -am_Error_e ControlSender::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) -{ - return mController->hookSystemDeregisterCrossfader(crossfaderID); -} - -void ControlSender::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - mController->hookSystemSinkVolumeTick(handle, sinkID, volume); -} - -void ControlSender::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - mController->hookSystemSourceVolumeTick(handle, sourceID, volume); -} - -void ControlSender::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - mController->hookSystemInterruptStateChange(sourceID, interruptState); -} - -void ControlSender::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mController->hookSystemSinkAvailablityStateChange(sinkID, availability); -} - -void ControlSender::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mController->hookSystemSourceAvailablityStateChange(sourceID, availability); -} - -void ControlSender::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) -{ - mController->hookSystemDomainStateChange(domainID, state); -} - -void ControlSender::hookSystemReceiveEarlyData(const std::vector & data) -{ - mController->hookSystemReceiveEarlyData(data); -} - -void ControlSender::hookSystemSpeedChange(const am_speed_t speed) -{ - mController->hookSystemSpeedChange(speed); -} - -void ControlSender::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) -{ - mController->hookSystemTimingInformationChanged(mainConnectionID, time); -} - -void ControlSender::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) -{ - mController->cbAckConnect(handle, errorID); -} - -void ControlSender::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) -{ - mController->cbAckDisconnect(handle, errorID); -} - -void ControlSender::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) -{ - mController->cbAckCrossFade(handle, hostsink, error); -} - -void ControlSender::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - mController->cbAckSetSinkVolumeChange(handle, volume, error); -} - -void ControlSender::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - mController->cbAckSetSourceVolumeChange(handle, volume, error); -} - -void ControlSender::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - mController->cbAckSetSourceState(handle, error); -} - -void ControlSender::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - mController->cbAckSetSourceSoundProperty(handle, error); -} - -am_Error_e ControlSender::startupController(ControlReceiveInterface *controlreceiveinterface) -{ - return mController->startupController(controlreceiveinterface); -} - -void ControlSender::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - mController->cbAckSetSinkSoundProperty(handle, error); -} - -void ControlSender::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - mController->cbAckSetSinkSoundProperties(handle, error); -} - -void ControlSender::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - mController->cbAckSetSourceSoundProperties(handle, error); -} - -void ControlSender::setControllerReady() -{ - mController->setControllerReady(); -} - -void ControlSender::setControllerRundown() -{ - mController->setControllerRundown(); -} - -am_Error_e am::ControlSender::getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector & listPrioConnectionFormats) -{ - return mController->getConnectionFormatChoice(sourceID, sinkID, listRoute, listPossibleConnectionFormats, listPrioConnectionFormats); -} - -void ControlSender::getInterfaceVersion(std::string & version) const -{ - version = ControlSendVersion; -} - -void ControlSender::confirmCommandReady() -{ - mController->confirmCommandReady(); -} - -void ControlSender::confirmRoutingReady() -{ - mController->confirmRoutingReady(); -} - -void ControlSender::confirmCommandRundown() -{ - mController->confirmCommandRundown(); -} - -void ControlSender::confirmRoutingRundown() -{ - mController->confirmRoutingRundown(); -} - diff --git a/AudioManagerDaemon/src/DBusWrapper.cpp b/AudioManagerDaemon/src/DBusWrapper.cpp deleted file mode 100644 index 71352ef..0000000 --- a/AudioManagerDaemon/src/DBusWrapper.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file SocketHandler.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 -#include -#include -#include -#include -#include -#include -#include -#include "DLTWrapper.h" - -using namespace am; - -#define ROOT_INTROSPECT_XML \ -DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ -"" \ -"" \ -"" \ -" " \ -"" \ -"" \ - -DBusWrapper* DBusWrapper::mReference = NULL; - -DBusWrapper::DBusWrapper(SocketHandler* socketHandler) : - pDbusDispatchCallback(this, &DBusWrapper::dbusDispatchCallback), // - pDbusFireCallback(this, &DBusWrapper::dbusFireCallback), // - pDbusCheckCallback(this, &DBusWrapper::dbusCheckCallback), // - pDbusTimerCallback(this, &DBusWrapper::dbusTimerCallback), // - mDbusConnection(0), // - mDBusError(), // - mNodesList(), // - mListTimerhandlePointer(), // - mSocketHandler(socketHandler) -{ - assert(mSocketHandler!=0); - - dbus_error_init(&mDBusError); - logInfo("DBusWrapper::DBusWrapper Opening DBus connection"); - mDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::DBusWrapper Error while getting the DBus"); - dbus_error_free(&mDBusError); - } - if (NULL == mDbusConnection) - { - logError("DBusWrapper::DBusWrapper DBus Connection is null"); - } - - //then we need to adopt the dbus to our mainloop: - //first, we are old enought to live longer then the connection: - dbus_connection_set_exit_on_disconnect(mDbusConnection, FALSE); - - //we do not need the manual dispatching, since it is not allowed to call from a different thread. So leave it uncommented: - //dbus_connection_set_dispatch_status_function - - //add watch functions: - dbus_bool_t watch = dbus_connection_set_watch_functions(mDbusConnection, addWatch, removeWatch, toogleWatch, this, NULL); - if (!watch) - { - logError("DBusWrapper::DBusWrapper Registering of watch functions failed"); - } - - //add timer functions: - dbus_bool_t timer = dbus_connection_set_timeout_functions(mDbusConnection, addTimeout, removeTimeout, toggleTimeout, this, NULL); - if (!timer) - { - logError("DBusWrapper::DBusWrapper Registering of timer functions failed"); - } - - //register callback for Introspectio - mObjectPathVTable.message_function = DBusWrapper::cbRootIntrospection; - dbus_connection_register_object_path(mDbusConnection, DBUS_SERVICE_OBJECT_PATH, &mObjectPathVTable, this); - int ret = dbus_bus_request_name(mDbusConnection, DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_DO_NOT_QUEUE, &mDBusError); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::DBusWrapper Name Error",mDBusError.message); - dbus_error_free(&mDBusError); - } - if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) - { - logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?",ret); - exit(1); - } -} - -DBusWrapper::~DBusWrapper() -{ - //close the connection again - logInfo("DBusWrapper::~DBusWrapper Closing DBus connection"); - dbus_connection_unref(mDbusConnection); - - //clean up all timerhandles we created but did not delete before - std::vector::iterator it = mListTimerhandlePointer.begin(); - for (; it != mListTimerhandlePointer.end(); ++it) - { - delete *it; - } -} - -void DBusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata) -{ - logInfo("DBusWrapper::~registerCallback register callback:",path); - - std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path; - dbus_error_init(&mDBusError); - mDbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &mDBusError); - dbus_connection_register_object_path(mDbusConnection, completePath.c_str(), vtable, userdata); - if (dbus_error_is_set(&mDBusError)) - { - logError("DBusWrapper::registerCallack error: ",mDBusError.message); - dbus_error_free(&mDBusError); - } - mNodesList.push_back(path); -} - -DBusHandlerResult DBusWrapper::cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference) -{ - logInfo("DBusWrapper::~cbRootIntrospection called:"); - - mReference = (DBusWrapper*) reference; - std::list nodesList = mReference->mNodesList; - DBusMessage * reply; - DBusMessageIter args; - dbus_uint32_t serial = 0; - if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - { - std::list::iterator nodeIter = nodesList.begin(); - const char *xml = ROOT_INTROSPECT_XML; - std::stringstream introspect; - introspect << std::string(xml); - for (; nodeIter != nodesList.end(); ++nodeIter) - { - introspect << ""; - } - introspect << ""; - - 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)) - { - logError("DBusWrapper::~cbRootIntrospection DBUS Out Of Memory!"); - } - - // send the reply && flush the connection - if (!dbus_connection_send(conn, reply, &serial)) - { - logError("DBusWrapper::~cbRootIntrospection 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; - } -} - -void DBusWrapper::getDBusConnection(DBusConnection *& connection) const -{ - connection = mDbusConnection; -} - -dbus_bool_t DBusWrapper::addWatch(DBusWatch *watch, void *userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - return mReference->addWatchDelegate(watch, userData); -} - -dbus_bool_t DBusWrapper::addWatchDelegate(DBusWatch * watch, void* userData) -{ - (void) userData; - int16_t event = 0; - sh_pollHandle_t handle = 0; - uint flags = dbus_watch_get_flags(watch); - - /* no watch flags for disabled watches */ - if (dbus_watch_get_enabled(watch)) - { - if (flags & DBUS_WATCH_READABLE) - event |= POLLIN; - if (flags & DBUS_WATCH_WRITABLE) - event |= POLLOUT; - } - - logInfo("DBusWrapper::addWatchDelegate entered new watch, fd=",dbus_watch_get_unix_fd(watch),"event flag=",event); - am_Error_e error = mSocketHandler->addFDPoll(dbus_watch_get_unix_fd(watch), event, NULL, &pDbusFireCallback, &pDbusCheckCallback, &pDbusDispatchCallback, watch, handle); - - //if everything is alright, add the watch and the handle to our map so we know this relationship - if (error == E_OK && handle != 0) - { - mMapHandleWatch.insert(std::make_pair(watch, handle)); - return true; - } - logError("DBusWrapper::addWatchDelegate entering watch failed"); - return (true); -} - -void DBusWrapper::removeWatch(DBusWatch *watch, void *userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - mReference->removeWatchDelegate(watch, userData); -} - -void DBusWrapper::removeWatchDelegate(DBusWatch *watch, void *userData) -{ - (void) userData; - std::map::iterator iterator = mMapHandleWatch.begin(); - iterator = mMapHandleWatch.find(watch); - if (iterator != mMapHandleWatch.end()) - mSocketHandler->removeFDPoll(iterator->second); - logInfo("DBusWrapper::removeWatch removed watch with handle",iterator->second); - mMapHandleWatch.erase(iterator); -} - -void DBusWrapper::toogleWatch(DBusWatch *watch, void *userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - mReference->toogleWatchDelegate(watch, userData); -} - -void DBusWrapper::toogleWatchDelegate(DBusWatch *watch, void *userData) -{ - (void) userData; - int16_t event = 0; - dbus_watch_get_unix_fd(watch); - uint flags = dbus_watch_get_flags(watch); - /* no watch flags for disabled watches */ - if (dbus_watch_get_enabled(watch)) - { - if (flags & DBUS_WATCH_READABLE) - event |= POLLIN; - if (flags & DBUS_WATCH_WRITABLE) - event |= POLLOUT; - } - std::map::iterator iterator = mMapHandleWatch.begin(); - iterator = mMapHandleWatch.find(watch); - if (iterator != mMapHandleWatch.end()) - mSocketHandler->updateEventFlags(iterator->second, event); - logInfo("DBusWrapper::toogleWatchDelegate watch was toggeled"); -} - -dbus_bool_t DBusWrapper::addTimeout(DBusTimeout *timeout, void* userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - return mReference->addTimeoutDelegate(timeout, userData); -} - -dbus_bool_t DBusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - if (!dbus_timeout_get_enabled(timeout)) - return false; - - //calculate the timeout in timeval - timespec pollTimeout; - int localTimeout = dbus_timeout_get_interval(timeout); - pollTimeout.tv_sec = localTimeout / 1000; - pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; - - //prepare handle and callback. new is eval, but there is no other choice because we need the pointer! - sh_timerHandle_t* handle = new sh_timerHandle_t; - mListTimerhandlePointer.push_back(handle); - shTimerCallBack* buffer = &pDbusTimerCallback; - - //add the timer to the pollLoop - mSocketHandler->addTimer(pollTimeout, buffer, *handle, timeout); - - //save the handle with dbus context - dbus_timeout_set_data(timeout, handle, NULL); - - //save timeout in Socket context - userData = timeout; - logInfo("DBusWrapper::addTimeoutDelegate a timeout was added"); - return true; -} - -void DBusWrapper::removeTimeout(DBusTimeout *timeout, void* userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - mReference->removeTimeoutDelegate(timeout, userData); -} - -void DBusWrapper::removeTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - (void) userData; - //get the pointer to the handle and remove the timer - sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); - mSocketHandler->removeTimer(*handle); - - //now go throught the timerlist and remove the pointer, free memory - std::vector::iterator it = mListTimerhandlePointer.begin(); - for (; it != mListTimerhandlePointer.end(); ++it) - { - if (*it == handle) - { - mListTimerhandlePointer.erase(it); - break; - } - } - delete handle; - logInfo("DBusWrapper::removeTimeoutDelegate a timeout was removed"); -} - -void DBusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData) -{ - mReference = (DBusWrapper*) userData; - assert(mReference!=0); - mReference->toggleTimeoutDelegate(timeout, userData); -} - -bool am::DBusWrapper::dbusDispatchCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - bool returnVal = true; - dbus_connection_ref(mDbusConnection); - if (dbus_connection_dispatch(mDbusConnection) == DBUS_DISPATCH_COMPLETE) - returnVal = false; - dbus_connection_unref(mDbusConnection); -// logInfo("DBusWrapper::dbusDispatchCallback was called"); - return returnVal; -} - -bool am::DBusWrapper::dbusCheckCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - bool returnVal = false; - dbus_connection_ref(mDbusConnection); - if (dbus_connection_get_dispatch_status(mDbusConnection) == DBUS_DISPATCH_DATA_REMAINS) - returnVal = true; - dbus_connection_unref(mDbusConnection); -// logInfo("DBusWrapper::dbusCheckCallback was called"); - return returnVal; -} - -void am::DBusWrapper::dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - assert(userData!=NULL); - uint flags = 0; - - if (pollfd.revents & POLLIN) - flags |= DBUS_WATCH_READABLE; - if (pollfd.revents & POLLOUT) - flags |= DBUS_WATCH_WRITABLE; - if (pollfd.revents & POLLHUP) - flags |= DBUS_WATCH_HANGUP; - if (pollfd.revents & POLLERR) - flags |= DBUS_WATCH_ERROR; - - DBusWatch *watch = (DBusWatch*) userData; - - dbus_connection_ref(mDbusConnection); - dbus_watch_handle(watch, flags); - dbus_connection_unref(mDbusConnection); -// logInfo("DBusWrapper::dbusFireCallback was called"); -} - -void DBusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) -{ - (void) userData; - //get the pointer to the handle and remove the timer - sh_timerHandle_t* handle = (sh_timerHandle_t*) dbus_timeout_get_data(timeout); - - //stop or restart? - if (dbus_timeout_get_enabled(timeout)) - { - //calculate the timeout in timeval - timespec pollTimeout; - int localTimeout = dbus_timeout_get_interval(timeout); - pollTimeout.tv_sec = localTimeout / 1000; - pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000; - mSocketHandler->restartTimer(*handle, pollTimeout); - } - else - { - mSocketHandler->stopTimer(*handle); - }logInfo("DBusWrapper::toggleTimeoutDelegate was called"); -} - -void DBusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) -{ - assert(userData!=NULL); - if (dbus_timeout_get_enabled((DBusTimeout*) userData)) - { - timespec ts; - ts.tv_nsec = -1; - ts.tv_sec = -1; - mSocketHandler->restartTimer(handle, ts); - } - dbus_timeout_handle((DBusTimeout*) userData); - logInfo("DBusWrapper::dbusTimerCallback was called"); -} - diff --git a/AudioManagerDaemon/src/DLTWrapper.cpp b/AudioManagerDaemon/src/DLTWrapper.cpp deleted file mode 100644 index ad03692..0000000 --- a/AudioManagerDaemon/src/DLTWrapper.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DLTWrapper.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "DLTWrapper.h" -#include -#include -#include - -DLTWrapper* DLTWrapper::mDLTWrapper = NULL; - -DLTWrapper *DLTWrapper::instance(const bool enableNoDLTDebug) -{ - if (!mDLTWrapper) - mDLTWrapper = new DLTWrapper(enableNoDLTDebug); -#ifndef WITH_DLT - if(enableNoDLTDebug) - mDLTWrapper->enableNoDLTDebug(true); -#endif - return mDLTWrapper; -} - -void DLTWrapper::unregisterContext(DltContext & handle) -{ -#ifdef WITH_DLT - dlt_unregister_context(&handle); -#endif -} - -DLTWrapper::DLTWrapper(const bool enableNoDLTDebug) : -#ifndef WITH_DLT - mEnableNoDLTDebug(enableNoDLTDebug), -#endif - mDltContext(), // - mDltContextData() -{ -#ifndef WITH_DLT - std::cout << "[DLT] Running without DLT-support" << std::endl; -#endif -} - -void DLTWrapper::registerApp(const char *appid, const char *description) -{ -#ifdef WITH_DLT - dlt_register_app(appid, description); - //register a default context - dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass"); -#endif -} - -void DLTWrapper::registerContext(DltContext& handle, const char *contextid, const char *description) -{ -#ifdef WITH_DLT - dlt_register_context(&handle, contextid, description); -#else - memcpy(&mDltContext.contextID,contextid,4); - strlen(description); - const size_t str_len = strlen(description); - if(str_len < 2000) - { - mDltContextData.context_description = new char[str_len + 1]; - (void) strcpy(mDltContextData.context_description,description); - } -#endif -} - -void DLTWrapper::init(DltLogLevelType loglevel, DltContext* context) -{ - if (!context) - context = &mDltContext; -#ifdef WITH_DLT - dlt_user_log_write_start(context, &mDltContextData, loglevel); -#endif - -} - -void DLTWrapper::send() -{ -#ifdef WITH_DLT - dlt_user_log_write_finish(&mDltContextData); -#else - if(mEnableNoDLTDebug) - std::cout << "[" << mDltContext.contextID << "] " << std::string(mDltContextData.buffer) << std::endl; - - mDltContextData.size = 0; -#endif -} - -void DLTWrapper::append(const int8_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int8(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const uint8_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint8(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const int16_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int16(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const uint16_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint16(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const int32_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_int32(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const uint32_t value) -{ -#ifdef WITH_DLT - dlt_user_log_write_uint32(&mDltContextData, value); -#else - appendNoDLT(value); -#endif -} - -void DLTWrapper::append(const char*& value) -{ -#ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, value); -#else - memcpy((mDltContextData.buffer+mDltContextData.size),value,strlen(value)); - mDltContextData.size += strlen(value); -#endif -} - -void DLTWrapper::append(const std::string& value) -{ -#ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, value.c_str()); -#else - memcpy((mDltContextData.buffer+mDltContextData.size),value.c_str(),value.size()); - mDltContextData.size += value.size(); -#endif -} - -void DLTWrapper::append(const bool value) -{ -#ifdef WITH_DLT - dlt_user_log_write_bool(&mDltContextData, static_cast(value)); -#else - appendNoDLT(value); -#endif -} - -#ifndef WITH_DLT -template void DLTWrapper::appendNoDLT(T value) -{ - if((mDltContextData.size + sizeof(value)) < DLT_USER_BUF_MAX_SIZE) - { - memcpy((mDltContextData.buffer+mDltContextData.size),&(value),sizeof(value)); - mDltContextData.size += sizeof(value); - } -} - -void DLTWrapper::enableNoDLTDebug(const bool enableNoDLTDebug) -{ - mEnableNoDLTDebug = enableNoDLTDebug; -} -#endif - -DLTWrapper::~DLTWrapper() -{ - if (mDLTWrapper) - delete mDLTWrapper; -} - diff --git a/AudioManagerDaemon/src/DatabaseHandler.cpp b/AudioManagerDaemon/src/DatabaseHandler.cpp deleted file mode 100644 index 54e0129..0000000 --- a/AudioManagerDaemon/src/DatabaseHandler.cpp +++ /dev/null @@ -1,4401 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file Databasehandler.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "DatabaseHandler.h" -#include "DatabaseObserver.h" -#include -#include -#include -#include -#include -#include "DLTWrapper.h" -#include "Router.h" - -#define DOMAIN_TABLE "Domains" -#define SOURCE_CLASS_TABLE "SourceClasses" -#define SINK_CLASS_TABLE "SinkClasses" -#define SOURCE_TABLE "Sources" -#define SINK_TABLE "Sinks" -#define GATEWAY_TABLE "Gateways" -#define CROSSFADER_TABLE "Crossfaders" -#define CONNECTION_TABLE "Connections" -#define MAINCONNECTION_TABLE "MainConnections" -#define INTERRUPT_TABLE "Interrupts" -#define MAIN_TABLE "MainTable" -#define SYSTEM_TABLE "SystemProperties" - -using namespace am; - -const std::string databaseTables[] = -{ " Domains (domainID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), busname VARCHAR(50), nodename VARCHAR(50), early BOOL, complete BOOL, state INTEGER, reserved BOOL);", // - " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // - " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // - " Sources (sourceID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domainID INTEGER, name VARCHAR(50), sourceClassID INTEGER, sourceState INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, interruptState INTEGER, reserved BOOL);", // - " Sinks (sinkID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), domainID INTEGER, sinkClassID INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, muteState INTEGER, mainVolume INTEGER, reserved BOOL);", // - " Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", // - " Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", // - " Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", // - " MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", // - " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" }; - -/** - * template to converts T to std::string - * @param i the value to be converted - * @return the string - */ -template -inline std::string i2s(T const& x) -{ - std::ostringstream o; - o << x; - return o.str(); -} - -DatabaseHandler::DatabaseHandler(std::string databasePath) : - mDatabase(NULL), // - mPath(databasePath), // - mDatabaseObserver(NULL), // - mFirstStaticSink(true), // - mFirstStaticSource(true), // - mFirstStaticGateway(true), // - mFirstStaticSinkClass(true), // - mFirstStaticSourceClass(true), // - mFirstStaticCrossfader(true), // - mListConnectionFormat() -{ - - std::ifstream infile(mPath.c_str()); - - if (infile) - { - remove(mPath.c_str()); - logInfo("DatabaseHandler::DatabaseHandler Knocked down database"); - } - - bool dbOpen = openDatabase(); - if (!dbOpen) - { - logInfo("DatabaseHandler::DatabaseHandler problems opening the database!"); - } - - createTables(); -} - -DatabaseHandler::~DatabaseHandler() -{ - logInfo("Closed Database"); - sqlite3_close(mDatabase); -} - -am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - assert(domainData.domainID==0); - assert(!domainData.name.empty()); - assert(!domainData.busname.empty()); - assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX); - - //first check for a reserved domain - sqlite3_stmt* query = NULL, *queryFinal; - int eCode = 0; - std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET name=?, busname=?, nodename=?, early=?, complete=?, state=?, reserved=? WHERE domainID=" + i2s(sqlite3_column_int(query, 0)); - } - else if (eCode == SQLITE_DONE) - { - - command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name, busname, nodename, early, complete, state, reserved) VALUES (?,?,?,?,?,?,?)"; - } - else - { - logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); - sqlite3_bind_text(queryFinal, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC); - sqlite3_bind_text(queryFinal, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC); - sqlite3_bind_text(queryFinal, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC); - sqlite3_bind_int(queryFinal, 4, domainData.early); - sqlite3_bind_int(queryFinal, 5, domainData.complete); - sqlite3_bind_int(queryFinal, 6, domainData.state); - sqlite3_bind_int(queryFinal, 7, 0); - - if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) - { - logError("DatabaseHandler::enterDomainDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - domainID = sqlite3_last_insert_rowid(mDatabase); - logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID); - - am_Domain_s domain = domainData; - domain.domainID = domainID; - if (mDatabaseObserver) - mDatabaseObserver->newDomain(domain); - - return E_OK; -} - -am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID) -{ - assert(mainConnectionData.mainConnectionID==0); - assert(mainConnectionData.connectionState>=CS_UNKNOWN && mainConnectionData.connectionState<=CS_MAX); - assert(mainConnectionData.sinkID!=0); - assert(mainConnectionData.sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - int16_t delay = 0; - std::string command = "INSERT INTO " + std::string(MAINCONNECTION_TABLE) + "(sourceID, sinkID, connectionState, delay) VALUES (?,?,?,-1)"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, mainConnectionData.sourceID); - sqlite3_bind_int(query, 2, mainConnectionData.sinkID); - sqlite3_bind_int(query, 3, mainConnectionData.connectionState); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - connectionID = sqlite3_last_insert_rowid(mDatabase); - - //now check the connectionTable for all connections in the route. IF connectionID exist - command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator elementIterator = mainConnectionData.listConnectionID.begin(); - for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator) - { - sqlite3_bind_int(query, 1, *elementIterator); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - int16_t temp_delay = sqlite3_column_int(query, 1); - if (temp_delay != -1 && delay != -1) - delay += temp_delay; - else - delay = -1; - } - else - { - logError("DatabaseHandler::enterMainConnectionDB did not find route for MainConnection:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - //now we create a table with references to the connections; - command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)"); - assert(this->sqQuery(command)); - - command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin()); - for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator) - { - sqlite3_bind_int(query, 1, *listConnectionIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); - - if (mDatabaseObserver) - { - am_MainConnectionType_s mainConnection; - mainConnection.mainConnectionID=connectionID; - mainConnection.connectionState=mainConnectionData.connectionState; - mainConnection.delay=delay; - mainConnection.sinkID=mainConnectionData.sinkID; - mainConnection.sourceID=mainConnectionData.sourceID; - mDatabaseObserver->newMainConnection(mainConnection); - mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState); - } - - //finally, we update the delay value for the maintable - if (delay == 0) - delay = -1; - return changeDelayMainConnection(delay, connectionID); -} - -am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - assert(sinkData.sinkID=MS_UNKNOWN && sinkData.muteState<=MS_MAX); - - sqlite3_stmt *query = NULL, *queryFinal = NULL; - int eCode = 0; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - command = "UPDATE " + std::string(SINK_TABLE) + " SET name=?, domainID=?, sinkClassID=?, volume=?, visible=?, availability=?, availabilityReason=?, muteState=?, mainVolume=?, reserved=? WHERE sinkID=" + i2s(sqlite3_column_int(query, 0)); - } - else if (eCode == SQLITE_DONE) - { - //if sinkID is zero and the first Static Sink was already entered, the ID is created - if (sinkData.sinkID == 0 && !mFirstStaticSink && !existSinkName(sinkData.name)) - { - command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)"; - } - else - { - //check if the ID already exists - if (existSinkNameOrID(sinkData.sinkID, sinkData.name)) - { - sqlite3_finalize(query); - return E_ALREADY_EXISTS; - } - command = "INSERT INTO " + std::string(SINK_TABLE) + "(name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, reserved, sinkID) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; - } - } - else - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); - sqlite3_bind_text(queryFinal, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); - sqlite3_bind_int(queryFinal, 2, sinkData.domainID); - sqlite3_bind_int(queryFinal, 3, sinkData.sinkClassID); - sqlite3_bind_int(queryFinal, 4, sinkData.volume); - sqlite3_bind_int(queryFinal, 5, sinkData.visible); - sqlite3_bind_int(queryFinal, 6, sinkData.available.availability); - sqlite3_bind_int(queryFinal, 7, sinkData.available.availabilityReason); - sqlite3_bind_int(queryFinal, 8, sinkData.muteState); - sqlite3_bind_int(queryFinal, 9, sinkData.mainVolume); - sqlite3_bind_int(queryFinal, 10, 0); - - //if the ID is not created, we add it to the query - if (sinkData.sinkID != 0) - { - sqlite3_bind_int(queryFinal, 11, sinkData.sinkID); - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticSink) - { - sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY); - mFirstStaticSink = false; - } - - if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(queryFinal); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSinkDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - //now read back the sinkID - command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkID = sqlite3_column_int(query, 0); - } - else - { - sinkID = 0; - logError("DatabaseHandler::existSink database error!:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_finalize(query); - - //now we need to create the additional tables: - command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)"); - assert(this->sqQuery(command)); - command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); - - //fill ConnectionFormats - command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin(); - for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator) - { - sqlite3_bind_int(query, 1, *connectionFormatIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - //Fill SinkSoundProperties - command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin(); - for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator) - { - sqlite3_bind_int(query, 1, SoundPropertyIterator->type); - sqlite3_bind_int(query, 2, SoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if (sinkData.visible == true) - { - command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); - sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - } - - logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID); - am_Sink_s sink = sinkData; - sink.sinkID = sinkID; - if (mDatabaseObserver != NULL) - mDatabaseObserver->newSink(sink); - return E_OK; -} - -am_Error_e DatabaseHandler::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - assert(crossfaderData.crossfaderID=HS_UNKNOWN && crossfaderData.hotSink<=HS_MAX); - assert(!crossfaderData.name.empty()); - assert(existSink(crossfaderData.sinkID_A)); - assert(existSink(crossfaderData.sinkID_B)); - assert(existSource(crossfaderData.sourceID)); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - //if gatewayData is zero and the first Static Sink was already entered, the ID is created - if (crossfaderData.crossfaderID == 0 && !mFirstStaticCrossfader) - { - command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink) VALUES (?,?,?,?,?)"; - } - else - { - //check if the ID already exists - if (existcrossFader(crossfaderData.crossfaderID)) - return E_ALREADY_EXISTS; - command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)"; - } - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC); - sqlite3_bind_int(query, 2, crossfaderData.sinkID_A); - sqlite3_bind_int(query, 3, crossfaderData.sinkID_B); - sqlite3_bind_int(query, 4, crossfaderData.sourceID); - sqlite3_bind_int(query, 5, crossfaderData.hotSink); - - //if the ID is not created, we add it to the query - if (crossfaderData.crossfaderID != 0) - { - sqlite3_bind_int(query, 6, crossfaderData.crossfaderID); - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticCrossfader) - { - sqlite3_bind_int(query, 6, DYNAMIC_ID_BOUNDARY); - mFirstStaticCrossfader = false; - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterCrossfaderDB SQLITE Finalize error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - - //now read back the crossfaderID - command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - crossfaderID = sqlite3_column_int(query, 0); - } - else - { - crossfaderID = 0; - logError("DatabaseHandler::enterCrossfaderDB database error!:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_finalize(query); - - logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID); - - am_Crossfader_s crossfader(crossfaderData); - crossfader.crossfaderID = crossfaderID; - if (mDatabaseObserver) - mDatabaseObserver->newCrossfader(crossfader); - return E_OK; -} - -am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - assert(gatewayData.gatewayIDsqQuery(command)); - command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)"); - assert(this->sqQuery(command)); - - //fill ConnectionFormats - command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin(); - for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator) - { - sqlite3_bind_int(query, 1, *connectionFormatIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - connectionFormatIterator = gatewayData.listSinkFormats.begin(); - for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator) - { - sqlite3_bind_int(query, 1, *connectionFormatIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID); - am_Gateway_s gateway = gatewayData; - gateway.gatewayID = gatewayID; - if (mDatabaseObserver) - mDatabaseObserver->newGateway(gateway); - return E_OK; -} - -am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - assert(sourceData.sourceID=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX); - - sqlite3_stmt* query = NULL, *queryFinal = NULL; - ; - int eCode = 0; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - command = "UPDATE " + std::string(SOURCE_TABLE) + " SET name=?, domainID=?, sourceClassID=?, sourceState=?, volume=?, visible=?, availability=?, availabilityReason=?, interruptState=?, reserved=? WHERE sourceID=" + i2s(sqlite3_column_int(query, 0)); - } - else if (eCode == SQLITE_DONE) - { - //if sinkID is zero and the first Static Sink was already entered, the ID is created - if (sourceData.sourceID == 0 && !mFirstStaticSource && !existSourceName(sourceData.name)) - { - command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved) VALUES (?,?,?,?,?,?,?,?,?,?)"; - } - else - { - //check if the ID already exists - if (existSourceNameOrID(sourceData.sourceID, sourceData.name)) - { - sqlite3_finalize(query); - return E_ALREADY_EXISTS; - } - command = "INSERT INTO " + std::string(SOURCE_TABLE) + "(name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, reserved, sourceID) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; - } - } - else - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryFinal, NULL); - sqlite3_bind_text(queryFinal, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); - sqlite3_bind_int(queryFinal, 2, sourceData.domainID); - sqlite3_bind_int(queryFinal, 3, sourceData.sourceClassID); - sqlite3_bind_int(queryFinal, 4, sourceData.sourceState); - sqlite3_bind_int(queryFinal, 5, sourceData.volume); - sqlite3_bind_int(queryFinal, 6, sourceData.visible); - sqlite3_bind_int(queryFinal, 7, sourceData.available.availability); - sqlite3_bind_int(queryFinal, 8, sourceData.available.availabilityReason); - sqlite3_bind_int(queryFinal, 9, sourceData.interruptState); - sqlite3_bind_int(queryFinal, 10, 0); - - //if the ID is not created, we add it to the query - if (sourceData.sourceID != 0) - { - sqlite3_bind_int(queryFinal, 11, sourceData.sourceID); - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticSource) - { - sqlite3_bind_int(queryFinal, 11, DYNAMIC_ID_BOUNDARY); - mFirstStaticSource = false; - } - - if ((eCode = sqlite3_step(queryFinal)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - sqlite3_finalize(queryFinal); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(queryFinal)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSourceDB SQLITE Finalize error code:", eCode); - sqlite3_finalize(queryFinal); - return E_DATABASE_ERROR; - } - - //now read back the sinkID - command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceID = sqlite3_column_int(query, 0); - } - else - { - sourceID = 0; - logError("DatabaseHandler::existSink database error!:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_finalize(query); - - //now we need to create the additional tables: - command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)"); - assert(this->sqQuery(command)); - command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); - - //fill ConnectionFormats - command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin(); - for (; connectionFormatIterator < sourceData.listConnectionFormats.end(); ++connectionFormatIterator) - { - sqlite3_bind_int(query, 1, *connectionFormatIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - //Fill SinkSoundProperties - command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin(); - for (; SoundPropertyIterator < sourceData.listSoundProperties.end(); ++SoundPropertyIterator) - { - sqlite3_bind_int(query, 1, SoundPropertyIterator->type); - sqlite3_bind_int(query, 2, SoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if (sourceData.visible == true) - { - command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); - sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - } - - logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); - - am_Source_s source = sourceData; - source.sourceID = sourceID; - if (mDatabaseObserver) - mDatabaseObserver->newSource(source); - return E_OK; -} - -am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) -{ - assert(mainconnectionID!=0); - if (!existMainConnection(mainconnectionID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - int16_t delay = 0; - command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator elementIterator = listConnectionID.begin(); - for (; elementIterator < listConnectionID.end(); ++elementIterator) - { - sqlite3_bind_int(query, 1, *elementIterator); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - int16_t temp_delay = sqlite3_column_int(query, 1); - if (temp_delay != -1 && delay != -1) - delay += temp_delay; - else - delay = -1; - } - else - { - logError("DatabaseHandler::changeMainConnectionRouteDB did not find route for MainConnection:", eCode); - - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //now we delete the data in the table - command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID); - assert(this->sqQuery(command)); - - command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator listConnectionIterator(listConnectionID.begin()); - for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator) - { - sqlite3_bind_int(query, 1, *listConnectionIterator); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID); - return E_OK; -} - -am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) -{ - assert(mainconnectionID!=0); - assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existMainConnection(mainconnectionID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET connectionState=? WHERE mainConnectionID=" + i2s(mainconnectionID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, connectionState); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); - - if (mDatabaseObserver) - mDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SINK_TABLE) + " SET mainVolume=? WHERE sinkID=" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, mainVolume); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); - - if (mDatabaseObserver) - mDatabaseObserver->volumeChanged(sinkID, mainVolume); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); - assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SINK_TABLE) + " SET availability=?, availabilityReason=? WHERE sinkID=" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, availability.availability); - sqlite3_bind_int(query, 2, availability.availabilityReason); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - }assert(sinkID!=0); - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mDatabaseObserver && sourceVisible(sinkID)) - mDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); - return E_OK; -} - -am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) -{ - assert(domainID!=0); - assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(DOMAIN_TABLE) + " SET state=? WHERE domainID=" + i2s(domainID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, domainState); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changDomainStateDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SINK_TABLE) + " SET muteState=? WHERE sinkID=" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, muteState); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - }assert(sinkID!=0); - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); - - if (mDatabaseObserver) - mDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX); - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, soundProperty.value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - }assert(sinkID!=0); - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - if (mDatabaseObserver) - mDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); - return E_OK; -} - -am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - assert(soundProperty.type>=MSP_UNKNOWN && soundProperty.type<=MSP_MAX); - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE SourceMainSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, soundProperty.value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - - if (mDatabaseObserver) - mDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); - assert(availability.availabilityReason>=AR_UNKNOWN && availability.availabilityReason<=AR_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SOURCE_TABLE) + " SET availability=?, availabilityReason=? WHERE sourceID=" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, availability.availability); - sqlite3_bind_int(query, 2, availability.availabilityReason); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mDatabaseObserver && sourceVisible(sourceID)) - mDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property) -{ - assert(property.type>=SYP_UNKNOWN && property.type<=SYP_MAX); - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, property.value); - sqlite3_bind_int(query, 2, property.type); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSystemPropertyDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSystemPropertyDB changed system property"); - - if (mDatabaseObserver) - mDatabaseObserver->systemPropertyChanged(property); - - return E_OK; -} - -am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) -{ - assert(mainConnectionID!=0); - - if (!existMainConnection(mainConnectionID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); - std::string command1 = "DROP table MainConnectionRoute" + i2s(mainConnectionID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - if (!sqQuery(command1)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID); - if (mDatabaseObserver) - { - mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); - mDatabaseObserver->removedMainConnection(mainConnectionID); - } - return E_OK; -} - -am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - - bool visible=sinkVisible(sinkID); - - std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); - std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID); - std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID); - std::string command3 = "DROP table SinkSoundProperty" + i2s(sinkID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - if (!sqQuery(command1)) - return E_DATABASE_ERROR; - if (!sqQuery(command2)) - return E_DATABASE_ERROR; - if (!sqQuery(command3)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); - - if (mDatabaseObserver != NULL) - mDatabaseObserver->removedSink(sinkID,visible); - - return E_OK; -} - -am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - - bool visible=sourceVisible(sourceID); - - std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID); - std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID); - std::string command3 = "DROP table SourceSoundProperty" + i2s(sourceID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - if (!sqQuery(command1)) - return E_DATABASE_ERROR; - if (!sqQuery(command2)) - return E_DATABASE_ERROR; - if (!sqQuery(command3)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); - if (mDatabaseObserver) - mDatabaseObserver->removedSource(sourceID,visible); - return E_OK; -} - -am_Error_e DatabaseHandler::removeGatewayDB(const am_gatewayID_t gatewayID) -{ - assert(gatewayID!=0); - - if (!existGateway(gatewayID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID); - if (mDatabaseObserver) - mDatabaseObserver->removeGateway(gatewayID); - return E_OK; -} - -am_Error_e DatabaseHandler::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) -{ - assert(crossfaderID!=0); - - if (!existcrossFader(crossfaderID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeDomainDB removed:", crossfaderID); - if (mDatabaseObserver) - mDatabaseObserver->removeCrossfader(crossfaderID); - return E_OK; -} - -am_Error_e DatabaseHandler::removeDomainDB(const am_domainID_t domainID) -{ - assert(domainID!=0); - - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeDomainDB removed:", domainID); - if (mDatabaseObserver) - mDatabaseObserver->removeDomain(domainID); - return E_OK; -} - -am_Error_e DatabaseHandler::removeSinkClassDB(const am_sinkClass_t sinkClassID) -{ - assert(sinkClassID!=0); - - if (!existSinkClass(sinkClassID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID); - std::string command1 = "DROP table SinkClassProperties" + i2s(sinkClassID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - if (!sqQuery(command1)) - return E_DATABASE_ERROR; - - logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID); - if (mDatabaseObserver) - mDatabaseObserver->numberOfSinkClassesChanged(); - - return E_OK; -} - -am_Error_e DatabaseHandler::removeSourceClassDB(const am_sourceClass_t sourceClassID) -{ - assert(sourceClassID!=0); - - if (!existSourceClass(sourceClassID)) - { - return E_NON_EXISTENT; - } - std::string command = "DELETE from " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID); - std::string command1 = "DROP table SourceClassProperties" + i2s(sourceClassID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - if (!sqQuery(command1)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID); - if (mDatabaseObserver) - mDatabaseObserver->numberOfSourceClassesChanged(); - return E_OK; -} - -am_Error_e DatabaseHandler::removeConnection(const am_connectionID_t connectionID) -{ - assert(connectionID!=0); - - std::string command = "DELETE from " + std::string(CONNECTION_TABLE) + " WHERE connectionID=" + i2s(connectionID); - if (!sqQuery(command)) - return E_DATABASE_ERROR; - logInfo("DatabaseHandler::removeConnection removed:", connectionID); - return E_OK; -} - -am_Error_e DatabaseHandler::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_ClassProperty_s propertyTemp; - std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + (i2s(sourceID)); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - classInfo.sourceClassID = sqlite3_column_int(query, 0); - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID)); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - classInfo.name = std::string((const char*) sqlite3_column_text(query, 0)); - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - //read out Properties - command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0); - propertyTemp.value = sqlite3_column_int(query, 1); - classInfo.listClassProperties.push_back(propertyTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - return E_OK; -} - -am_Error_e DatabaseHandler::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const -{ - - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; - int eCode = 0; - am_ConnectionFormat_e tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 and sinkID=" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkData.name = std::string((const char*) sqlite3_column_text(query, 0)); - sinkData.domainID = sqlite3_column_int(query, 1); - sinkData.sinkClassID = sqlite3_column_int(query, 2); - sinkData.volume = sqlite3_column_int(query, 3); - sinkData.visible = sqlite3_column_int(query, 4); - sinkData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5); - sinkData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6); - sinkData.muteState = (am_MuteState_e) sqlite3_column_int(query, 7); - sinkData.mainVolume = sqlite3_column_int(query, 8); - sinkData.sinkID = sqlite3_column_int(query, 9); - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - sinkData.listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - sinkData.listSoundProperties.push_back(tempSoundProperty); - } - - if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - sinkData.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - } - - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; - int eCode = 0; - am_ConnectionFormat_e tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceData.name = std::string((const char*) sqlite3_column_text(query, 0)); - sourceData.domainID = sqlite3_column_int(query, 1); - sourceData.sourceClassID = sqlite3_column_int(query, 2); - sourceData.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3); - sourceData.volume = sqlite3_column_int(query, 4); - sourceData.visible = sqlite3_column_int(query, 5); - sourceData.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6); - sourceData.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7); - sourceData.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8); - sourceData.sourceID = sqlite3_column_int(query, 9); - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - sourceData.listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - sourceData.listSoundProperties.push_back(tempSoundProperty); - } - - if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - sourceData.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - } - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSourceInfoDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e am::DatabaseHandler::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const -{ - assert(mainConnectionID!=0); - if (!existMainConnection(mainConnectionID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt *query = NULL, *query1 = NULL; - int eCode = 0; - am_MainConnection_s temp; - std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); - std::string command1 = "SELECT connectionID FROM MainConnectionRoute"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - mainConnectionData.mainConnectionID = sqlite3_column_int(query, 0); - mainConnectionData.sourceID = sqlite3_column_int(query, 1); - mainConnectionData.sinkID = sqlite3_column_int(query, 2); - mainConnectionData.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); - mainConnectionData.delay = sqlite3_column_int(query, 4); - std::string statement = command1 + i2s(mainConnectionID); - sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL); - while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) - { - mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0)); - } - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getMainConnectionInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) -{ - assert(sinkClass.sinkClassID!=0); - assert(!sinkClass.listClassProperties.empty()); - - sqlite3_stmt* query = NULL; - int eCode = 0; - - //check if the ID already exists - if (!existSinkClass(sinkClass.sinkClassID)) - return E_NON_EXISTENT; - - //fill ConnectionFormats - std::string command = "UPDATE SinkClassProperties" + i2s(sinkClass.sinkClassID) + " set value=? WHERE classProperty=?;"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); - for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) - { - sqlite3_bind_int(query, 1, Iterator->value); - sqlite3_bind_int(query, 2, Iterator->classProperty); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) -{ - assert(sourceClass.sourceClassID!=0); - assert(!sourceClass.listClassProperties.empty()); - - sqlite3_stmt* query = NULL; - int eCode = 0; - - //check if the ID already exists - if (!existSourceClass(sourceClass.sourceClassID)) - return E_NON_EXISTENT; - - //fill ConnectionFormats - std::string command = "UPDATE SourceClassProperties" + i2s(sourceClass.sourceClassID) + " set value=? WHERE classProperty=?;"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator Iterator = sourceClass.listClassProperties.begin(); - for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) - { - sqlite3_bind_int(query, 1, Iterator->value); - sqlite3_bind_int(query, 2, Iterator->classProperty); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return E_OK; -} - -am_Error_e DatabaseHandler::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_ClassProperty_s propertyTemp; - std::string command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + (i2s(sinkID)); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkClass.sinkClassID = sqlite3_column_int(query, 0); - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID)); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkClass.name = std::string((const char*) sqlite3_column_text(query, 0)); - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - //read out Properties - command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(query, 0); - propertyTemp.value = sqlite3_column_int(query, 1); - sinkClass.listClassProperties.push_back(propertyTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkClassInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - return E_OK; -} - -am_Error_e DatabaseHandler::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const -{ - assert(gatewayID!=0); - if (!existGateway(gatewayID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; - int eCode = 0; - am_ConnectionFormat_e tempConnectionFormat; - std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - gatewayData.name = std::string((const char*) sqlite3_column_text(query, 0)); - gatewayData.sinkID = sqlite3_column_int(query, 1); - gatewayData.sourceID = sqlite3_column_int(query, 2); - gatewayData.domainSinkID = sqlite3_column_int(query, 3); - gatewayData.domainSourceID = sqlite3_column_int(query, 4); - gatewayData.controlDomainID = sqlite3_column_int(query, 5); - gatewayData.gatewayID = sqlite3_column_int(query, 6); - - //convertionMatrix: - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(gatewayData.gatewayID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getGatewayInfoDB database error with convertionFormat"); - return E_DATABASE_ERROR; - } - gatewayData.convertionMatrix = iter->second; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL); - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0); - gatewayData.listSourceFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL); - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0); - gatewayData.listSinkFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getGatewayInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; - -} - -am_Error_e DatabaseHandler::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const -{ - assert(crossfaderID!=0); - if (!existcrossFader(crossfaderID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfaderID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - crossfaderData.name = std::string((const char*) sqlite3_column_text(query, 0)); - crossfaderData.sinkID_A = sqlite3_column_int(query, 1); - crossfaderData.sinkID_B = sqlite3_column_int(query, 2); - crossfaderData.sourceID = sqlite3_column_int(query, 3); - crossfaderData.hotSink = static_cast(sqlite3_column_int(query, 4)); - crossfaderData.crossfaderID = sqlite3_column_int(query, 5); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getCrossfaderInfoDB SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getCrossfaderInfoDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const -{ - assert(domainID!=0); - listSinkID.clear(); - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_sinkID_t temp; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND domainID=" + (i2s(domainID)); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp = sqlite3_column_int(query, 0); - listSinkID.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinksOfDomain SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinksOfDomain SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const -{ - assert(domainID!=0); - listSourceID.clear(); - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_sourceID_t temp; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID); - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp = sqlite3_column_int(query, 0); - listSourceID.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourcesOfDomain SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSourcesOfDomain SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listCrossfader) const -{ - assert(domainID!=0); - listCrossfader.clear(); - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_crossfaderID_t temp; - - std::string command = "SELECT c.crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " c," + std::string(SOURCE_TABLE) + " s WHERE c.sourceID=s.sourceID AND s.domainID=" + i2s(domainID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp = sqlite3_column_int(query, 0); - listCrossfader.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListCrossfadersOfDomain SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; - -} - -am_Error_e DatabaseHandler::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const -{ - assert(domainID!=0); - listGatewaysID.clear(); - if (!existDomain(domainID)) - { - return E_NON_EXISTENT; - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_gatewayID_t temp; - - std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE controlDomainID=" + i2s(domainID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp = sqlite3_column_int(query, 0); - listGatewaysID.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListGatewaysOfDomain SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListGatewaysOfDomain SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListMainConnections(std::vector & listMainConnections) const -{ - listMainConnections.clear(); - sqlite3_stmt *query = NULL, *query1 = NULL; - int eCode = 0; - am_MainConnection_s temp; - std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE); - std::string command1 = "SELECT connectionID FROM MainConnectionRoute"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.mainConnectionID = sqlite3_column_int(query, 0); - temp.sourceID = sqlite3_column_int(query, 1); - temp.sinkID = sqlite3_column_int(query, 2); - temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); - temp.delay = sqlite3_column_int(query, 4); - std::string statement = command1 + i2s(temp.mainConnectionID); - sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL); - while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) - { - temp.listConnectionID.push_back(sqlite3_column_int(query1, 0)); - } - listMainConnections.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListMainConnections SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListDomains(std::vector & listDomains) const -{ - listDomains.clear(); - sqlite3_stmt* query = NULL; - int eCode = 0; - am_Domain_s temp; - std::string command = "SELECT domainID, name, busname, nodename, early, complete, state FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.domainID = sqlite3_column_int(query, 0); - temp.name = std::string((const char*) sqlite3_column_text(query, 1)); - temp.busname = std::string((const char*) sqlite3_column_text(query, 2)); - temp.nodename = std::string((const char*) sqlite3_column_text(query, 3)); - temp.early = sqlite3_column_int(query, 4); - temp.complete = sqlite3_column_int(query, 5); - temp.state = (am_DomainState_e) sqlite3_column_int(query, 6); - listDomains.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListDomains SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListDomains SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListConnections(std::vector & listConnections) const -{ - listConnections.clear(); - sqlite3_stmt* query = NULL; - int eCode = 0; - am_Connection_s temp; - std::string command = "SELECT connectionID, sourceID, sinkID, delay, connectionFormat FROM " + std::string(CONNECTION_TABLE) + " WHERE reserved=0"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.connectionID = sqlite3_column_int(query, 0); - temp.sourceID = sqlite3_column_int(query, 1); - temp.sinkID = sqlite3_column_int(query, 2); - temp.delay = sqlite3_column_int(query, 3); - temp.connectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(query, 4); - listConnections.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListConnections SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListConnections SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSinks(std::vector & listSinks) const -{ - listSinks.clear(); - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; - int eCode = 0; - am_Sink_s temp; - am_ConnectionFormat_e tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.name = std::string((const char*) sqlite3_column_text(query, 0)); - temp.domainID = sqlite3_column_int(query, 1); - temp.sinkClassID = sqlite3_column_int(query, 2); - temp.volume = sqlite3_column_int(query, 3); - temp.visible = sqlite3_column_int(query, 4); - temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 5); - temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 6); - temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7); - temp.mainVolume = sqlite3_column_int(query, 8); - temp.sinkID = sqlite3_column_int(query, 9); - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - temp.listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID); - sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - temp.listSoundProperties.push_back(tempSoundProperty); - } - - if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID); - sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - temp.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - listSinks.push_back(temp); - temp.listConnectionFormats.clear(); - temp.listMainSoundProperties.clear(); - temp.listSoundProperties.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinks SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSources(std::vector & listSources) const -{ - listSources.clear(); - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; - int eCode = 0; - am_Source_s temp; - am_ConnectionFormat_e tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.name = std::string((const char*) sqlite3_column_text(query, 0)); - temp.domainID = sqlite3_column_int(query, 1); - temp.sourceClassID = sqlite3_column_int(query, 2); - temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3); - temp.volume = sqlite3_column_int(query, 4); - temp.visible = sqlite3_column_int(query, 5); - temp.available.availability = (am_Availablility_e) sqlite3_column_int(query, 6); - temp.available.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 7); - temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8); - temp.sourceID = sqlite3_column_int(query, 9); - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - temp.listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID); - sqlite3_prepare_v2(mDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_SoundPropertyType_e) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - temp.listSoundProperties.push_back(tempSoundProperty); - } - - if ((eCode = sqlite3_finalize(qSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID); - sqlite3_prepare_v2(mDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL); - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_MainSoundPropertyType_e) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - temp.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - if ((eCode = sqlite3_finalize(qMAinSoundProperty)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - listSources.push_back(temp); - temp.listConnectionFormats.clear(); - temp.listMainSoundProperties.clear(); - temp.listSoundProperties.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSources SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSourceClasses(std::vector & listSourceClasses) const -{ - listSourceClasses.clear(); - - sqlite3_stmt* query = NULL, *subQuery = NULL; - int eCode = 0, eCode1; - am_SourceClass_s classTemp; - am_ClassProperty_s propertyTemp; - - std::string command = "SELECT sourceClassID, name FROM " + std::string(SOURCE_CLASS_TABLE); - std::string command2; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - classTemp.sourceClassID = sqlite3_column_int(query, 0); - classTemp.name = std::string((const char*) sqlite3_column_text(query, 1)); - - //read out Properties - command2 = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classTemp.sourceClassID); - sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL); - - while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0); - propertyTemp.value = sqlite3_column_int(subQuery, 1); - classTemp.listClassProperties.push_back(propertyTemp); - } - - if (eCode1 != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode1); - - return E_DATABASE_ERROR; - } - - if ((eCode1 = sqlite3_finalize(subQuery)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode1); - - return E_DATABASE_ERROR; - } - listSourceClasses.push_back(classTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListCrossfaders(std::vector & listCrossfaders) const -{ - listCrossfaders.clear(); - sqlite3_stmt* query = NULL; - int eCode = 0; - am_Crossfader_s tempData; - std::string command = "SELECT name, sinkID_A, sinkID_B, sourceID, hotSink,crossfaderID FROM " + std::string(CROSSFADER_TABLE); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - tempData.name = std::string((const char*) sqlite3_column_text(query, 0)); - tempData.sinkID_A = sqlite3_column_int(query, 1); - tempData.sinkID_B = sqlite3_column_int(query, 2); - tempData.sourceID = sqlite3_column_int(query, 3); - tempData.hotSink = static_cast(sqlite3_column_int(query, 4)); - tempData.crossfaderID = sqlite3_column_int(query, 5); - listCrossfaders.push_back(tempData); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListCrossfaders SQLITE error code:", eCode); - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListCrossfaders SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListGateways(std::vector & listGateways) const -{ - listGateways.clear(); - sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; - int eCode = 0; - am_Gateway_s temp; - am_ConnectionFormat_e tempConnectionFormat; - - std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.name = std::string((const char*) sqlite3_column_text(query, 0)); - temp.sinkID = sqlite3_column_int(query, 1); - temp.sourceID = sqlite3_column_int(query, 2); - temp.domainSinkID = sqlite3_column_int(query, 3); - temp.domainSourceID = sqlite3_column_int(query, 4); - temp.controlDomainID = sqlite3_column_int(query, 5); - temp.gatewayID = sqlite3_column_int(query, 6); - - //convertionMatrix: - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(temp.gatewayID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getListGateways database error with convertionFormat"); - - return E_DATABASE_ERROR; - } - temp.convertionMatrix = iter->second; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL); - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSourceConnectionFormat, 0); - temp.listSourceFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qSourceConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL); - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qSinkConnectionFormat, 0); - temp.listSinkFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qSinkConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - listGateways.push_back(temp); - temp.listSinkFormats.clear(); - temp.listSourceFormats.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListGateways SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListGateways SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSinkClasses(std::vector & listSinkClasses) const -{ - listSinkClasses.clear(); - - sqlite3_stmt* query = NULL, *subQuery = NULL; - int eCode = 0; - am_SinkClass_s classTemp; - am_ClassProperty_s propertyTemp; - - std::string command = "SELECT sinkClassID, name FROM " + std::string(SINK_CLASS_TABLE); - std::string command2; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - classTemp.sinkClassID = sqlite3_column_int(query, 0); - classTemp.name = std::string((const char*) sqlite3_column_text(query, 1)); - - //read out Properties - command2 = "SELECT classProperty, value FROM SinkClassProperties" + i2s(classTemp.sinkClassID); - sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &subQuery, NULL); - - while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_ClassProperty_e) sqlite3_column_int(subQuery, 0); - propertyTemp.value = sqlite3_column_int(subQuery, 1); - classTemp.listClassProperties.push_back(propertyTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(subQuery)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - listSinkClasses.push_back(classTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSourceClasses SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListVisibleMainConnections(std::vector & listConnections) const -{ - listConnections.clear(); - sqlite3_stmt *query = NULL; - int eCode = 0; - am_MainConnectionType_s temp; - - std::string command = "SELECT mainConnectionID, sourceID, sinkID, connectionState, delay FROM " + std::string(MAINCONNECTION_TABLE); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.mainConnectionID = sqlite3_column_int(query, 0); - temp.sourceID = sqlite3_column_int(query, 1); - temp.sinkID = sqlite3_column_int(query, 2); - temp.connectionState = (am_ConnectionState_e) sqlite3_column_int(query, 3); - temp.delay = sqlite3_column_int(query, 4); - listConnections.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListVisibleMainConnections SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListVisibleMainConnections SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListMainSinks(std::vector & listMainSinks) const -{ - listMainSinks.clear(); - sqlite3_stmt* query = NULL; - int eCode = 0; - am_SinkType_s temp; - - std::string command = "SELECT name, sinkID, availability, availabilityReason, muteState, mainVolume, sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE visible=1 AND reserved=0"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.name = std::string((const char*) sqlite3_column_text(query, 0)); - temp.sinkID = sqlite3_column_int(query, 1); - temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2); - temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3); - temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 4); - temp.volume = sqlite3_column_int(query, 5); - temp.sinkClassID = sqlite3_column_int(query, 6); - listMainSinks.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinks SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinks SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListMainSources(std::vector & listMainSources) const -{ - listMainSources.clear(); - sqlite3_stmt* query = NULL; - int eCode = 0; - am_SourceType_s temp; - std::string command = "SELECT name, sourceClassID, availability, availabilityReason, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE visible=1"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.name = std::string((const char*) sqlite3_column_text(query, 0)); - temp.sourceClassID = sqlite3_column_int(query, 1); - temp.availability.availability = (am_Availablility_e) sqlite3_column_int(query, 2); - temp.availability.availabilityReason = (am_AvailabilityReason_e) sqlite3_column_int(query, 3); - temp.sourceID = sqlite3_column_int(query, 4); - - listMainSources.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSources SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences - listSoundProperties.clear(); - - sqlite3_stmt* query = NULL; - int eCode = 0; - am_MainSoundProperty_s temp; - std::string command = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSoundProperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return E_DATABASE_ERROR; // todo: here we could change to non existen, but not shown in sequences - listSourceProperties.clear(); - - sqlite3_stmt* query = NULL; - int eCode = 0; - am_MainSoundProperty_s temp; - std::string command = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_MainSoundPropertyType_e) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSourceProperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getListSystemProperties(std::vector & listSystemProperties) const -{ - listSystemProperties.clear(); - - sqlite3_stmt* query = NULL; - int eCode = 0; - am_SystemProperty_s temp; - std::string command = "SELECT type, value FROM " + std::string(SYSTEM_TABLE); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_SystemPropertyType_e) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSystemProperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSystemProperties SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSystemProperties SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e am::DatabaseHandler::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const -{ - listConnectionFormats.clear(); - sqlite3_stmt *qConnectionFormat = NULL; - int eCode = 0; - am_ConnectionFormat_e tempConnectionFormat; - std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSinkConnectionFormats SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e am::DatabaseHandler::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const -{ - listConnectionFormats.clear(); - sqlite3_stmt* qConnectionFormat = NULL; - int eCode = 0; - am_ConnectionFormat_e tempConnectionFormat; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL); - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_ConnectionFormat_e) sqlite3_column_int(qConnectionFormat, 0); - listConnectionFormats.push_back(tempConnectionFormat); - } - - if ((eCode = sqlite3_finalize(qConnectionFormat)) != SQLITE_OK) - { - logError("DatabaseHandler::getListSources SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e am::DatabaseHandler::getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const -{ - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(gatewayID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getListGatewayConnectionFormats database error with convertionFormat"); - - return (E_DATABASE_ERROR); - } - listConnectionFormat = iter->second; - - return (E_OK); -} - -am_Error_e DatabaseHandler::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const -{ - assert(mainConnectionID!=0); - delay = -1; - sqlite3_stmt *query = NULL; - int eCode = 0; - - std::string command = "SELECT delay FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - delay = sqlite3_column_int(query, 0); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getTimingInformation SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getTimingInformation SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - if (delay == -1) - return E_NOT_POSSIBLE; - - return E_OK; -} - -bool DatabaseHandler::sqQuery(const std::string& query) -{ - sqlite3_stmt* statement; - int eCode = 0; - if ((eCode = sqlite3_exec(mDatabase, query.c_str(), NULL, &statement, NULL)) != SQLITE_OK) - { - logError("DatabaseHandler::sqQuery SQL Query failed:", query.c_str(), "error code:", eCode); - return false; - } - return true; -} - -bool DatabaseHandler::openDatabase() -{ - if (sqlite3_open_v2(mPath.c_str(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) - { - logInfo("DatabaseHandler::openDatabase opened database"); - return true; - } - logError("DatabaseHandler::openDatabase failed to open database"); - return false; -} - -am_Error_e DatabaseHandler::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) -{ - assert(connectionID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE delay=? AND mainConnectionID=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, delay); - sqlite3_bind_int(query, 2, connectionID); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - sqlite3_finalize(query); - return E_OK; - } - command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, delay); - sqlite3_bind_int(query, 2, connectionID); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeDelayMainConnection SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - if (mDatabaseObserver) - mDatabaseObserver->timingInformationChanged(connectionID, delay); - - return E_OK; -} - -am_Error_e DatabaseHandler::enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID) -{ - assert(connection.connectionID==0); - assert(connection.sinkID!=0); - assert(connection.sourceID!=0); - //connection format is not checked, because it's project specific - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "INSERT INTO " + std::string(CONNECTION_TABLE) + "(sinkID, sourceID, delay, connectionFormat, reserved) VALUES (?,?,?,?,?)"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, connection.sinkID); - sqlite3_bind_int(query, 2, connection.sourceID); - sqlite3_bind_int(query, 3, connection.delay); - sqlite3_bind_int(query, 4, connection.connectionFormat); - sqlite3_bind_int(query, 5, true); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - connectionID = sqlite3_last_insert_rowid(mDatabase); - - logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID); - return E_OK; -} - -am_Error_e DatabaseHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) -{ - assert(sinkClass.sinkClassIDsqQuery(command)); - - //fill ConnectionFormats - command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); - for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) - { - sqlite3_bind_int(query, 1, Iterator->classProperty); - sqlite3_bind_int(query, 2, Iterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSinkClassDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass"); - if (mDatabaseObserver) - mDatabaseObserver->numberOfSinkClassesChanged(); - return E_OK; -} - -am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) -{ - assert(sourceClass.sourceClassID::const_iterator Iterator = sourceClass.listClassProperties.begin(); - for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) - { - sqlite3_bind_int(query, 1, Iterator->classProperty); - sqlite3_bind_int(query, 2, Iterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSourceClassDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass"); - - if (mDatabaseObserver) - mDatabaseObserver->numberOfSourceClassesChanged(); - return E_OK; -} - -am_Error_e DatabaseHandler::enterSystemProperties(const std::vector & listSystemProperties) -{ - assert(!listSystemProperties.empty()); - sqlite3_stmt* query = NULL; - int eCode = 0; - std::vector::const_iterator listIterator = listSystemProperties.begin(); - std::string command = "DELETE * FROM " + std::string(SYSTEM_TABLE); - sqQuery(command); - - command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - for (; listIterator < listSystemProperties.end(); ++listIterator) - { - sqlite3_bind_int(query, 1, listIterator->type); - sqlite3_bind_int(query, 2, listIterator->value); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - sqlite3_reset(query); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::enterSystemProperties SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::enterSystemProperties entered system properties"); - return E_OK; -} - -bool DatabaseHandler::existMainConnection(const am_mainConnectionID_t mainConnectionID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE) + " WHERE mainConnectionID=" + i2s(mainConnectionID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSource(const am_sourceID_t sourceID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND sourceID=" + i2s(sourceID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSource database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND (name=? OR sourceID=?)"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - sqlite3_bind_int(query, 2, sourceID); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSource database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSourceName(const std::string & name) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 AND name=?"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSource database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSink(const am_sinkID_t sinkID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSink database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND (name=? OR sinkID=?)"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - sqlite3_bind_int(query, 2, sinkID); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSink database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSinkName(const std::string & name) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND name=?"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSink database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existDomain(const am_domainID_t domainID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE reserved=0 AND domainID=" + i2s(domainID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existDomain database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existGateway(const am_gatewayID_t gatewayID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existGateway database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -am_Error_e DatabaseHandler::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const -{ - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - std::string command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - int eCode = 0; - am_Error_e returnVal = E_DATABASE_ERROR; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - domainID = sqlite3_column_int(query, 0); - returnVal = E_OK; - } - else - { - logError("DatabaseHandler::getDomainOfSource database error!:", eCode); - } - sqlite3_finalize(query); - return (returnVal); -} - -am_Error_e am::DatabaseHandler::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - std::string command = "SELECT domainID FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); - int eCode = 0; - am_Error_e returnVal = E_DATABASE_ERROR; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - domainID = sqlite3_column_int(query, 0); - returnVal = E_OK; - } - else - { - logError("DatabaseHandler::getDomainOfSink database error!:", eCode); - } - sqlite3_finalize(query); - return (returnVal); -} - -bool DatabaseHandler::existSinkClass(const am_sinkClass_t sinkClassID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + i2s(sinkClassID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSinkClass database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existSourceClass(const am_sourceClass_t sourceClassID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + i2s(sourceClassID); - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSinkClass database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - assert(connectionID!=0); - - sqlite3_stmt *query = NULL, *queryMainConnections, *queryMainConnectionSubIDs; - int eCode = 0, eCode1 = 0; - std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, delay); - sqlite3_bind_int(query, 2, connectionID); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - //now we need to find all mainConnections that use the changed connection and update their timing - - int tempMainConnectionID; - //first get all route tables for all mainconnections - command = "SELECT name FROM sqlite_master WHERE type ='table' and name LIKE 'MainConnectionRoute%'"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryMainConnections, NULL); - - while ((eCode = sqlite3_step(queryMainConnections)) == SQLITE_ROW) - { - //now check if the connection ID is in this table - std::string tablename = std::string((const char*) sqlite3_column_text(queryMainConnections, 0)); - std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID); - sqlite3_prepare_v2(mDatabase, command2.c_str(), -1, &queryMainConnectionSubIDs, NULL); - if ((eCode1 = sqlite3_step(queryMainConnectionSubIDs)) == SQLITE_ROW) - { - //if the connection ID is in, recalculate the mainconnection delay - std::stringstream(tablename.substr(tablename.find_first_not_of("MainConnectionRoute"))) >> tempMainConnectionID; - changeDelayMainConnection(calculateMainConnectionDelay(tempMainConnectionID), tempMainConnectionID); - } - else if (eCode1 != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode1); - - return E_DATABASE_ERROR; - } - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(queryMainConnections)) != SQLITE_OK) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::changeConnectionFinal(const am_connectionID_t connectionID) -{ - assert(connectionID!=0); - - sqlite3_stmt *query = NULL; - int eCode = 0; - std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set reserved=0 WHERE connectionID=?"; - - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, connectionID); - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeConnectionFinal SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - return E_OK; -} - -am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const -{ - assert(mainConnectionID!=0); - sqlite3_stmt* query = NULL; - std::string command = "SELECT sum(Connections.delay),min(Connections.delay) FROM " + std::string(CONNECTION_TABLE) + ",MainConnectionRoute" + i2s(mainConnectionID) + " WHERE MainConnectionRoute" + i2s(mainConnectionID) + ".connectionID = Connections.connectionID"; - int eCode = 0; - am_timeSync_t delay = 0; - am_timeSync_t min = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - delay = sqlite3_column_int(query, 0); - min = sqlite3_column_int(query, 1); - } - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - if (min < 0) - delay = -1; - return delay; - -} - -void DatabaseHandler::registerObserver(DatabaseObserver *iObserver) -{ - assert(iObserver!=NULL); - mDatabaseObserver = iObserver; -} - -bool DatabaseHandler::sourceVisible(const am_sourceID_t sourceID) const -{ - assert(sourceID!=0); - sqlite3_stmt* query = NULL; - std::string command = "SELECT visible FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - int eCode = 0; - bool returnVal = false; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - returnVal = (bool) sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::sourceVisible database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::sinkVisible(const am_sinkID_t sinkID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT visible FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 AND sinkID=" + i2s(sinkID); - int eCode = 0; - bool returnVal = false; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - returnVal = sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::sinkVisible database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existConnection(const am_Connection_s connection) -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE sinkID=? AND sourceID=? AND connectionFormat=? AND reserved=0"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, connection.sinkID); - sqlite3_bind_int(query, 2, connection.sourceID); - sqlite3_bind_int(query, 3, connection.connectionFormat); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existConnectionID(const am_connectionID_t connectionID) -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT connectionID FROM " + std::string(CONNECTION_TABLE) + " WHERE connectionID=? AND reserved=0"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, connectionID); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -bool DatabaseHandler::existcrossFader(const am_crossfaderID_t crossfaderID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?"; - int eCode = 0; - bool returnVal = true; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, crossfaderID); - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - sqlite3_finalize(query); - return returnVal; -} - -am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const -{ - assert(sourceID!=0); - sqlite3_stmt* query = NULL; - sourceState = SS_UNKNNOWN; - std::string command = "SELECT sourceState FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - int eCode = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceState = (am_SourceState_e) sqlite3_column_int(query, 0); - } - else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - logError("DatabaseHandler::getSoureState database error!:", eCode); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) -{ - assert(sourceID!=0); - assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX); - sqlite3_stmt* query = NULL; - std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID); - int eCode = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, sourceState); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSourceState SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - return E_OK; -} - -am_Error_e DatabaseHandler::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const -{ - assert(sinkID!=0); - sqlite3_stmt* query = NULL; - volume = -1; - std::string command = "SELECT volume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); - int eCode = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - volume = sqlite3_column_int(query, 0); - } - else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - logError("DatabaseHandler::getSinkVolume database error!:", eCode); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const -{ - assert(sourceID!=0); - sqlite3_stmt* query = NULL; - volume = -1; - std::string command = "SELECT volume FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - int eCode = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - volume = sqlite3_column_int(query, 0); - } - else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - logError("DatabaseHandler::getSourceVolume database error!:", eCode); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_SoundPropertyType_e propertyType, uint16_t & value) const -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT value FROM SinkSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - value = sqlite3_column_int(query, 0); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_SoundPropertyType_e propertyType, uint16_t & value) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return E_DATABASE_ERROR; // todo: here we could change to non existent, but not shown in sequences - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT value FROM SourceSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - value = sqlite3_column_int(query, 0); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - return E_OK; -} - -am_Error_e DatabaseHandler::getDomainState(const am_domainID_t domainID, am_DomainState_e state) const -{ - assert(domainID!=0); - sqlite3_stmt* query = NULL; - state = DS_UNKNOWN; - std::string command = "SELECT domainState FROM " + std::string(DOMAIN_TABLE) + " WHERE domainID=" + i2s(domainID); - int eCode = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - state = (am_DomainState_e) sqlite3_column_int(query, 0); - } - else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - logError("DatabaseHandler::getDomainState database error!:", eCode); - } - sqlite3_finalize(query); - return E_OK; - -} - -am_Error_e DatabaseHandler::peekDomain(const std::string & name, am_domainID_t & domainID) -{ - sqlite3_stmt* query = NULL, *queryInsert = NULL; - std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; - int eCode = 0, eCode1 = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - domainID = sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::peekDomain database error!:", eCode); - return E_DATABASE_ERROR; - } - else - { - command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); - sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); - sqlite3_bind_int(queryInsert, 2, 1); //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1); - return E_DATABASE_ERROR; - } - - if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) - { - logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); - return E_DATABASE_ERROR; - } - domainID = sqlite3_last_insert_rowid(mDatabase); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::peekSink(const std::string & name, am_sinkID_t & sinkID) -{ - sqlite3_stmt* query = NULL, *queryInsert = NULL; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?"; - int eCode = 0, eCode1 = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkID = sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink database error!:", eCode); - return E_DATABASE_ERROR; - } - else - { - if (mFirstStaticSink) - { - command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved,sinkID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")"; - mFirstStaticSink = false; - } - else - { - command = "INSERT INTO " + std::string(SINK_TABLE) + " (name,reserved) VALUES (?,?)"; - } - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); - sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); - sqlite3_bind_int(queryInsert, 2, 1); //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); - return E_DATABASE_ERROR; - } - - if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) - { - logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); - return E_DATABASE_ERROR; - } - sinkID = sqlite3_last_insert_rowid(mDatabase); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::peekSource(const std::string & name, am_sourceID_t & sourceID) -{ - sqlite3_stmt* query = NULL, *queryInsert = NULL; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?"; - int eCode = 0, eCode1 = 0; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceID = sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink database error!:", eCode); - return E_DATABASE_ERROR; - } - else - { - if (mFirstStaticSource) - { - command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved,sourceID) VALUES (?,?," + i2s(DYNAMIC_ID_BOUNDARY) + ")"; - mFirstStaticSource = false; - } - else - { - command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (name,reserved) VALUES (?,?)"; - } - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &queryInsert, NULL); - sqlite3_bind_text(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC); - sqlite3_bind_int(queryInsert, 2, 1); //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); - return E_DATABASE_ERROR; - } - - if ((eCode1 = sqlite3_finalize(queryInsert)) != SQLITE_OK) - { - logError("DatabaseHandler::peekDomain SQLITE Finalize error code:", eCode1); - return E_DATABASE_ERROR; - } - sourceID = sqlite3_last_insert_rowid(mDatabase); - } - sqlite3_finalize(query); - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SINK_TABLE) + " SET volume=? WHERE sinkID=" + i2s(sinkID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, volume); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSinkVolume SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) -{ - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(SOURCE_TABLE) + " SET volume=? WHERE sourceID=" + i2s(sourceID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, volume); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSourceVolume SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX); - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE SourceSoundProperty" + i2s(sourceID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, soundProperty.value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - assert(soundProperty.type>=SP_UNKNOWN && soundProperty.type<=SP_MAX); - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, soundProperty.value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode); - return E_DATABASE_ERROR; - }assert(sinkID!=0); - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Finalize error code:", eCode); - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - - return E_OK; -} - -am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) -{ - assert(crossfaderID!=0); - assert(hotsink>=HS_UNKNOWN && hotsink>=HS_MAX); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existcrossFader(crossfaderID)) - { - return E_NON_EXISTENT; - } - command = "UPDATE " + std::string(CROSSFADER_TABLE) + " SET hotsink=? WHERE crossfaderID=" + i2s(crossfaderID); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, hotsink); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode); - - return E_DATABASE_ERROR; - } - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Finalize error code:", eCode); - - return E_DATABASE_ERROR; - } - - logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink); - return E_OK; -} - -am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std::vector& flatTree) -{ - sqlite3_stmt* query = NULL; - int eCode = 0; - size_t i = 0; - std::string command; - am_domainID_t rootID = tree.returnRootDomainID(); - RoutingTreeItem *parent = tree.returnRootItem(); - - if (onlyfree) - { - command = "SELECT g.domainSourceID,g.gatewayID FROM " + std::string(GATEWAY_TABLE) + " g WHERE domainSinkID=? AND NOT EXISTS (SELECT NULL FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = g.sinkID OR c.sourceID = g.sourceID )"; - } - else - { - command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?"; - } - - do - { - if (i != 0) - { - parent = flatTree.at(i - 1); - rootID = parent->returnDomainID(); - } - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_int(query, 1, rootID); - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - flatTree.push_back(tree.insertItem(sqlite3_column_int(query, 0), sqlite3_column_int(query, 1), parent)); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode); - - return (E_DATABASE_ERROR); - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::getRoutingTree SQLITE Finalize error code:", eCode); - - return (E_DATABASE_ERROR); - } - i++; - } while (flatTree.size() > (i - 1)); - - return (E_OK); -} - -am_Error_e am::DatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID) -{ - if (name.empty()) - return E_NON_EXISTENT; - - am_Error_e returnVal = E_NON_EXISTENT; - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkClassID = sqlite3_column_int(query, 0); - returnVal = E_OK; - } - else if (eCode != SQLITE_DONE) - { - sinkClassID = 0; - logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode); - returnVal = E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::peekSinkClassID SQLITE Finalize error code:", eCode); - returnVal = E_DATABASE_ERROR; - } - return returnVal; -} - -am_Error_e am::DatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID) -{ - if (name.empty()) - return E_NON_EXISTENT; - - am_Error_e returnVal = E_NON_EXISTENT; - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?"; - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceClassID = sqlite3_column_int(query, 0); - returnVal = E_OK; - } - else if (eCode != SQLITE_DONE) - { - sourceClassID = 0; - logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode); - returnVal = E_DATABASE_ERROR; - } - - if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) - { - logError("DatabaseHandler::peekSourceClassID SQLITE Finalize error code:", eCode); - returnVal = E_DATABASE_ERROR; - } - return returnVal; -} - -void DatabaseHandler::createTables() -{ - for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++) - { - assert(sqQuery("CREATE TABLE " + databaseTables[i])); - } -} - diff --git a/AudioManagerDaemon/src/DatabaseObserver.cpp b/AudioManagerDaemon/src/DatabaseObserver.cpp deleted file mode 100644 index 93031ef..0000000 --- a/AudioManagerDaemon/src/DatabaseObserver.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DatabaseObserver.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 statiasyncCally or dynamiasyncCally 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 "DatabaseObserver.h" -#include -#include -#include -#include -#include -#include "CommandSender.h" -#include "RoutingSender.h" -#include "TelnetServer.h" -#include "DLTWrapper.h" -//#include "CAmSerializer.h" - -using namespace am; - -DatabaseObserver::DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler) : - mCommandSender(iCommandSender), // - mRoutingSender(iRoutingSender), // - mSerializer(iSocketHandler) // -{ - assert(mCommandSender!=0); - assert(mRoutingSender!=0); - assert(iSocketHandler!=0); -} - -DatabaseObserver::DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler, TelnetServer *iTelnetServer) : - mCommandSender(iCommandSender), // - mRoutingSender(iRoutingSender), // - mTelnetServer(iTelnetServer), // - mSerializer(iSocketHandler) // -{ - assert(mTelnetServer!=0); - assert(mCommandSender!=0); - assert(mRoutingSender!=0); - assert(iSocketHandler!=0); -} - -DatabaseObserver::~DatabaseObserver() -{ -} - -void DatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbNewMainConnection, mainConnection); -} - -void DatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbRemovedMainConnection, mainConnection); -} - -void DatabaseObserver::newSink(const am_Sink_s& sink) -{ - mRoutingSender->addSinkLookup(sink); - if (sink.visible) - { - am_SinkType_s s; - s.availability = sink.available; - s.muteState = sink.muteState; - s.name = sink.name; - s.sinkClassID = sink.sinkClassID; - s.sinkID = sink.sinkID; - s.volume = sink.mainVolume; - mSerializer.asyncCall(mCommandSender, &CommandSender::cbNewSink, s); - } -} - -void DatabaseObserver::newSource(const am_Source_s& source) -{ - mRoutingSender->addSourceLookup(source); - if (source.visible) - { - am_SourceType_s s; - s.availability = source.available; - s.name = source.name; - s.sourceClassID = source.sourceClassID; - s.sourceID = source.sourceID; - mSerializer.asyncCall(mCommandSender, &CommandSender::cbNewSource, s); - } -} - -void DatabaseObserver::newDomain(const am_Domain_s& domain) -{ - mRoutingSender->addDomainLookup(domain); -} - -void DatabaseObserver::newGateway(const am_Gateway_s& gateway) -{ - (void) gateway; - //todo: implement something -} - -void DatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) -{ - mRoutingSender->addCrossfaderLookup(crossfader); -} - -void DatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) -{ - mRoutingSender->removeSinkLookup(sinkID); - - if (visible) - mSerializer.asyncCall(mCommandSender, &CommandSender::cbRemovedSink, sinkID); -} - -void DatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) -{ - mRoutingSender->removeSourceLookup(sourceID); - - if (visible) - mSerializer.asyncCall(mCommandSender, &CommandSender::cbRemovedSource, sourceID); -} - -void DatabaseObserver::removeDomain(const am_domainID_t domainID) -{ - mRoutingSender->removeDomainLookup(domainID); -} - -void DatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) -{ - (void) gatewayID; - //todo: implement something? -} - -void DatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) -{ - mRoutingSender->removeCrossfaderLookup(crossfaderID); -} - -void DatabaseObserver::numberOfSinkClassesChanged() -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbNumberOfSinkClassesChanged); -} - -void DatabaseObserver::numberOfSourceClassesChanged() -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbNumberOfSourceClassesChanged); -} - -void DatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbMainConnectionStateChanged, connectionID, connectionState); -} - -void DatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbMainSinkSoundPropertyChanged, sinkID, SoundProperty); -} - -void DatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbMainSourceSoundPropertyChanged, sourceID, SoundProperty); -} - -void DatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbSinkAvailabilityChanged, sinkID, availability); -} - -void DatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbSourceAvailabilityChanged, sourceID, availability); -} - -void DatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbVolumeChanged, sinkID, volume); -} - -void DatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbSinkMuteStateChanged, sinkID, muteState); -} - -void DatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbSystemPropertyChanged, SystemProperty); -} - -void DatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) -{ - mSerializer.asyncCall(mCommandSender, &CommandSender::cbTimingInformationChanged, mainConnection, time); -} diff --git a/AudioManagerDaemon/src/Router.cpp b/AudioManagerDaemon/src/Router.cpp deleted file mode 100644 index c74989a..0000000 --- a/AudioManagerDaemon/src/Router.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file Router.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "Router.h" -#include "DatabaseHandler.h" -#include "ControlSender.h" -#include -#include -#include -#include - -using namespace am; - -Router::Router(DatabaseHandler* iDatabaseHandler, ControlSender* iSender) : - mDatabaseHandler(iDatabaseHandler), // - mControlSender(iSender) -{ - assert(mDatabaseHandler); - assert(mControlSender); -} - -am_Error_e Router::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) -{ - returnList.clear(); - //first find out in which domains the source and sink are - am_domainID_t sourceDomainID; - am_domainID_t sinkDomainID; - if (mDatabaseHandler->getDomainOfSource(sourceID, sourceDomainID) != E_OK) - return (E_NON_EXISTENT); - if (mDatabaseHandler->getDomainOfSink(sinkID, sinkDomainID) != E_OK) - return (E_NON_EXISTENT); - - if (sourceDomainID == sinkDomainID) //shortcut if the domains are the same... - { - //first get the list of possible connection formats - std::vector listFormats, listPriorityConnectionFormats; - listPossibleConnectionFormats(sourceID, sinkID, listFormats); - - //dummy route - am_Route_s route; - route.sinkID = sinkID; - route.sourceID = sourceID; - route.route.clear(); - - //get the prio of the Controller: - mControlSender->getConnectionFormatChoice(sourceID, sinkID, route, listFormats, listPriorityConnectionFormats); - - //no possible connection, so no route ! But we report OK since there is no fault ... - if (listPriorityConnectionFormats.empty()) - return E_OK; - - //return the first item as route: - am_RoutingElement_s routingElement; - routingElement.sourceID = sourceID; - routingElement.sinkID = sinkID; - routingElement.connectionFormat = listPriorityConnectionFormats[0]; - routingElement.domainID = sourceDomainID; - - //Now get a route: - am_Route_s actualRoute; - actualRoute.route.push_back(routingElement); - actualRoute.sourceID = sourceID; - actualRoute.sinkID = sinkID; - - //push it to the return list - we are done here ... - returnList.push_back(actualRoute); - return E_OK; - - } - RoutingTree routingtree(sourceDomainID); //Build up a Tree from the Source_Domain to every other domain. - std::vector flattree; //This list is the flat tree - std::vector matchtree; - std::vector listGatewayID; //holds all gateway ids of the route - am_RoutingElement_s routingElement; - am_Route_s actualRoute; //holds the actual Route - am_sourceID_t lastSource = 0; - - mDatabaseHandler->getRoutingTree(onlyfree, routingtree, flattree); //Build up the tree out of the database as - - //we go through the returned flattree and look for our sink, after that flattree holds only treeItems that match - std::vector::iterator iterator = flattree.begin(); - for (; iterator != flattree.end(); ++iterator) - { - if ((*iterator)->returnDomainID() == sinkDomainID) - { - matchtree.push_back(*iterator); - } - } - - //No we need to trace back the routes for each entry in matchtree - iterator = matchtree.begin(); - for (; iterator != matchtree.end(); ++iterator) - { - std::vector actualRoutingElement; //intermediate list of current routing pairs - //getting the route for the actual item - routingtree.getRoute(*iterator, listGatewayID); //This gives only the Gateway IDs we need more - - //go throught the gatewayids and get more information - std::vector::iterator gatewayIterator = listGatewayID.begin(); - for (; gatewayIterator != listGatewayID.end(); ++gatewayIterator) - { - am_Gateway_s gatewayData; - if (mDatabaseHandler->getGatewayInfoDB(*gatewayIterator, gatewayData) != E_OK) - return (E_UNKNOWN); - - //at the beginning of the route, we connect first the source to the first gateway - if (gatewayIterator == listGatewayID.begin()) - { - routingElement.sourceID = sourceID; - routingElement.domainID = sourceDomainID; - } - else - { - routingElement.sourceID = lastSource; - routingElement.domainID = gatewayData.domainSinkID; - } - routingElement.sinkID = gatewayData.sinkID; - actualRoutingElement.push_back(routingElement); - lastSource = gatewayData.sourceID; - } - //at the end of the route, connect to the sink ! - routingElement.sourceID = lastSource; - routingElement.sinkID = sinkID; - routingElement.domainID = sinkDomainID; - actualRoutingElement.push_back(routingElement); - - //So now we got the route, what is missing are the connectionFormats... - - //Step through the routes and try to use always the best connectionFormat - std::vector::iterator routingInterator = actualRoutingElement.begin(); - gatewayIterator = listGatewayID.begin(); - if (findBestWay(sinkID, sourceID, actualRoutingElement, routingInterator, gatewayIterator) != E_OK) - { - continue; - } - - //add the route to the list of routes... - actualRoute.sourceID = sourceID; - actualRoute.sinkID = sinkID; - actualRoute.route = actualRoutingElement; - returnList.push_back(actualRoute); - } - return (E_OK); -} - -void Router::listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& listFormats) const -{ - std::vector listSourceFormats; - std::vector listSinkFormats; - mDatabaseHandler->getListSinkConnectionFormats(sinkID, listSinkFormats); - mDatabaseHandler->getListSourceConnectionFormats(sourceID, listSourceFormats); - std::sort(listSinkFormats.begin(), listSinkFormats.end()); //todo: this might be not needed if we use strictly sorted input - std::sort(listSourceFormats.begin(), listSourceFormats.end()); //todo: this might be not needed if we use strictly sorted input - std::insert_iterator > inserter(listFormats, listFormats.begin()); - set_intersection(listSourceFormats.begin(), listSourceFormats.end(), listSinkFormats.begin(), listSinkFormats.end(), inserter); -} - -am_Error_e Router::findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector & listRoute, std::vector::iterator routeIterator, std::vector::iterator gatewayIterator) -{ - am_Error_e returnError = E_NOT_POSSIBLE; - std::vector listConnectionFormats; - std::vector listMergeConnectionFormats; - std::vector listPriorityConnectionFormats; - std::vector::iterator nextIterator = routeIterator + 1; - //get best connection format - listPossibleConnectionFormats(routeIterator->sourceID, routeIterator->sinkID, listConnectionFormats); - - //if we have not just started, we need to take care about the gateways... - if (routeIterator != listRoute.begin()) - { - //since we have to deal with Gateways, there are restrictions what connectionFormat we can take. So we need to take the subset of connections that are restricted: - std::vector listRestrictedConnectionFormats; - std::insert_iterator > inserter(listMergeConnectionFormats, listMergeConnectionFormats.begin()); - std::vector::iterator tempIterator(routeIterator); - tempIterator--; - listRestrictedOutputFormatsGateways(*gatewayIterator, (tempIterator)->connectionFormat, listRestrictedConnectionFormats); - std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input - set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter); - gatewayIterator++; - } - else - { - listMergeConnectionFormats = listConnectionFormats; - } - - am_Route_s route; - route.sinkID = sinkID; - route.sourceID = sourceID; - route.route = listRoute; - - //let the controller decide: - mControlSender->getConnectionFormatChoice(routeIterator->sourceID, routeIterator->sinkID, route, listMergeConnectionFormats, listPriorityConnectionFormats); - - //we have the list sorted after prios - now we try one after the other with the next part of the route - std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); - - //here we need to check if we are at the end and stop - if (nextIterator == listRoute.end()) - { - if (!listPriorityConnectionFormats.empty()) - { - routeIterator->connectionFormat = listPriorityConnectionFormats.front(); - return E_OK; - } - else - return E_NOT_POSSIBLE; - } - - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) - { - routeIterator->connectionFormat = *connectionFormatIterator; - if ((returnError = findBestWay(sinkID, sourceID, listRoute, nextIterator, gatewayIterator)) == E_OK) - { - break; - } - } - - return (returnError); -} - -void Router::listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_ConnectionFormat_e sinkConnectionFormat, std::vector & listFormats) const -{ - listFormats.clear(); - am_Gateway_s gatewayData; - mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData); - std::vector::const_iterator rowSinkIterator = gatewayData.listSinkFormats.begin(); - std::vector::const_iterator matrixIterator = gatewayData.convertionMatrix.begin(); - - //find the row number of the sink - rowSinkIterator = find(gatewayData.listSinkFormats.begin(), gatewayData.listSinkFormats.end(), sinkConnectionFormat); - int rowNumberSink = rowSinkIterator - gatewayData.listSinkFormats.begin(); - - //go through the convertionMatrix and find out if the conversion is possible, if yes, add connectionFormat ... - std::advance(matrixIterator, rowNumberSink); - - //iterate line-wise through the matrix and add more formats - do - { - if (*matrixIterator) - { - listFormats.push_back(gatewayData.listSourceFormats.at((matrixIterator - gatewayData.convertionMatrix.begin()) / gatewayData.listSinkFormats.size())); - } - std::advance(matrixIterator, gatewayData.listSinkFormats.size()); - } while (gatewayData.convertionMatrix.end() - matrixIterator > 0); -} - -Router::~Router() -{ -} - -RoutingTreeItem::RoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, RoutingTreeItem *parent) : - mDomainID(domainID), // - mGatewayID(gatewayID), // - mParentItem(parent) -{ - assert(mDomainID!=0); -} - -void RoutingTreeItem::appendChild(RoutingTreeItem *newChild) -{ - assert(newChild); - mListChildItems.push_back(newChild); -} - -void RoutingTreeItem::returnChildItems(std::vector listChildItems) -{ - listChildItems = mListChildItems; -} - -am_domainID_t RoutingTreeItem::returnDomainID() const -{ - return (mDomainID); -} - -am_gatewayID_t RoutingTreeItem::returnGatewayID() const -{ - return (mGatewayID); -} - -RoutingTreeItem* RoutingTreeItem::returnParent() const -{ - return (mParentItem); -} - -RoutingTreeItem::~RoutingTreeItem() -{ -} - -RoutingTree::RoutingTree(const am_domainID_t rootDomainID) : - mRootItem(RoutingTreeItem(rootDomainID)) -{ - assert(rootDomainID!=0); -} - -RoutingTreeItem *RoutingTree::insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, RoutingTreeItem *parent) -{ - RoutingTreeItem *newTree = new RoutingTreeItem(domainID, gatewayID, parent); - parent->appendChild(newTree); - mListChild.push_back(newTree); - return newTree; -} - -void RoutingTree::getRoute(RoutingTreeItem *targetItem, std::vector& listGateways) -{ - listGateways.clear(); - RoutingTreeItem *parentItem = targetItem; - while (parentItem != &mRootItem) - { - listGateways.push_back(parentItem->returnGatewayID()); - parentItem = parentItem->returnParent(); - } - std::reverse(listGateways.begin(), listGateways.end()); -} - -am_domainID_t RoutingTree::returnRootDomainID() const -{ - return (mRootItem.returnDomainID()); -} - -RoutingTreeItem *RoutingTree::returnRootItem() -{ - return (&mRootItem); -} - -RoutingTree::~RoutingTree() -{ - std::vector::iterator it = mListChild.begin(); - for (; it != mListChild.end(); ++it) - { - delete *it; - } -} - diff --git a/AudioManagerDaemon/src/RoutingReceiver.cpp b/AudioManagerDaemon/src/RoutingReceiver.cpp deleted file mode 100644 index 715fa36..0000000 --- a/AudioManagerDaemon/src/RoutingReceiver.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingReceiver.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (christian.ei.mueller@bmw.de) - * - * \section LicenseRoutingReceiver.h - * - * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause) - * Copyright (C) 2011, BMW AG Christian Mueller 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 . - * 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 "RoutingReceiver.h" -#include "DatabaseHandler.h" -#include "RoutingSender.h" -#include "ControlSender.h" -#include "DLTWrapper.h" -#include -#include -#include - - -using namespace am; - -RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler) : - mDatabaseHandler(iDatabaseHandler), // - mRoutingSender(iRoutingSender), // - mControlSender(iControlSender), // - mSocketHandler(iSocketHandler), // - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false) -{ - assert(mDatabaseHandler!=NULL); - assert(mRoutingSender!=NULL); - assert(mControlSender!=NULL); - assert(mSocketHandler!=NULL); -} - -RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler, DBusWrapper *iDBusWrapper) : - mDatabaseHandler(iDatabaseHandler), // - mRoutingSender(iRoutingSender), // - mControlSender(iControlSender), // - mSocketHandler(iSocketHandler), // - mDBusWrapper(iDBusWrapper), // - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false) -{ - assert(mDatabaseHandler!=NULL); - assert(mRoutingSender!=NULL); - assert(mControlSender!=NULL); - assert(mSocketHandler!=NULL); - assert(mDBusWrapper!=NULL); -} - -RoutingReceiver::~RoutingReceiver() -{ -} - -void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - mRoutingSender->removeHandle(handle); - if (error == E_OK) - { - mDatabaseHandler->changeConnectionFinal(connectionID); - } - else - { - mDatabaseHandler->removeConnection(connectionID); - } - mControlSender->cbAckConnect(handle, error); -} - -void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - mRoutingSender->removeHandle(handle); - if (error == E_OK) - { - mDatabaseHandler->removeConnection(connectionID); - } - mControlSender->cbAckDisconnect(handle, error); -} - -void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sinkID != 0) - { - //todo: check if volume in handleData is same than volume. React to it. - mDatabaseHandler->changeSinkVolume(handleData.sinkID, volume); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSinkVolumeChange(handle, volume, error); -} - -void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sourceID != 0) - { - //todo: check if volume in handleData is same than volume. React to it. - mDatabaseHandler->changeSourceVolume(handleData.sourceID, volume); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSourceVolumeChange(handle, volume, error); -} - -void RoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sourceID != 0) - { - //todo: check if volume in handleData is same than volume. React to it. - mDatabaseHandler->changeSourceState(handleData.sourceID, handleData.sourceState); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSourceState(handle, error); -} - -void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sinkID != 0) - { - mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery, handleData.sinkID); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSinkSoundProperty(handle, error); - -} - -void am::RoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sinkID != 0) - { - std::vector::const_iterator it = handleData.soundProperties->begin(); - for (; it != handleData.soundProperties->end(); ++it) - { - mDatabaseHandler->changeSinkSoundPropertyDB(*it, handleData.sinkID); - } - delete handleData.soundProperties; - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSinkSoundProperties(handle, error); -} - -void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sourceID != 0) - { - mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery, handleData.sourceID); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSourceSoundProperty(handle, error); -} - -void am::RoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.sourceID != 0) - { - std::vector::const_iterator it = handleData.soundProperties->begin(); - for (; it != handleData.soundProperties->end(); ++it) - { - mDatabaseHandler->changeSourceSoundPropertyDB(*it, handleData.sourceID); - } - delete handleData.soundProperties; - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckSetSourceSoundProperties(handle, error); -} - -void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) -{ - RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle); - if (error == E_OK && handleData.crossfaderID != 0) - { - //todo: check if volume in handleData is same than volume. React to it. - mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID, hotSink); - } - mRoutingSender->removeHandle(handle); - mControlSender->cbAckCrossFade(handle, hotSink, error); -} - -void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - mControlSender->hookSystemSourceVolumeTick(handle, sourceID, volume); -} - -void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - mControlSender->hookSystemSinkVolumeTick(handle, sinkID, volume); -} - -am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID) -{ - return mDatabaseHandler->peekDomain(name, domainID); - -} - -am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - return mControlSender->hookSystemRegisterDomain(domainData, domainID); -} - -am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID) -{ - return mControlSender->hookSystemDeregisterDomain(domainID); -} - -am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - return mControlSender->hookSystemRegisterGateway(gatewayData, gatewayID); -} - -am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID) -{ - return mControlSender->hookSystemDeregisterGateway(gatewayID); -} - -am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID) -{ - return mDatabaseHandler->peekSink(name, sinkID); -} - -am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - return mControlSender->hookSystemRegisterSink(sinkData, sinkID); -} - -am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID) -{ - return mControlSender->hookSystemDeregisterSink(sinkID); -} - -am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID) -{ - return mDatabaseHandler->peekSource(name, sourceID); -} - -am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - return mControlSender->hookSystemRegisterSource(sourceData, sourceID); -} - -am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID) -{ - return mControlSender->hookSystemDeregisterSource(sourceID); -} - -am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - return mControlSender->hookSystemRegisterCrossfader(crossfaderData, crossfaderID); -} - -am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID) -{ - return mControlSender->hookSystemDeregisterCrossfader(crossfaderID); -} - -void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - return mControlSender->hookSystemInterruptStateChange(sourceID, interruptState); -} - -void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID) -{ - mControlSender->hookSystemDomainRegistrationComplete(domainID); -} - -void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mControlSender->hookSystemSinkAvailablityStateChange(sinkID, availability); -} - -void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mControlSender->hookSystemSourceAvailablityStateChange(sourceID, availability); -} - -void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - mControlSender->hookSystemDomainStateChange(domainID, domainState); -} - -void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - mDatabaseHandler->changeConnectionTimingInformation(connectionID, delay); -} - -void RoutingReceiver::sendChangedData(const std::vector & earlyData) -{ - mControlSender->hookSystemReceiveEarlyData(earlyData); -} - -am_Error_e RoutingReceiver::peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) -{ - return mDatabaseHandler->peekSinkClassID(name, sinkClassID); -} - -am_Error_e RoutingReceiver::peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) -{ - return mDatabaseHandler->peekSourceClassID(name, sourceClassID); -} - -am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *& dbusConnectionWrapper) const -{ -#ifdef WITH_DBUS_WRAPPER - dbusConnectionWrapper = mDBusWrapper; - return E_OK; -#else - return E_UNKNOWN; -#endif -} - -am_Error_e RoutingReceiver::getSocketHandler(SocketHandler *& socketHandler) const -{ - socketHandler = mSocketHandler; - return E_OK; -} - -void RoutingReceiver::getInterfaceVersion(std::string & version) const -{ - version = RoutingReceiveVersion; -} - -void RoutingReceiver::confirmRoutingReady(const uint16_t handle) -{ - mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); - if (mWaitStartup && mListStartupHandles.empty()) - mControlSender->confirmRoutingReady(); -} - -void RoutingReceiver::confirmRoutingRundown(const uint16_t handle) -{ - mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); - if (mWaitRundown && mListRundownHandles.empty()) - mControlSender->confirmCommandRundown(); -} - -uint16_t am::RoutingReceiver::getStartupHandle() -{ - uint16_t handle = ++handleCount; //todo: handle overflow - mListStartupHandles.push_back(handle); - return handle; -} - -uint16_t am::RoutingReceiver::getRundownHandle() -{ - uint16_t handle = ++handleCount; //todo: handle overflow - mListRundownHandles.push_back(handle); - return handle; -} - -void am::RoutingReceiver::waitOnStartup(bool startup) -{ - mWaitStartup = startup; -} - -void am::RoutingReceiver::waitOnRundown(bool rundown) -{ - mWaitRundown = rundown; -} - diff --git a/AudioManagerDaemon/src/RoutingSender.cpp b/AudioManagerDaemon/src/RoutingSender.cpp deleted file mode 100644 index c59641d..0000000 --- a/AudioManagerDaemon/src/RoutingSender.cpp +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "RoutingSender.h" -#include -#include -#include -#include -#include -#include - -#include "RoutingReceiver.h" -#include "PluginTemplate.h" -#include "DLTWrapper.h" - -using namespace am; - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 -#define REQUIRED_INTERFACE_VERSION_MINOR 0 - -#define CALL_ALL_INTERFACES(...) \ - std::vector::iterator iter = mListInterfaces.begin(); \ - std::vector::iterator iterEnd = mListInterfaces.end(); \ - for (; iter__VA_ARGS__; \ - } - -RoutingSender::RoutingSender(const std::vector& listOfPluginDirectories) : - mHandleCount(0), // - mlistActiveHandles(), // - mListInterfaces(), // - mMapConnectionInterface(), // - mMapCrossfaderInterface(), // - mMapDomainInterface(), // - mMapSinkInterface(), // - mMapSourceInterface(), // - mMapHandleInterface(), // - mRoutingReceiver() -{ - std::vector sharedLibraryNameList; - std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); - std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); - - // search communicator plugins in configured directories - for (; dirIter < dirIterEnd; ++dirIter) - { - const char* directoryName = dirIter->c_str(); - logInfo("Searching for HookPlugins in", directoryName); - DIR *directory = opendir(directoryName); - - if (!directory) - { - logError("RoutingSender::RoutingSender Error opening directory: ", directoryName); - continue; - } - - // iterate content of directory - struct dirent *itemInDirectory = 0; - while ((itemInDirectory = readdir(directory))) - { - unsigned char entryType = itemInDirectory->d_type; - std::string entryName = itemInDirectory->d_name; - - bool regularFile = (entryType == DT_REG || entryType == DT_LNK); - bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); - - if (regularFile && sharedLibExtension) - { - logInfo("RoutingSender::RoutingSender adding file: ", entryName); - std::string name(directoryName); - sharedLibraryNameList.push_back(name + "/" + entryName); - } - else - { - logInfo("RoutingSender::RoutingSender PluginSearch ignoring file :", entryName); - } - } - - closedir(directory); - } - - // iterate all communicator plugins and start them - std::vector::iterator iter = sharedLibraryNameList.begin(); - std::vector::iterator iterEnd = sharedLibraryNameList.end(); - - for (; iter != iterEnd; ++iter) - { - logInfo("RoutingSender::RoutingSender try loading: ", *iter); - - RoutingSendInterface* (*createFunc)(); - void* tempLibHandle = NULL; - createFunc = getCreateFunction(*iter, tempLibHandle); - - if (!createFunc) - { - logError("RoutingSender::RoutingSender Entry point of RoutingPlugin not found"); - continue; - } - - RoutingSendInterface* router = createFunc(); - - if (!router) - { - logError("RoutingSender::RoutingSender RoutingPlugin initialization failed. Entry Function not callable"); - continue; - } - - InterfaceNamePairs routerInterface; - routerInterface.routingInterface = router; - - //check libversion - std::string version; - router->getInterfaceVersion(version); - uint16_t minorVersion, majorVersion; - std::istringstream(version.substr(0, 1)) >> majorVersion; - std::istringstream(version.substr(2, 1)) >> minorVersion; - if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) - { - logInfo("RoutingPlugin initialization failed. Version of Interface to old"); - continue; - } - - //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain.... - router->returnBusName(routerInterface.busName); - assert(!routerInterface.busName.empty()); - mListInterfaces.push_back(routerInterface); - mListLibraryHandles.push_back(tempLibHandle); - } -} - -RoutingSender::~RoutingSender() -{ - unloadLibraries(); - HandlesMap::iterator it = mlistActiveHandles.begin(); - - //clean up heap if existent - for (; it != mlistActiveHandles.end(); ++it) - { - if (it->first.handleType == H_SETSINKSOUNDPROPERTIES || it->first.handleType == H_SETSOURCESOUNDPROPERTIES) - { - delete it->second.soundProperties; - } - } -} - -am_Error_e RoutingSender::startupInterfaces(RoutingReceiver *iRoutingReceiver) -{ - mRoutingReceiver = iRoutingReceiver; - am_Error_e returnError = E_OK; - - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - am_Error_e error = (*iter).routingInterface->startupInterface(iRoutingReceiver); - if (error != E_OK) - { - returnError = error; - } - } - return returnError; -} - -am_Error_e RoutingSender::asyncAbort(const am_Handle_s& handle) -{ - HandleInterfaceMap::iterator iter = mMapHandleInterface.begin(); - iter = mMapHandleInterface.find(handle.handle); - if (iter != mMapHandleInterface.end()) - { - return iter->second->asyncAbort(handle); - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) -{ - am_handleData_c handleData; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - { - handleData.connectionID = connectionID; - handle = createHandle(handleData, H_CONNECT); - mMapConnectionInterface.insert(std::make_pair(connectionID, iter->second)); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncConnect(handle, connectionID, sourceID, sinkID, connectionFormat); - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID) -{ - am_handleData_c handleData; - ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin(); - mMapConnectionInterface.find(connectionID); - if (iter != mMapConnectionInterface.end()) - { - handleData.connectionID = connectionID; - handle = createHandle(handleData, H_DISCONNECT); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - am_Error_e returnVal = iter->second->asyncDisconnect(handle, connectionID); - mMapConnectionInterface.erase(iter); - return returnVal; - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - am_handleData_c handleData; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - handleData.sinkID = sinkID; - handleData.volume = volume; - handle = createHandle(handleData, H_SETSINKVOLUME); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSinkVolume(handle, sinkID, volume, ramp, time); - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - am_handleData_c handleData; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - handleData.sourceID = sourceID; - handleData.volume = volume; - handle = createHandle(handleData, H_SETSOURCEVOLUME); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSourceVolume(handle, sourceID, volume, ramp, time); - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state) -{ - am_handleData_c handleData; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - handleData.sourceID = sourceID; - handleData.sourceState = state; - handle = createHandle(handleData, H_SETSOURCESTATE); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSourceState(handle, sourceID, state); - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) -{ - am_handleData_c handleData; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - handleData.sinkID = sinkID; - handleData.soundPropery = soundProperty; - handle = createHandle(handleData, H_SETSINKSOUNDPROPERTY); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSinkSoundProperty(handle, sinkID, soundProperty); - return (E_NON_EXISTENT); -} - -am_Error_e RoutingSender::asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) -{ - am_handleData_c handleData; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - handleData.sourceID = sourceID; - handleData.soundPropery = soundProperty; - handle = createHandle(handleData, H_SETSOURCESOUNDPROPERTY); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSourceSoundProperty(handle, sourceID, soundProperty); - return (E_NON_EXISTENT); -} - -am_Error_e RoutingSender::asyncSetSourceSoundProperties(am_Handle_s& handle, const std::vector & listSoundProperties, const am_sourceID_t sourceID) -{ - am_handleData_c handleData; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - handleData.sourceID = sourceID; - handleData.soundProperties = new std::vector(listSoundProperties); - handle = createHandle(handleData, H_SETSOURCESOUNDPROPERTIES); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSourceSoundProperties(handle, sourceID, listSoundProperties); - return (E_NON_EXISTENT); -} - -am_Error_e RoutingSender::asyncSetSinkSoundProperties(am_Handle_s& handle, const std::vector & listSoundProperties, const am_sinkID_t sinkID) -{ - am_handleData_c handleData; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - handleData.sinkID = sinkID; - handleData.soundProperties = new std::vector(listSoundProperties); - handle = createHandle(handleData, H_SETSINKSOUNDPROPERTIES); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncSetSinkSoundProperties(handle, sinkID, listSoundProperties); - return (E_NON_EXISTENT); - -} - -am_Error_e RoutingSender::asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) -{ - am_handleData_c handleData; - CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin(); - iter = mMapCrossfaderInterface.find(crossfaderID); - if (iter != mMapCrossfaderInterface.end()) - handleData.crossfaderID = crossfaderID; - handleData.hotSink = hotSink; - handle = createHandle(handleData, H_CROSSFADE); - mMapHandleInterface.insert(std::make_pair(handle.handle, iter->second)); - return iter->second->asyncCrossFade(handle, crossfaderID, hotSink, rampType, time); - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); - iter = mMapDomainInterface.find(domainID); - if (iter != mMapDomainInterface.end()) - return iter->second->setDomainState(domainID, domainState); - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::addDomainLookup(const am_Domain_s& domainData) -{ - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - if ((*iter).busName.compare(domainData.busname) == 0) - { - mMapDomainInterface.insert(std::make_pair(domainData.domainID, (*iter).routingInterface)); - return E_OK; - } - } - - return E_UNKNOWN; -} - -am_Error_e RoutingSender::addSourceLookup(const am_Source_s& sourceData) -{ - DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); - iter = mMapDomainInterface.find(sourceData.domainID); - if (iter != mMapDomainInterface.end()) - { - mMapSourceInterface.insert(std::make_pair(sourceData.sourceID, iter->second)); - return E_OK; - } - - return E_UNKNOWN; -} - -am_Error_e RoutingSender::addSinkLookup(const am_Sink_s& sinkData) -{ - DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); - iter = mMapDomainInterface.find(sinkData.domainID); - if (iter != mMapDomainInterface.end()) - { - mMapSinkInterface.insert(std::make_pair(sinkData.sinkID, iter->second)); - return E_OK; - } - - return E_UNKNOWN; -} - -am_Error_e RoutingSender::addCrossfaderLookup(const am_Crossfader_s& crossfaderData) -{ - DomainInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(crossfaderData.sourceID); - if (iter != mMapSourceInterface.end()) - { - mMapSourceInterface.insert(std::make_pair(crossfaderData.crossfaderID, iter->second)); - return E_OK; - } - - return E_UNKNOWN; -} - -am_Error_e RoutingSender::removeDomainLookup(const am_domainID_t domainID) -{ - DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); - iter = mMapDomainInterface.find(domainID); - if (iter != mMapDomainInterface.end()) - { - mMapDomainInterface.erase(iter); - return E_OK; - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::removeSourceLookup(const am_sourceID_t sourceID) -{ - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - { - mMapSourceInterface.erase(iter); - return E_OK; - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::removeSinkLookup(const am_sinkID_t sinkID) -{ - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - { - mMapSinkInterface.erase(iter); - return E_OK; - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::removeCrossfaderLookup(const am_crossfaderID_t crossfaderID) -{ - CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin(); - iter = mMapCrossfaderInterface.find(crossfaderID); - if (iter != mMapCrossfaderInterface.end()) - { - mMapCrossfaderInterface.erase(iter); - return E_OK; - } - - return E_NON_EXISTENT; -} - -am_Error_e RoutingSender::removeHandle(const am_Handle_s& handle) -{ - if (mlistActiveHandles.erase(handle)) - return E_OK; - return E_UNKNOWN; -} - -am_Error_e RoutingSender::getListHandles(std::vector & listHandles) const -{ - listHandles.clear(); - HandlesMap::const_iterator it = mlistActiveHandles.begin(); - for (; it != mlistActiveHandles.end(); ++it) - { - listHandles.push_back(it->first); - } - return E_OK; -} - -am_Handle_s RoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type) -{ - am_Handle_s handle; - handle.handle = ++mHandleCount; //todo: handle overflows here... - handle.handleType = type; - mlistActiveHandles.insert(std::make_pair(handle, handleData)); - return handle; -} - -RoutingSender::am_handleData_c RoutingSender::returnHandleData(const am_Handle_s handle) const -{ - HandlesMap::const_iterator it = mlistActiveHandles.begin(); - it = mlistActiveHandles.find(handle); - return (it->second); -} - -void RoutingSender::setRoutingReady() -{ - mRoutingReceiver->waitOnStartup(false); - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - (*iter).routingInterface->setRoutingReady(mRoutingReceiver->getStartupHandle()); - } - mRoutingReceiver->waitOnStartup(true); -} - -void RoutingSender::setRoutingRundown() -{ - mRoutingReceiver->waitOnRundown(false); - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - (*iter).routingInterface->setRoutingRundown(mRoutingReceiver->getStartupHandle()); - } - mRoutingReceiver->waitOnRundown(true); -} - -void RoutingSender::unloadLibraries(void) -{ - std::vector::iterator iterator = mListLibraryHandles.begin(); - for (; iterator < mListLibraryHandles.end(); ++iterator) - { - dlclose(*iterator); - } - mListLibraryHandles.clear(); -} - -am_Error_e RoutingSender::getListPlugins(std::vector& interfaces) const -{ - std::vector::const_iterator it = mListInterfaces.begin(); - for (; it != mListInterfaces.end(); ++it) - { - interfaces.push_back(it->busName); - } - return E_OK; -} - -void RoutingSender::getInterfaceVersion(std::string & version) const -{ - version = RoutingSendVersion; -} - diff --git a/AudioManagerDaemon/src/SocketHandler.cpp b/AudioManagerDaemon/src/SocketHandler.cpp deleted file mode 100644 index 444289f..0000000 --- a/AudioManagerDaemon/src/SocketHandler.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DBusWrapper.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "SocketHandler.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "DLTWrapper.h" - -//todo: implement time correction if timer was interrupted by call -//todo: change hitlist to a list that holds all information, because entering and removing items will be cheaper than with std::vector - -using namespace am; - -SocketHandler::SocketHandler() : - mListPoll(), // - mListTimer(), // - mListActiveTimer(), // - mNextTimer(), // - mLastInsertedHandle(0), // - mLastInsertedPollHandle(0), // - mRecreatePollfds(true), // - mTimeout() -{ - mTimeout.tv_nsec = -1; - mTimeout.tv_sec = -1; - gDispatchDone = 0; -} - -SocketHandler::~SocketHandler() -{ -} - -//todo: maybe have some: give me more time returned? -/** - * start the block listening for filedescriptors. This is the mainloop. - */ -void SocketHandler::start_listenting() -{ - gDispatchDone=0; - int16_t pollStatus; - std::list hitList; - - //init the timer - initTimer(); - - //prepare the signalmask - sigset_t sigmask; - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGINT); - sigaddset(&sigmask, SIGQUIT); - sigaddset(&sigmask, SIGTERM); - sigaddset(&sigmask, SIGHUP); - sigaddset(&sigmask, SIGQUIT); - - while (!gDispatchDone) - { - //first we go through the registered filedescriptors and check if someone needs preparation: - mListPoll_t::iterator prepIter = mListPoll.begin(); - shPollPrepare *prep = NULL; - for (; prepIter != mListPoll.end(); ++prepIter) - { - if ((prep = prepIter->prepareCB) != NULL) - prep->Call(prepIter->handle, prepIter->userData); - } - - if (mRecreatePollfds) - { - mfdPollingArray.clear(); - //there was a change in the setup, so we need to recreate the fdarray from the list - std::for_each(mListPoll.begin(), mListPoll.end(), CopyPollfd(mfdPollingArray)); - mRecreatePollfds = false; - } - - //block until something is on a filedescriptor -#ifdef WITH_PPOLL - - timespec buffertime; - if ((pollStatus = ppoll(&mfdPollingArray[0], mfdPollingArray.size(), insertTime(buffertime), &sigmask)) < 0) - { - if (errno == EINTR) - { - //a signal was received, that means it's time to go... - pollStatus = 0; - } - else - { - logError("SocketHandler::start_listenting ppoll returned with error", errno); - exit(0); - } - } - -#else - //sigprocmask (SIG_SETMASK, &mask, &oldmask); - if((pollStatus=poll(&mfdPollingArray[0],mfdPollingArray.size(),timespec2ms(mTimeout)))<0) - { - - if(errno==EINTR) - { - //a signal was received, that means it's time to go... - //todo: add things to do here before going to sleep - exit(0); - } - logError("SocketHandler::start_listenting poll returned with error",errno); - exit(0); - } - //sigprocmask (SIG_SETMASK, &oldmask, NULL); -#endif - - if (pollStatus != 0) //only check filedescriptors if there was a change - { - //todo: here could be a timer that makes sure naughty plugins return! - - //freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines - mListPoll_t listPoll(mListPoll); - - //get all indexes of the fired events and save them int hitList - hitList.clear(); - std::vector::iterator it = mfdPollingArray.begin(); - do - { - it = std::find_if(it, mfdPollingArray.end(), onlyFiredEvents); - if (it != mfdPollingArray.end()) - hitList.push_back(std::distance(mfdPollingArray.begin(), it++)); - - } while (it != mfdPollingArray.end()); - - //stage 1, call firedCB for all matched events, but only if callback is not zero! - std::list::iterator hListIt = hitList.begin(); - for (; hListIt != hitList.end(); ++hListIt) - { - shPollFired* fire = NULL; - if ((fire = listPoll.at(*hListIt).firedCB) != NULL) - fire->Call(mfdPollingArray.at(*hListIt), listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData); - } - - //stage 2, lets ask around if some dispatching is necessary, if not, they are taken from the hitlist - hListIt = hitList.begin(); - for (; hListIt != hitList.end(); ++hListIt) - { - shPollCheck* check = NULL; - if ((check = listPoll.at(*hListIt).checkCB) != NULL) - { - if (!check->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) - { - hListIt = hitList.erase(hListIt); - } - } - } - - //stage 3, the ones left need to dispatch, we do this as long as there is something to dispatch.. - do - { - hListIt = hitList.begin(); - for (; hListIt != hitList.end(); ++hListIt) - { - shPollDispatch *dispatch = NULL; - if ((dispatch = listPoll.at(*hListIt).dispatchCB) != NULL) - { - if (!dispatch->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) - { - hListIt = hitList.erase(hListIt); - } - } - else //there is no dispatch function, so we just remove the file from the list... - { - hListIt = hitList.erase(hListIt); - } - } - } while (!hitList.empty()); - - } - else //Timerevent - { - //this was a timer event, we need to take care about the timers - timerUp(); - } - } -} - -/** - * exits the loop - */ -void SocketHandler::stop_listening() -{ - gDispatchDone = 1; -} - -/** - * Adds a filedescriptor to the polling loop - * @param fd this is a valid filedescriptor - * @param event the event flags - * @param callback the callback that shall be called if the filedescriptor poll succeeded - * @return E_OK if the descriptor was added, E_NON_EXISTENT if the fd is not valid - */ - -am_Error_e SocketHandler::addFDPoll(const int fd, const short event, shPollPrepare *prepare, shPollFired *fired, shPollCheck *check, shPollDispatch *dispatch, void *userData, sh_pollHandle_t & handle) -{ - if (!fdIsValid(fd)) - return E_NON_EXISTENT; - - sh_poll_s pollData; - pollData.pollfdValue.fd = fd; - pollData.handle = ++mLastInsertedPollHandle; - pollData.pollfdValue.events = event; - pollData.pollfdValue.revents = 0; - pollData.userData = userData; - pollData.prepareCB = prepare; - pollData.firedCB = fired; - pollData.checkCB = check; - pollData.dispatchCB = dispatch; - - //add new data to the list - mListPoll.push_back(pollData); - - mRecreatePollfds = true; - - handle = pollData.handle; - return E_OK; -} - -/** - * removes a filedescriptor from the poll loop - * @param fd the filedescriptor to be removed - * @return E_OK in case of sucess, E_NON_EXISTENT or E_UNKNOWN if the fd in not registered - */ -am_Error_e SocketHandler::removeFDPoll(const sh_pollHandle_t handle) -{ - mListPoll_t::iterator iterator = mListPoll.begin(); - - for (; iterator != mListPoll.end(); ++iterator) - { - if (iterator->handle == handle) - { - iterator = mListPoll.erase(iterator); - mRecreatePollfds = true; - return E_OK; - } - } - return E_UNKNOWN; -} - -/** - * adds a timer to the list of timers. The callback will be fired when the timer is up. - * This is not a high precise timer, it is very coarse. It is meant to be used for timeouts when waiting - * for an answer via a filedescriptor. - * One time timer. If you need again a timer, you need to add a new timer in the callback of the old one. - * @param timeouts time until the callback is fired - * @param callback the callback - * @param handle the handle that is created for the timer is returned. Can be used to remove the timer - * @return E_OK in case of success - */ -am_Error_e SocketHandler::addTimer(const timespec timeouts, shTimerCallBack*& callback, sh_timerHandle_t& handle, void * userData) -{ - assert(!((timeouts.tv_sec==0) && (timeouts.tv_nsec==0))); - assert(callback!=NULL); - - timer_s timerItem; - - //create a new handle for the timer - handle = ++mLastInsertedHandle; //todo: overflow ruling ! - timerItem.handle = handle; - timerItem.countdown = timeouts; - timerItem.timeout = timeouts; - timerItem.callback = callback; - timerItem.userData = userData; - - //add timer to the list - mListActiveTimer.push_back(timerItem); - mListTimer.push_back(timerItem); - - //very important: sort the list so that the smallest value is front - mListActiveTimer.sort(compareCountdown); - mTimeout = mListActiveTimer.front().countdown; - return E_OK; -} - -/** - * removes a timer from the list of timers - * @param handle the handle to the timer - * @return E_OK in case of success, E_UNKNOWN if timer was not found. - */ -am_Error_e SocketHandler::removeTimer(const sh_timerHandle_t handle) -{ - assert(handle!=0); - - //stop the current timer - stopTimer(handle); - - std::list::iterator it = mListTimer.begin(); - for (; it != mListTimer.end(); ++it) - { - if (it->handle == handle) - { - it = mListTimer.erase(it); - return E_OK; - } - } - return E_UNKNOWN; -} - -/** - * restarts a timer and updates with a new interval - * @param handle handle to the timer - * @param timeouts new timout time - * @return E_OK on success, E_NON_EXISTENT if the handle was not found - */ -am_Error_e SocketHandler::restartTimer(const sh_timerHandle_t handle, const timespec timeouts) -{ - timer_s timerItem; - std::list::iterator it = mListTimer.begin(); - for (; it != mListTimer.end(); ++it) - { - if (it->handle == handle) - { - timerItem = *it; - break; - } - } - - if (timeouts.tv_nsec != -1 && timeouts.tv_sec != -1) - { - timerItem.timeout = timeouts; - } - - mListActiveTimer.push_back(timerItem); - - //very important: sort the list so that the smallest value is front - mListActiveTimer.sort(compareCountdown); - mTimeout = mListActiveTimer.front().countdown; - return E_OK; -} - -am_Error_e SocketHandler::stopTimer(const sh_timerHandle_t handle) -{ - //go through the list and remove the timer with the handle - std::list::iterator it = mListActiveTimer.begin(); - for (; it != mListActiveTimer.end(); ++it) - { - if (it->handle == handle) - { - it = mListActiveTimer.erase(it); - if (!mListActiveTimer.empty()) - { - mTimeout = mListActiveTimer.front().countdown; - } - else - { - mTimeout.tv_nsec = -1; - mTimeout.tv_sec = -1; - } - return E_OK; - } - } - return E_NON_EXISTENT; -} - -/** - * updates the eventFlags of a poll - * @param fd the filedescriptor of the poll - * @param event the event flags - * @return E_OK on succsess, E_NON_EXISTENT if fd was not found - */ -am_Error_e SocketHandler::updateEventFlags(const sh_pollHandle_t handle, const short events) -{ - mListPoll_t::iterator iterator = mListPoll.begin(); - - for (; iterator != mListPoll.end(); ++iterator) - { - if (iterator->handle == handle) - { - iterator->pollfdValue.events = events; - mRecreatePollfds = true; - return E_OK; - } - } - return E_UNKNOWN; -} - -/** - * checks if a filedescriptor is valid - * @param fd the filedescriptor - * @return true if the fd is valid - */ -bool SocketHandler::fdIsValid(const int fd) const -{ - return (fcntl(fd, F_GETFL) != -1 || errno != EBADF); -} - -/** - * whenever a timer is up, this function needs to be called. - * Removes the fired timer, calls the callback and resets mTimeout - */ -void SocketHandler::timerUp() -{ - //first fire the event - mListActiveTimer.front().callback->Call(mListActiveTimer.front().handle, mListActiveTimer.front().userData); - - //then remove the first timer, the one who fired - mListActiveTimer.pop_front(); - if (!mListActiveTimer.empty()) - { - //substract the old value from all timers in the list - std::for_each(mListActiveTimer.begin(), mListActiveTimer.end(), SubstractTime(mTimeout)); - mTimeout = mListActiveTimer.front().countdown; - } - else - { - mTimeout.tv_nsec = -1; - mTimeout.tv_sec = -1; - } -} - -/** - * init the timers - */ -void SocketHandler::initTimer() -{ - if (!mListActiveTimer.empty()) - { - mTimeout = mListActiveTimer.front().countdown; - } - else - { - mTimeout.tv_nsec = -1; - mTimeout.tv_sec = -1; - } -} - -/** - * convert timespec to milliseconds - * @param time time in timespec - * @return time in milliseconds - */ -inline int SocketHandler::timespec2ms(const timespec & time) -{ - return (time.tv_nsec == -1 && time.tv_sec == -1) ? -1 : time.tv_sec * 1000 + time.tv_nsec / 1000000; -} - -inline timespec* am::SocketHandler::insertTime(timespec& buffertime) -{ - buffertime.tv_nsec = mTimeout.tv_nsec; - buffertime.tv_sec = mTimeout.tv_sec; - return (mTimeout.tv_nsec == -1 && mTimeout.tv_sec == -1) ? NULL : &buffertime; -} - -/** - * functor to easy substract from each countdown - * @param t value to substract from - */ -void SocketHandler::SubstractTime::operator ()(timer_s & t) const -{ - int val = 0; - if ((val = t.countdown.tv_nsec - param.tv_nsec) < 0) - { - t.countdown.tv_nsec = 1000000000 + val; - t.countdown.tv_sec--; - } - else - { - t.countdown.tv_nsec = val; - } - (t.countdown.tv_sec - param.tv_sec) < 0 ? 0 : (t.countdown.tv_sec -= param.tv_sec); -} - -void SocketHandler::CopyPollfd::operator ()(const sh_poll_s & row) -{ - pollfd temp = row.pollfdValue; - temp.revents = 0; - mArray.push_back(temp); -} - diff --git a/AudioManagerDaemon/src/TelnetServer.cpp b/AudioManagerDaemon/src/TelnetServer.cpp deleted file mode 100644 index 1cae985..0000000 --- a/AudioManagerDaemon/src/TelnetServer.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file TelnetServer.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "TelnetServer.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "DatabaseHandler.h" -#include "RoutingSender.h" -#include "DLTWrapper.h" -#include "CAmTelnetMenuHelper.h" - -using namespace am; - -TelnetServer* TelnetServer::instance = NULL; - -#define PRINT_BOOL(var) var ? output+="true\t\t" : output+="false\t\t"; - -TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, unsigned int servPort, unsigned int maxConnections) - :telnetConnectFiredCB(this,&TelnetServer::connectSocket), - telnetReceiveFiredCB(this,&TelnetServer::receiveData), - telnetDispatchCB(this,&TelnetServer::dispatchData), - telnetCheckCB(this,&TelnetServer::check), - mSocketHandler(iSocketHandler), - mCommandSender(iCommandSender), - mCommandReceiver(iCommandReceiver), - mRoutingSender(iRoutingSender), - mRoutingReceiver(iRoutingReceiver), - mControlSender(iControlSender), - mControlReceiver(iControlReceiver), - mDatabasehandler(iDatabasehandler), - mRouter(iRouter), - mConnecthandle(), - mMsgList(), - mListConnections(), - mConnectFD(NULL), - mServerPort(servPort), - mMaxConnections(maxConnections), - mTelnetMenuHelper(iSocketHandler,iCommandSender,iCommandReceiver,iRoutingSender,iRoutingReceiver,iControlSender,iControlReceiver,iDatabasehandler,iRouter,this) -{ - assert(mSocketHandler!=NULL); - assert(mCommandReceiver!=NULL); - assert(mCommandSender!=NULL); - assert(mControlSender!=NULL); - assert(mControlReceiver!=NULL); - assert(mRoutingSender!=NULL); - assert(mRoutingReceiver!=NULL); - assert(mDatabasehandler!=NULL); - assert(mRouter!=NULL); - assert(servPort!=0); - assert(mMaxConnections!=0); - - instance = this; - //mTelnetMenuHelper.setTelnetServer(this); - - int yes = 1; - struct sockaddr_in servAddr; - - //setup the port Listener - mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = INADDR_ANY; - servAddr.sin_port = htons(servPort); - bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr)); - - if (listen(mConnectFD,mMaxConnections) < 0) - { - logError("TelnetServer::TelnetServerk cannot listen ",errno); - } - else - logInfo("TelnetServer::TelnetServer started listening on port", mServerPort); - - int a=1; - ioctl (mConnectFD, FIONBIO, (char *) &a); - setsockopt (mConnectFD, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof (a)); - - short events = 0; - events |= POLLIN; - mSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle); -} - -TelnetServer::~TelnetServer() -{ -} - -void TelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //first, accept the connection, create a new filedescriptor - struct sockaddr answer; - socklen_t len=sizeof(answer); - connection_s connection; - connection.handle = 0; - connection.filedescriptor = accept(pfd.fd, (struct sockaddr*)&answer, &len); - - // Notiy menuhelper - mTelnetMenuHelper.newSocketConnection(connection.filedescriptor); - - //set the correct event: - short event = 0; - event |=POLLIN; - - //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data - mSocketHandler->addFDPoll(connection.filedescriptor,event,NULL,&telnetReceiveFiredCB,&telnetCheckCB,&telnetDispatchCB,NULL,connection.handle); - mListConnections.push_back(connection); -} - -void TelnetServer::disconnectClient(int filedescriptor) -{ - std::vector::iterator iter = mListConnections.begin(); - while(iter != mListConnections.end()) - { - if( filedescriptor == iter->filedescriptor ) - { - if( E_OK == mSocketHandler->removeFDPoll(iter->handle)) - { - mListConnections.erase(iter); - close(filedescriptor); - } - else - { - // TODO: Handle error - } - - break; - } - iter++; - } -} - -void TelnetServer::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //initialize buffer - char buffer[100]; - //read until buffer is full or no more data is there - int read=recv(pollfd.fd,buffer,100,NULL); - if (read>1) - { - //read the message and store it in a queue - its a telnet connection so data will be sent on enter ! - std::string msg=std::string(buffer,read); - mMsgList.push(msg); - } -} - -bool TelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData) -{ - (void) userData; - std::vector::iterator iterator=mListConnections.begin(); - for(;iterator!=mListConnections.end();++iterator) - { - if(iterator->handle==handle) break; - } - //if (iterator==mListConnections.end()) return false; - - std::string command; - std::queue MsgQueue; - if(!mMsgList.empty()) - { - sliceCommand(mMsgList.front(),command,MsgQueue); - mMsgList.pop(); - } - - mTelnetMenuHelper.enterCmdQueue(MsgQueue,iterator->filedescriptor); - - // must return false to stop endless polling - return false; - - /* - mMsgList.pop(); - mMapCommand_t::iterator commandIter=mMapCommands.find(command); - if (commandIter==mMapCommands.end()) - { - send(iterator->filedescriptor,"Command not found!\n",20,0); - } - else - { - commandIter->second(msg,iterator->filedescriptor); - //(*commandIter).second(msg,iterator->filedescriptor); - } - - //remove the message from the queue and return false if there is no more message to read. - if (mMsgList.size()!=0) return true; - return false; - */ -} - -bool TelnetServer::check(const sh_pollHandle_t handle, void *userData) -{ - (void)handle; - (void)userData; - if (mMsgList.size() != 0) return true; - return false; -} - -void am::TelnetServer::sliceCommand(const std::string & string, std::string & command, std::queue & MsgQueue) -{ - (void) command; - std::stringstream stream(string); - std::istream_iterator begin(stream); - std::istream_iterator end; - std::string cmd; - bool endOfStream = false; - - int c = 0; - - while(!endOfStream) - { - cmd = *begin; - MsgQueue.push(cmd); - begin++; - - if(begin == end ) - { - endOfStream = true; - } - c++; - } - - - /* - command = *begin++; - msg = std::vector(begin, end); - */ -} - - diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index dee5edb..b6acf5d 100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -35,22 +35,22 @@ #include #ifdef WITH_TELNET -#include "TelnetServer.h" +#include "CAmTelnetServer.h" #endif #ifdef WITH_DBUS_WRAPPER -#include +#include #endif -#include -#include "DatabaseHandler.h" -#include "ControlSender.h" -#include "CommandSender.h" -#include "RoutingSender.h" -#include "RoutingReceiver.h" -#include "CommandReceiver.h" -#include "ControlReceiver.h" -#include "DatabaseObserver.h" -#include "Router.h" -#include "DLTWrapper.h" +#include +#include "CAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "CAmCommandSender.h" +#include "CAmRoutingSender.h" +#include "CAmRoutingReceiver.h" +#include "CAmCommandReceiver.h" +#include "CAmControlReceiver.h" +#include "CAmDatabaseObserver.h" +#include "CAmRouter.h" +#include "shared/CAmDltWrapper.h" #include #include #include @@ -219,16 +219,15 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context) logError("signal handler was called, exit now..."); gDispatchDone = 1; //todo: maually fire the mainloop - //todo: ifdef no sockethandler exit(1); } int main(int argc, char *argv[]) { - DLTWrapper::instance()->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); - DLTWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); + CAmDltWrapper::instance(true)->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); + CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); logInfo("The Audiomanager is started"); - log(&AudioManager, DLT_LOG_ERROR, "The version of the Audiomanager", DAEMONVERSION); + logInfo("The version of the Audiomanager", DAEMONVERSION); listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); @@ -256,40 +255,36 @@ int main(int argc, char *argv[]) std::set_new_handler(&OutOfMemoryHandler); //Instantiate all classes. Keep in same order ! - SocketHandler iSocketHandler; + CAmSocketHandler iSocketHandler; #ifdef WITH_DBUS_WRAPPER - DBusWrapper iDBusWrapper(&iSocketHandler); + CAmDbusWrapper iDBusWrapper(&iSocketHandler); #endif /*WITH_DBUS_WRAPPER */ - DatabaseHandler iDatabaseHandler(databasePath); - RoutingSender iRoutingSender(listRoutingPluginDirs); - CommandSender iCommandSender(listCommandPluginDirs); - ControlSender iControlSender(controllerPlugin); - Router iRouter(&iDatabaseHandler, &iControlSender); + CAmDatabaseHandler iDatabaseHandler(databasePath); + CAmRoutingSender iRoutingSender(listRoutingPluginDirs); + CAmCommandSender iCommandSender(listCommandPluginDirs); + CAmControlSender iControlSender(controllerPlugin); + CAmRouter iRouter(&iDatabaseHandler, &iControlSender); #ifdef WITH_DBUS_WRAPPER - CommandReceiver iCommandReceiver(&iDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper); - RoutingReceiver iRoutingReceiver(&iDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper); - ControlReceiver iControlReceiver(&iDatabaseHandler, &iRoutingSender, &iCommandSender, &iSocketHandler, &iRouter); -#ifdef WITH_TELNET - TelnetServer iTelnetServer(&iSocketHandler, &iCommandSender, &iCommandReceiver, &iRoutingSender, &iRoutingReceiver, &iControlSender, &iControlReceiver, &iDatabaseHandler, &iRouter, telnetport, maxConnections); - DatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer); -#else /*WITH_TELNET*/ - DatabaseObserver iObserver(&iCommandSender,&iRoutingSender, &iSocketHandler); -#endif + CAmCommandReceiver iCommandReceiver(&iDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper); + CAmRoutingReceiver iRoutingReceiver(&iDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper); + CAmControlReceiver iControlReceiver(&iDatabaseHandler, &iRoutingSender, &iCommandSender, &iSocketHandler, &iRouter); #else /*WITH_DBUS_WRAPPER*/ - CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler); - RoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler); + CAmCommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler); + CAmRoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler); ControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter); +#endif /*WITH_DBUS_WRAPPER*/ + #ifdef WITH_TELNET - TelnetServer iTelnetServer(&iSocketHandler,telnetport,maxConnections); - DatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer); + CAmTelnetServer iTelnetServer(&iSocketHandler, &iCommandSender, &iCommandReceiver, &iRoutingSender, &iRoutingReceiver, &iControlSender, &iControlReceiver, &iDatabaseHandler, &iRouter, telnetport, maxConnections); + CAmDatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer); #else /*WITH_TELNET*/ - DatabaseObserver iObserver(&iCommandSender, &iSocketHandler, &iRoutingSender); + CAmDatabaseObserver iObserver(&iCommandSender,&iRoutingSender, &iSocketHandler); #endif -#endif /*WITH_DBUS_WRAPPER*/ + iDatabaseHandler.registerObserver(&iObserver); diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp new file mode 100644 index 0000000..6e9ead1 --- /dev/null +++ b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp @@ -0,0 +1,529 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file controlInterfaceTest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmControlInterfaceTest.h" +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +CAmControlInterfaceTest::CAmControlInterfaceTest() : + pSocketHandler(), // + pDBusWrapper((CAmDbusWrapper*) 1), // + plistCommandPluginDirs(), // + plistRoutingPluginDirs(), // + pDatabaseHandler(std::string(":memory:")), // + pRoutingSender(plistRoutingPluginDirs), //RoutingReceiver + pCommandSender(plistCommandPluginDirs), // + pMockControlInterface(), // + pMockRoutingInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlSender(std::string("")), // + pRouter(&pDatabaseHandler,&pControlSender), // + pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler, pDBusWrapper) +{ + pDatabaseHandler.registerObserver(&pDatabaseObserver); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); + pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock"); + +} + +CAmControlInterfaceTest::~CAmControlInterfaceTest() +{ +} + +void CAmControlInterfaceTest::SetUp() +{ + logInfo("RoutingSendInterface Test started"); +} + +void CAmControlInterfaceTest::TearDown() +{ +} + +TEST_F(CAmControlInterfaceTest,registerDomain) +{ + + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterDomain(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerDomain(domain,domainID)); + ASSERT_EQ(domainID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterDomain) +{ + am_domainID_t domainID = 34; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterDomain(34)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterDomain(domainID)); +} + +TEST_F(CAmControlInterfaceTest,registerSink) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterSink(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerSink(sink,sinkID)); + ASSERT_EQ(sinkID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterSink) +{ + am_sinkID_t sinkID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSink(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSink(sinkID)); +} + +TEST_F(CAmControlInterfaceTest,registerSource) +{ + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterSource(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerSource(source,sourceID)); + ASSERT_EQ(sourceID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterSource) +{ + am_sourceID_t sourceID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSource(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSource(sourceID)); +} + +TEST_F(CAmControlInterfaceTest,registerGateway) +{ + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + pCF.createGateway(gateway); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterGateway(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerGateway(gateway,gatewayID)); + ASSERT_EQ(gatewayID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterGateway) +{ + am_gatewayID_t gatewayID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterGateway(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterGateway(gatewayID)); +} + +TEST_F(CAmControlInterfaceTest,ackConnect) +{ + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector connectionList; + std::vector handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //when asyncConnect is called, we expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //The handle should have the correct type + ASSERT_EQ(handle.handleType, H_CONNECT); + ASSERT_EQ(handle.handle, 1); + ASSERT_EQ(connectionID, 1); + + //The list of handles shall have the handle inside + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, handle.handleType); + + //we check the list of connections - but it must be empty because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + + //finally we answer via the RoutingInterface and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); + pRoutingReceiver.ackConnect(handle, connectionID, E_OK); + + //the list of handles must be empty now + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //but the connection must be in the connectionlist + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(!connectionList.empty()); + + //no we try the same, but do expect a no_change answer directly and no call because connection already exists + ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); +} + +TEST_F(CAmControlInterfaceTest,ackDisconnect) +{ + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector connectionList; + std::vector handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //now we first need to connect, we expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //answer with an ack to insert the connection in the database + EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); + pRoutingReceiver.ackConnect(handle, connectionID, E_OK); + + //now we can start to disconnect and expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); + + //during the disconnection, the connection is still in the list! + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(!connectionList.empty()); + + //then we fire the ack and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1); + pRoutingReceiver.ackDisconnect(handle, connectionID, E_OK); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //make sure the connection is gone + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + + //Now let's try to disconnect what is not existing... + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,2)); +} + +TEST_F(CAmControlInterfaceTest,setSourceState) +{ + + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector handlesList; + am_Handle_s handle; + am_SourceState_e state; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //we set the sourcestate and expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); + + //we want our handle in the list and let the type be the right one + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESTATE); + + //the state must be unchanged because did not get the ack + ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); + ASSERT_EQ(state, SS_ON); + + //now we sent out the ack and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceState(handle, E_OK); + + //finally we need the sourcestate to be changed + ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); + ASSERT_EQ(state, SS_PAUSED); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //we try again but expect a no change error + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); +} + +TEST_F(CAmControlInterfaceTest,SetSinkVolumeChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_volume_t volume; + std::vector handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + sink.volume = 10; + + //setup environment, we need a domain and a sink + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //set the volume and expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSINKVOLUME); + + //now we read out the volume, but we expect no change because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); + ASSERT_EQ(sink.volume, volume); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1); + pRoutingReceiver.ackSetSinkVolumeChange(handle, 11, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); + ASSERT_EQ(11, volume); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); +} + +TEST_F(CAmControlInterfaceTest,ackSetSourceVolumeChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_volume_t volume; + std::vector handlesList; + am_Handle_s handle; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + source.volume = 12; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the sinkVolume, expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCEVOLUME); + + //now we read out the volume, but we expect no change because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); + ASSERT_EQ(source.volume, volume); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceVolumeChange(handle, 11, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); + ASSERT_EQ(11, volume); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); +} + +TEST_F(CAmControlInterfaceTest,ackSetSinkSoundProperty) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector handlesList; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + uint16_t oldvalue; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + soundProperty.type = SP_EXAMPLE_BASS; + soundProperty.value = 244; + + //setup environment, we need a domain and a sink + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //change the soundproperty, expect a call on the routinginterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,2,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSINKSOUNDPROPERTY); + + //read out this property. There is no change, because the ack did not arrive yet. + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(2,SP_EXAMPLE_BASS,oldvalue)); + ASSERT_EQ(sink.listSoundProperties[0].value, oldvalue); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSinkSoundProperty(handle, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_EXAMPLE_BASS,oldvalue)); + ASSERT_EQ(soundProperty.value, oldvalue); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); +} + +TEST_F(CAmControlInterfaceTest,ackSetSourceSoundProperty) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector handlesList; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + uint16_t oldvalue; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + soundProperty.type = SP_EXAMPLE_BASS; + soundProperty.value = 244; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //we trigger the change and wait for a call on the routinginterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,2,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESOUNDPROPERTY); + + //read out this property. There is no change, because the ack did not arrive yet. + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(2,SP_EXAMPLE_BASS,oldvalue)); + ASSERT_EQ(source.listSoundProperties[0].value, oldvalue); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceSoundProperty(handle, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_EXAMPLE_BASS,oldvalue)); + ASSERT_EQ(soundProperty.value, oldvalue); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); +} + +TEST_F(CAmControlInterfaceTest,crossFading) +{ + //todo: implement crossfading test +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h new file mode 100644 index 0000000..a39e9ed --- /dev/null +++ b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h @@ -0,0 +1,79 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file controlInterfaceTest.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include +#include + +#include "CAmDatabaseHandler.h" +#include "CAmControlReceiver.h" +#include "CAmRoutingReceiver.h" +#include "CAmDatabaseObserver.h" +#include "CAmControlSender.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "../IAmRoutingBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../IAmControlBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmRoutingSend.h" +#include "../MockIAmControlSend.h" +#include "shared/CAmSocketHandler.h" +#include "shared/CAmDbusWrapper.h" + +namespace am +{ + +class CAmControlInterfaceTest: public ::testing::Test +{ +public: + CAmControlInterfaceTest(); + ~CAmControlInterfaceTest(); + CAmSocketHandler pSocketHandler; + CAmDbusWrapper* pDBusWrapper; + std::vector plistCommandPluginDirs; + std::vector plistRoutingPluginDirs; + CAmDatabaseHandler pDatabaseHandler; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmControlSend pMockControlInterface; + MockIAmRoutingSend pMockRoutingInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmDatabaseObserver pDatabaseObserver; + CAmControlReceiver pControlReceiver; + CAmRoutingReceiver pRoutingReceiver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); +}; + +} + +#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt b/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..54f7c35 --- /dev/null +++ b/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt @@ -0,0 +1,85 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger AmControlInterfaceTest +# +# \file CMakeLists.txt +# +# \date 20-Oct-2011 3:42:04 PM +# \author Christian Mueller (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 Mueller 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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmControlInterfaceTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(SQLITE REQUIRED sqlite3) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${GTEST_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB CONTROL_INTERFACE_SRCS_CXX + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmControlReceiver.cpp" + "../../src/CAmControlSender.cpp" + "../../src/CAmRouter.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmCommandReceiver.cpp" + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmControlInterfaceTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${GTEST_LIBRARIES} + gmock +) + +INSTALL(TARGETS AmControlInterfaceTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + + + + diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp new file mode 100644 index 0000000..a5948ed --- /dev/null +++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp @@ -0,0 +1,1941 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file databasetest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmDatabaseHandlerTest.h" +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +//extern int GetRandomNumber(int nLow, int nHigh); +//extern bool equalSoundProperty (const am_SoundProperty_s a, const am_SoundProperty_s b); +extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b); +//extern bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b); +extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b); +extern std::string int2string(int i); + +CAmDatabaseHandlerTest::CAmDatabaseHandlerTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(),// + pDatabaseHandler(std::string(":memory:")), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pMockInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlSender(""), // + pRouter(&pDatabaseHandler, &pControlSender), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); +} + +CAmDatabaseHandlerTest::~CAmDatabaseHandlerTest() +{ +} + +void CAmDatabaseHandlerTest::createMainConnectionSetup() +{ + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector connectionList; + + //we create 9 sources and sinks: + + + + for (uint16_t i = 1; i < 10; i++) + { + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + + pCF.createSink(sink); + sink.sinkID = i; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = i; + source.name = "source" + int2string(i); + source.domainID = 4; + + connection.sinkID = i; + connection.sourceID = i; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + connectionList.push_back(connectionID); + + } + + //create a mainConnection + am_MainConnection_s mainConnection; + am_mainConnectionID_t mainConnectionID; + std::vector mainConnectionList; + mainConnection.listConnectionID = connectionList; + mainConnection.mainConnectionID = 0; + mainConnection.sinkID = 1; + mainConnection.sourceID = 1; + mainConnection.connectionState = CS_CONNECTED; + mainConnection.delay = -1; + + //enter mainconnection in database + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_NE(0, mainConnectionID); + + //read out the mainconnections and check if they are equal to the data written. + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList)); + bool equal = true; + std::vector::iterator listIterator = mainConnectionList.begin(); + for (; listIterator < mainConnectionList.end(); ++listIterator) + { + if (listIterator->mainConnectionID == mainConnectionID) + { + equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->sinkID == mainConnection.sinkID) && (listIterator->sourceID == mainConnection.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); + } + } + ASSERT_EQ(true, equal); +} + +void CAmDatabaseHandlerTest::SetUp() +{ +} + +void CAmDatabaseHandlerTest::TearDown() +{ +} + +TEST_F(CAmDatabaseHandlerTest,getMainConnectionInfo) +{ + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector connectionList; + + //we create 9 sources and sinks: + + + + for (uint16_t i = 1; i < 10; i++) + { + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + + pCF.createSink(sink); + sink.sinkID = i; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = i; + source.name = "source" + int2string(i); + source.domainID = 4; + + connection.sinkID = i; + connection.sourceID = i; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + connectionList.push_back(connectionID); + + } + + //create a mainConnection + am_MainConnection_s mainConnection; + am_mainConnectionID_t mainConnectionID; + std::vector mainConnectionList; + mainConnection.listConnectionID = connectionList; + mainConnection.mainConnectionID = 0; + mainConnection.sinkID = 1; + mainConnection.sourceID = 1; + mainConnection.connectionState = CS_CONNECTED; + mainConnection.delay = -1; + + //enter mainconnection in database + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_NE(0, mainConnectionID); + + //read out the mainconnections and check if they are equal to the data written. + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList)); + bool equal = true; + std::vector::iterator listIterator = mainConnectionList.begin(); + for (; listIterator < mainConnectionList.end(); ++listIterator) + { + if (listIterator->mainConnectionID == mainConnectionID) + { + equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->sinkID == mainConnection.sinkID) && (listIterator->sourceID == mainConnection.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); + } + }ASSERT_EQ(true, equal); + + am_MainConnection_s mainConnectionT; + ASSERT_EQ(E_OK, pDatabaseHandler.getMainConnectionInfoDB(mainConnectionID,mainConnectionT)); + ASSERT_TRUE( (mainConnection.connectionState==mainConnectionT.connectionState) && (mainConnection.delay==mainConnectionT.delay) && (std::equal(mainConnection.listConnectionID.begin(),mainConnection.listConnectionID.end(),mainConnectionT.listConnectionID.begin())) && (mainConnection.sinkID==mainConnectionT.sinkID) && (mainConnection.sourceID==mainConnectionT.sourceID) && (mainConnectionID==mainConnectionT.mainConnectionID)); + +} + +TEST_F(CAmDatabaseHandlerTest,getSinKInfo) +{ + //fill the connection database + am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; + am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; + std::vector sinkList; + + pCF.createSink(staticSink); + staticSink.sinkID = 4; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(firstDynamicSink); + firstDynamicSink.name = "firstdynamic"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSink(secondDynamicSink); + secondDynamicSink.name = "seconddynamic"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) + << "ERROR: database error"; + bool equal = true; + + std::vector::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + equal = equal && pCF.compareSink(listIterator, staticSink); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + equal = equal && pCF.compareSink(listIterator, firstDynamicSink); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + equal = equal && pCF.compareSink(listIterator, secondDynamicSink); + } + }ASSERT_EQ(true, equal); + + am_Sink_s sinkData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkInfoDB(secondDynamicSinkID,sinkData)); + ASSERT_TRUE( (secondDynamicSink.available.availability == sinkData.available.availability) && (secondDynamicSink.available.availabilityReason == sinkData.available.availabilityReason) && (secondDynamicSink.sinkClassID == sinkData.sinkClassID) && (secondDynamicSink.domainID == sinkData.domainID) && (secondDynamicSink.visible == sinkData.visible) && (secondDynamicSink.name.compare(sinkData.name) == 0) && (secondDynamicSink.volume == sinkData.volume) && std::equal(secondDynamicSink.listConnectionFormats.begin(), secondDynamicSink.listConnectionFormats.end(), sinkData.listConnectionFormats.begin()) && std::equal(secondDynamicSink.listMainSoundProperties.begin(), secondDynamicSink.listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty)); + +} + +TEST_F(CAmDatabaseHandlerTest,getSourceInfo) +{ + //fill the connection database + am_Source_s staticSource, firstDynamicSource, secondDynamicSource; + am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; + std::vector sourceList; + + pCF.createSource(staticSource); + staticSource.sourceID = 4; + staticSource.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(firstDynamicSource); + firstDynamicSource.name = "firstDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSource(secondDynamicSource); + secondDynamicSource.name = "secondDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) + << "ERROR: database error"; + bool equal = true; + + std::vector::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + equal = equal && pCF.compareSource(listIterator, staticSource); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + equal = equal && pCF.compareSource(listIterator, firstDynamicSource); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + equal = equal && pCF.compareSource(listIterator, secondDynamicSource); + } + pCF.compareSource(listIterator, secondDynamicSource); + + }ASSERT_EQ(true, equal); + + am_Source_s sourceData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceInfoDB(secondDynamicSourceID,sourceData)); + ASSERT_TRUE( + (secondDynamicSource.available.availability == sourceData.available.availability) && (secondDynamicSource.available.availabilityReason == sourceData.available.availabilityReason) && (secondDynamicSource.sourceClassID == sourceData.sourceClassID) && (secondDynamicSource.domainID == sourceData.domainID) && (secondDynamicSource.interruptState == sourceData.interruptState) && (secondDynamicSource.visible == sourceData.visible) && (secondDynamicSource.name.compare(sourceData.name) == 0) && (secondDynamicSource.volume == sourceData.volume) && std::equal(secondDynamicSource.listConnectionFormats.begin(), secondDynamicSource.listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) && std::equal(secondDynamicSource.listMainSoundProperties.begin(), secondDynamicSource.listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty)); + +} + +TEST_F(CAmDatabaseHandlerTest, peekSourceID) +{ + + std::string sourceName("myClassID"); + am_sourceClass_t sourceClassID, peekID; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sourceClass.name = sourceName; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID)); + ASSERT_EQ(sourceClassID, peekID); +} + +TEST_F(CAmDatabaseHandlerTest, peekSinkID) +{ + + std::string sinkName("myClassID"); + am_sinkClass_t sinkClassID, peekID; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sinkClass.name = sinkName; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID)); + ASSERT_EQ(sinkClassID, peekID); +} + +TEST_F(CAmDatabaseHandlerTest,crossfaders) +{ + + + + am_Crossfader_s crossfader; + am_crossfaderID_t crossfaderID; + am_Sink_s sinkA, sinkB; + am_Source_s source; + am_sourceID_t sourceID; + am_sinkID_t sinkAID, sinkBID; + pCF.createSink(sinkA); + pCF.createSink(sinkB); + sinkB.name = "sinkB"; + pCF.createSource(source); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); + + crossfader.crossfaderID = 0; + crossfader.hotSink = HS_SINKA; + crossfader.sinkID_A = sinkAID; + crossfader.sinkID_B = sinkBID; + crossfader.sourceID = sourceID; + crossfader.name = "Crossfader"; + crossfader.hotSink = HS_UNKNOWN; + + std::vector listCrossfaders; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfaders(listCrossfaders)); + ASSERT_EQ(crossfader.sinkID_A, listCrossfaders[0].sinkID_A); + ASSERT_EQ(crossfader.sinkID_B, listCrossfaders[0].sinkID_B); + ASSERT_EQ(crossfader.sourceID, listCrossfaders[0].sourceID); + ASSERT_EQ(crossfader.hotSink, listCrossfaders[0].hotSink); + ASSERT_EQ(100, listCrossfaders[0].crossfaderID); + ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0); +} + +TEST_F(CAmDatabaseHandlerTest,crossfadersGetFromDomain) +{ + + + + am_Crossfader_s crossfader; + am_crossfaderID_t crossfaderID; + am_Sink_s sinkA, sinkB; + am_Source_s source; + am_sourceID_t sourceID; + am_sinkID_t sinkAID, sinkBID; + am_domainID_t domainID; + am_Domain_s domain; + pCF.createSink(sinkA); + pCF.createSink(sinkB); + pCF.createDomain(domain); + sinkB.name = "sinkB"; + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + source.domainID = domainID; + sinkA.domainID = domainID; + sinkB.domainID = domainID; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); + + crossfader.crossfaderID = 0; + crossfader.hotSink = HS_SINKA; + crossfader.sinkID_A = sinkAID; + crossfader.sinkID_B = sinkBID; + crossfader.sourceID = sourceID; + crossfader.name = "Crossfader"; + crossfader.hotSink = HS_UNKNOWN; + + std::vector listCrossfaders; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfadersOfDomain(source.domainID,listCrossfaders)); + ASSERT_EQ(100, listCrossfaders[0]); + +} + +TEST_F(CAmDatabaseHandlerTest,sourceState) +{ + am_Source_s source; + am_sourceID_t sourceID; + std::vector listSources; + pCF.createSource(source); + source.sourceState = SS_OFF; + + //prepare the test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the source state + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceState(sourceID,SS_ON)); + + //read out the changed values + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(listSources[0].sourceState, SS_ON); +} + +TEST_F(CAmDatabaseHandlerTest,sinkVolumeChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + std::vector listSinks; + pCF.createSink(sink); + sink.volume = 23; + + //prepare the test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //change the volume and check the read out + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkVolume(sinkID,34)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].volume, 34); +} + +TEST_F(CAmDatabaseHandlerTest,sourceVolumeChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + std::vector listSources; + pCF.createSource(source); + source.volume = 23; + + //prepare test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the volume and check the read out + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceVolume(sourceID,34)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(listSources[0].volume, 34); +} + +TEST_F(CAmDatabaseHandlerTest, peekSource) +{ + std::vector listSources; + am_sourceID_t sourceID, source2ID, source3ID; + am_Source_s source; + pCF.createSource(source); + + //peek a source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); + + //make sure it is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.empty()); + ASSERT_EQ(sourceID, 100); + + //now enter the source with the same name and make sure it does not get a new ID + source.name = "newsource"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source2ID); + ASSERT_TRUE(listSources[0].sourceID==sourceID); + + //now we peek again. This time, the source exists + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(source.name,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.size()==1); + ASSERT_EQ(source3ID, source2ID); +} + +TEST_F(CAmDatabaseHandlerTest, peekSourceDouble) +{ + std::vector listSources; + am_sourceID_t sourceID; + am_sourceID_t source2ID; + am_sourceID_t source3ID; + am_Source_s source; + pCF.createSource(source); + + //peek a source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); + + //peek a second source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.empty()); + ASSERT_EQ(sourceID, 100); + source.name = "newsource"; + + //now enter the source with the same name than the first peek and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source3ID); + ASSERT_TRUE(listSources[0].sourceID==sourceID); +} + +TEST_F(CAmDatabaseHandlerTest, peekSink) +{ + std::vector listSinks; + am_sinkID_t sinkID, sink2ID, sink3ID; + am_Sink_s sink; + pCF.createSink(sink); + + //peek a sink that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); + + //make sure it is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.empty()); + ASSERT_EQ(sinkID, 100); + sink.name = "newsink"; + + //now enter the source with the same name and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink2ID); + ASSERT_TRUE(listSinks[0].sinkID==sinkID); + + //now we peek again, this time, the sink exists + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(sink.name,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.size()==1); + ASSERT_EQ(sink3ID, sink2ID); +} + +TEST_F(CAmDatabaseHandlerTest, peekSinkDouble) +{ + std::vector listSinks; + am_sinkID_t sinkID; + am_sinkID_t sink2ID; + am_sinkID_t sink3ID; + am_Sink_s sink; + pCF.createSink(sink); + + //peek a sink that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); + + //peek again + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.empty()); + ASSERT_EQ(sinkID, 100); + sink.name = "newsink"; + + //now enter the sink with the same name than the first peek and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink3ID); + ASSERT_TRUE(listSinks[0].sinkID==sinkID); +} + +TEST_F(CAmDatabaseHandlerTest,changeConnectionTimingInformationCheckMainConnection) +{ + std::vector connectionList; + std::vector mainList; + + //prepare the test, it is one mainconnection, so we expect one callback + createMainConnectionSetup(); + + //first get all visible mainconnections and make sure, the delay is set to -1 for the first entry + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); + ASSERT_EQ(mainList[0].delay, -1); + + //no go through all connections and set the delay time to 24 for each connection + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + std::vector::iterator iteratorConnectionList = connectionList.begin(); + for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList) + { + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24)); + } + + //we read the result again and expect that the value is now different from -1 + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); + ASSERT_EQ(mainList[0].delay, 216); +} + +TEST_F(CAmDatabaseHandlerTest,changeConnectionTimingInformation) +{ + am_Connection_s connection; + am_connectionID_t connectionID; + std::vector connectionList; + pCF.createConnection(connection); + + //enter a connection + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + + //change the timing and check it + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(connectionID,24)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList[0].delay==24); +} + +TEST_F(CAmDatabaseHandlerTest,getSinkClassOfSink) +{ + std::vector sinkClassList; + std::vector classPropertyList; + am_SinkClass_s sinkClass, returnClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + am_Sink_s sink; + am_sinkID_t sinkID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 4; + sinkClass.listClassProperties = classPropertyList; + pCF.createSink(sink); + sink.sinkClassID = 4; + + //prepare test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //enter a new sinkclass, read out again and check + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 4); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkClassInfoDB(sinkID,returnClass)); + ASSERT_EQ(sinkClassList[0].name, returnClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, returnClass.sinkClassID); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),returnClass.listClassProperties.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,getSourceClassOfSource) +{ + std::vector sourceClassList; + std::vector classPropertyList; + am_SourceClass_s sourceClass, sinkSourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + am_Source_s source; + am_sourceID_t sourceID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 1; + sourceClass.listClassProperties = classPropertyList; + pCF.createSource(source); + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 1); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceClassInfoDB(sourceID,sinkSourceClass)); + ASSERT_EQ(sourceClassList[0].name, sinkSourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, sinkSourceClass.sourceClassID); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),sinkSourceClass.listClassProperties.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,removeSourceClass) +{ + std::vector sourceClassList; + std::vector classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 3; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 3); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSourceClassDB(3)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_TRUE(sourceClassList.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,updateSourceClass) +{ + std::vector sourceClassList; + std::vector classPropertyList, changedPropertyList; + am_SourceClass_s sourceClass, changedClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties = classPropertyList; + changedClass = sourceClass; + changedClass.listClassProperties[1].value = 6; + changedPropertyList = changedClass.listClassProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + changedClass.sourceClassID = sourceClassID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 100); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceClassInfoDB(changedClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 100); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,enterSourceClass) +{ + std::vector sourceClassList; + std::vector classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 100); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,enterSourceClassStatic) +{ + std::vector sourceClassList; + std::vector classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 3; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 3); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,removeSinkClass) +{ + std::vector sinkClassList; + std::vector classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 100); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkClassDB(sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_TRUE(sinkClassList.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,updateSinkClass) +{ + std::vector sinkClassList; + std::vector classPropertyList, changedPropertyList; + am_SinkClass_s sinkClass, changedClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + changedClass = sinkClass; + changedClass.listClassProperties[1].value = 6; + changedPropertyList = changedClass.listClassProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + changedClass.sinkClassID = sinkClassID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 100); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkClassInfoDB(changedClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 100); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,enterSinkClass) +{ + std::vector sinkClassList; + std::vector classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 100); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest,enterSinkClassStatic) +{ + std::vector sinkClassList; + std::vector classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 4; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 4); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmDatabaseHandlerTest, changeSystemProperty) +{ + std::vector listSystemProperties, listReturn; + am_SystemProperty_s systemProperty; + + systemProperty.type = SYP_UNKNOWN; + systemProperty.value = 33; + listSystemProperties.push_back(systemProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); + systemProperty.value = 444; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); + ASSERT_EQ(listReturn[0].type, systemProperty.type); + ASSERT_EQ(listReturn[0].value, systemProperty.value); +} + +TEST_F(CAmDatabaseHandlerTest, systemProperties) +{ + std::vector listSystemProperties, listReturn; + am_SystemProperty_s systemProperty; + + systemProperty.type = SYP_UNKNOWN; + systemProperty.value = 33; + listSystemProperties.push_back(systemProperty); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); + ASSERT_EQ(listReturn[0].type, systemProperty.type); + ASSERT_EQ(listReturn[0].value, systemProperty.value); +} + +TEST_F(CAmDatabaseHandlerTest,enterSourcesCorrect) +{ + //fill the connection database + am_Source_s staticSource, firstDynamicSource, secondDynamicSource; + am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; + std::vector sourceList; + + pCF.createSource(staticSource); + staticSource.sourceID = 4; + staticSource.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(firstDynamicSource); + firstDynamicSource.name = "firstDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSource(secondDynamicSource); + secondDynamicSource.name = "secondDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) + << "ERROR: database error"; + bool equal = true; + + std::vector::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + equal = equal && pCF.compareSource(listIterator, staticSource); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + equal = equal && pCF.compareSource(listIterator, firstDynamicSource); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + equal = equal && pCF.compareSource(listIterator, secondDynamicSource); + } + + } + ASSERT_EQ(true, equal); +} + +TEST_F(CAmDatabaseHandlerTest, changeSourceMainSoundProperty) +{ + std::vector listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_MainSoundProperty_s property; + property.type = MSP_UNKNOWN; + property.value = 33; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB(property,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + std::vector::iterator listIterator = listSources[0].listMainSoundProperties.begin(); + for (; listIterator < listSources[0].listMainSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + { + ASSERT_EQ(listIterator->value, property.value); + } + } +} + +TEST_F(CAmDatabaseHandlerTest, changeSinkMuteState) +{ + std::vector listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MuteState_e muteState = MS_MUTED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(muteState, listSinks[0].muteState); +} + +TEST_F(CAmDatabaseHandlerTest, changeSinkMainSoundProperty) +{ + std::vector listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MainSoundProperty_s property; + property.type = MSP_UNKNOWN; + property.value = 33; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + std::vector::iterator listIterator = listSinks[0].listMainSoundProperties.begin(); + for (; listIterator < listSinks[0].listMainSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + { + ASSERT_EQ(listIterator->value, property.value); + } + } +} + +TEST_F(CAmDatabaseHandlerTest, peekDomain) +{ + std::vector listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.empty()); + ASSERT_EQ(domainID, 1); + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); + ASSERT_TRUE(listDomains[0].domainID==domainID); +} + +TEST_F(CAmDatabaseHandlerTest, peekDomainFirstEntered) +{ + std::vector listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID)); + ASSERT_EQ(domainID, domain2ID); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.size()==1); +} + +TEST_F(CAmDatabaseHandlerTest, changeDomainState) +{ + std::vector listDomains; + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + am_DomainState_e newState = DS_INDEPENDENT_STARTUP; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changDomainStateDB(newState,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(newState, listDomains[0].state); +} + +TEST_F(CAmDatabaseHandlerTest, changeMainConnectionState) +{ + std::vector listMainConnections; + createMainConnectionSetup(); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); + ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState); +} + +TEST_F(CAmDatabaseHandlerTest, changeSinkAvailability) +{ + std::vector listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(availability.availability, listSinks[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason); +} + +TEST_F(CAmDatabaseHandlerTest, changeSourceAvailability) +{ + std::vector listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + source.visible = true; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(availability.availability, listSources[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason); +} + +TEST_F(CAmDatabaseHandlerTest,changeMainConnectionRoute) +{ + std::vector originalList; + std::vector newList; + createMainConnectionSetup(); + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector listConnectionID; + + + + for (uint16_t i = 1; i < 10; i++) + { + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + + connection.sinkID = i + 20; + connection.sourceID = i + 20; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + + pCF.createSink(sink); + sink.sinkID = i + 20; + sink.name = "sink" + int2string(i + 20); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = i + 20; + source.name = "source" + int2string(i + 30); + source.domainID = 4; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + listConnectionID.push_back(connectionID); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(originalList)); + + } + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(1,listConnectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(newList)); + ASSERT_FALSE(std::equal(newList[0].listConnectionID.begin(),newList[0].listConnectionID.end(),originalList[0].listConnectionID.begin())); +} + +TEST_F(CAmDatabaseHandlerTest,changeMainSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_mainVolume_t newVol = 20; + std::vector listSinks; + pCF.createSink(sink); + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].mainVolume, newVol); +} + +TEST_F(CAmDatabaseHandlerTest,getMainSourceSoundProperties) +{ + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + std::vector mainSoundProperties = source.listMainSoundProperties; + std::vector listMainSoundProperties; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties)); + ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); +} + +TEST_F(CAmDatabaseHandlerTest,getMainSinkSoundProperties) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + std::vector mainSoundProperties = sink.listMainSoundProperties; + std::vector listMainSoundProperties; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties)); + ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); +} + +TEST_F(CAmDatabaseHandlerTest,getMainSources) +{ + am_Source_s source, source1, source2; + am_sourceID_t sourceID; + pCF.createSource(source); + pCF.createSource(source1); + pCF.createSource(source2); + source1.name = "source1"; + source2.name = "source2"; + bool equal = true; + source1.visible = false; + std::vector listMainSources; + std::vector listSources; + + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source2,sourceID)); + source2.sourceID = sourceID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listMainSources)); + listSources.push_back(source); + listSources.push_back(source2); + std::vector::iterator listIterator = listMainSources.begin(); + for (; listIterator < listMainSources.end(); ++listIterator) + { + equal = equal && pCF.compareSinkMainSource(listIterator, listSources); + } + ASSERT_TRUE(equal); +} + +TEST_F(CAmDatabaseHandlerTest,getMainSinks) +{ + am_Sink_s sink, sink1, sink2; + am_sinkID_t sinkID; + pCF.createSink(sink); + pCF.createSink(sink1); + pCF.createSink(sink2); + sink1.name = "sink1"; + sink2.name = "sink2"; + bool equal = true; + sink1.visible = false; + std::vector listMainSinks; + std::vector listSinks; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink2,sinkID)); + sink2.sinkID = sinkID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listMainSinks)); + listSinks.push_back(sink); + listSinks.push_back(sink2); + std::vector::iterator listIterator = listMainSinks.begin(); + for (; listIterator < listMainSinks.end(); ++listIterator) + { + equal = equal && pCF.compareSinkMainSink(listIterator, listSinks); + } + ASSERT_TRUE(equal); +} + +TEST_F(CAmDatabaseHandlerTest,getVisibleMainConnections) +{ + createMainConnectionSetup(); + std::vector listVisibleMainConnections; + std::vector listMainConnections; + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(listVisibleMainConnections)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); + ASSERT_EQ(listMainConnections[0].mainConnectionID, listVisibleMainConnections[0].mainConnectionID); + ASSERT_EQ(listMainConnections[0].connectionState, listVisibleMainConnections[0].connectionState); + ASSERT_EQ(listMainConnections[0].delay, listVisibleMainConnections[0].delay); + ASSERT_EQ(listMainConnections[0].sinkID, listVisibleMainConnections[0].sinkID); + ASSERT_EQ(listMainConnections[0].sourceID, listVisibleMainConnections[0].sourceID); +} + +TEST_F(CAmDatabaseHandlerTest,getListSourcesOfDomain) +{ + am_Source_s source, source2; + am_Domain_s domain; + am_domainID_t domainID; + am_sourceID_t sourceID; + std::vector sourceList, sourceCheckList; + pCF.createSource(source); + source.sourceID = 1; + source.name = "testSource"; + source.domainID = 1; + pCF.createSource(source2); + source2.sourceID = 0; + source2.name = "testSource2"; + source2.domainID = 5; + pCF.createDomain(domain); + sourceCheckList.push_back(1); //sink.sinkID); + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source2,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSourcesOfDomain(2,sourceList)) + << "ERROR: database error";ASSERT_TRUE(sourceList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListSourcesOfDomain(1,sourceList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,getListSinksOfDomain) +{ + am_Sink_s sink, sink2; + am_Domain_s domain; + am_domainID_t domainID; + am_sinkID_t sinkID; + std::vector sinkList, sinkCheckList; + pCF.createSink(sink); + sink.sinkID = 1; + sink.domainID = 1; + pCF.createSink(sink2); + sink2.domainID = 5; + sink2.name = "sink2"; + pCF.createDomain(domain); + sinkCheckList.push_back(1); //sink.sinkID); + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSinksOfDomain(2,sinkList)) + << "ERROR: database error";ASSERT_TRUE(sinkList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(1,sinkList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,getListGatewaysOfDomain) +{ + + + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID; + am_domainID_t domainID; + am_Domain_s domain; + std::vector gatewayList, gatewayCheckList; + pCF.createGateway(gateway); + gateway.gatewayID = 1; + gateway.name = "testGateway"; + gateway.controlDomainID = 1; + gateway.sourceID = 1; + gateway.sinkID = 1; + gateway.domainSinkID = 1; + gateway.domainSourceID = 1; + pCF.createGateway(gateway2); + gateway2.gatewayID = 2; + gateway2.name = "testGateway2"; + gateway2.controlDomainID = 4; + gateway2.sourceID = 1; + gateway2.sinkID = 1; + gateway2.domainSinkID = 1; + gateway2.domainSourceID = 1; + pCF.createDomain(domain); + gatewayCheckList.push_back(gateway.gatewayID); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList)) + << "ERROR: database error";ASSERT_TRUE(gatewayList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(1,gatewayList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,removeDomain) +{ + am_Domain_s domain; + am_domainID_t domainID; + std::vector listDomains; + pCF.createDomain(domain); + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(listDomains)) + << "ERROR: database error"; + ASSERT_TRUE(listDomains.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,removeGateway) +{ + + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + std::vector listGateways; + pCF.createGateway(gateway); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(listGateways)) + << "ERROR: database error"; + ASSERT_TRUE(listGateways.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,removeSink) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + std::vector listSinks; + pCF.createSink(sink); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + ASSERT_TRUE(listSinks.empty()); +} + +TEST_F(CAmDatabaseHandlerTest,removeSource) +{ + //fill the connection database + am_Source_s source; + am_sourceID_t sourceID; + std::vector listSources; + pCF.createSource(source); + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) + << "ERROR: database error"; + ASSERT_TRUE(listSources.empty()); +} + +TEST_F(CAmDatabaseHandlerTest, removeMainConnection) +{ + createMainConnectionSetup(); + + + ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,removeNonexistentMainConnectionFail) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,removeNonexistentSource) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,removeNonexistentSink) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,removeNonexistentGateway) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,registerGatewayCorrect) +{ + + + //initialize gateway + std::vector returnList; + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createGateway(gateway); + pCF.createGateway(gateway1); + gateway1.gatewayID = 20; + pCF.createGateway(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(100,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(101,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + bool equal = true; + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + equal = equal && pCF.compareGateway(listIterator, gateway); + } + + if (listIterator->gatewayID == gatewayID1) + { + equal = equal && pCF.compareGateway(listIterator, gateway1); + } + + if (listIterator->gatewayID == gatewayID2) + { + equal = equal && pCF.compareGateway(listIterator, gateway2); + } + } + + ASSERT_EQ(true, equal); +} + +TEST_F(CAmDatabaseHandlerTest,getGatewayInfo) +{ + + + //initialize gateway + std::vector returnList; + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createGateway(gateway); + pCF.createGateway(gateway1); + gateway1.gatewayID = 20; + pCF.createGateway(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(100,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(101,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + bool equal = true; + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + equal = equal && pCF.compareGateway(listIterator, gateway); + } + + if (listIterator->gatewayID == gatewayID1) + { + equal = equal && pCF.compareGateway(listIterator, gateway1); + } + + if (listIterator->gatewayID == gatewayID2) + { + equal = equal && pCF.compareGateway(listIterator, gateway2); + } + } + + ASSERT_EQ(true, equal); + + am_Gateway_s gatewayInfo; + ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo)); + ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo)); + +} + +TEST_F(CAmDatabaseHandlerTest,enterSinkThatAlreadyExistFail) +{ + //fill the connection database + am_Sink_s staticSink, SecondSink; + am_sinkID_t staticSinkID, SecondSinkID; + + pCF.createSink(staticSink); + staticSink.sinkID = 43; + staticSink.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(SecondSink); + SecondSink.sinkID = 43; + SecondSink.name = "SecondSink"; + + ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,enterSourcesThatAlreadyExistFail) +{ + //fill the connection database + am_Source_s staticSource, SecondSource; + am_sourceID_t staticSourceID, SecondSourceID; + pCF.createSource(staticSource); + staticSource.sourceID = 4; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(SecondSource); + SecondSource.sourceID = 4; + + ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID)) + << "ERROR: database error"; +} + +TEST_F(CAmDatabaseHandlerTest,registerDomainCorrect) +{ + //initialize domain + std::vector returnList; + am_Domain_s domain; + am_domainID_t domainID = 0; + pCF.createDomain(domain); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_NE(0,domainID) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); + bool equal = true; + std::vector::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->domainID == domainID) + { + equal = equal && (listIterator->name.compare(domain.name) == 0) && (listIterator->busname.compare(domain.busname) == 0) && (listIterator->complete == domain.complete) && (listIterator->early == domain.early) && (listIterator->state == domain.state); + } + } + ASSERT_EQ(true, equal); +} + +TEST_F(CAmDatabaseHandlerTest,registerConnectionCorrect) +{ + am_Connection_s connection; + am_connectionID_t connectionID; + std::vector returnList; + pCF.createConnection(connection); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID)) + << "ERROR: database error";; + ASSERT_NE(0,connectionID) + << "ERROR: connectionID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(returnList)); + bool equal = false; + std::vector::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->connectionID == connectionID) + { + equal = (listIterator->sourceID == connection.sourceID) && (listIterator->sinkID == connection.sinkID) && (listIterator->delay == connection.delay) && (listIterator->connectionFormat = connection.connectionFormat); + } + } + ASSERT_EQ(true, equal); +} + +TEST_F(CAmDatabaseHandlerTest,enterMainConnectionCorrect) +{ + createMainConnectionSetup(); +} + +TEST_F(CAmDatabaseHandlerTest,enterSinksCorrect) +{ + //fill the connection database + am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; + am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; + std::vector sinkList; + + pCF.createSink(staticSink); + staticSink.sinkID = 4; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(firstDynamicSink); + firstDynamicSink.name = "firstdynamic"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSink(secondDynamicSink); + secondDynamicSink.name = "seconddynamic"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) + << "ERROR: database error"; + bool equal = true; + + std::vector::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + equal = equal && pCF.compareSink(listIterator, staticSink); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + equal = equal && pCF.compareSink(listIterator, firstDynamicSink); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + equal = equal && pCF.compareSink(listIterator, secondDynamicSink); + } + } + ASSERT_EQ(true, equal); +} + +//Commented out - gives always a warning.. +//TEST_F(databaseTest,registerDomainFailonID0) +//{ +// am_Domain_s domain; +// am_domainID_t domainID=5; +// pCF.createDomain(domain); +// domain.domainID=1; +// ASSERT_DEATH(pDatabaseHandler.enterDomainDB(domain,domainID),"Assertion `domainData.domainID==0'"); +//} + +int main(int argc, char **argv) +{ + CAmDltWrapper::instance()->registerApp("databse", "databasetest"); + logInfo("Database Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h new file mode 100644 index 0000000..a66af97 --- /dev/null +++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file databasetest.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef DATABASETEST_H_ +#define DATABASETEST_H_ + +#define UNIT_TEST 1 + +#include +#include + +#include "CAmDatabaseHandler.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "CAmControlSender.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +class CAmDatabaseHandlerTest: public ::testing::Test +{ +public: + CAmDatabaseHandlerTest(); + ~CAmDatabaseHandlerTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandler pDatabaseHandler; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmCommandSend pMockInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + + void createMainConnectionSetup(); +}; + +} + +#endif /* DATABASETEST_H_ */ diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt new file mode 100644 index 0000000..da326da --- /dev/null +++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt @@ -0,0 +1,81 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger AmDatabaseHandlerTest +# +# \file CMakeLists.txt +# +# \date 20-Oct-2011 3:42:04 PM +# \author Christian Mueller (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 Mueller 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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmDatabaseHandlerTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(SQLITE REQUIRED sqlite3) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB DATABASE_SRCS_CXX + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmControlReceiver.cpp" + "../../src/CAmControlSender.cpp" + "../../src/CAmRouter.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmCommandReceiver.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmDatabaseHandlerTest ${DATABASE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmDatabaseHandlerTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${GTEST_LIBRARIES} + gmock +) + +INSTALL(TARGETS AmDatabaseHandlerTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp new file mode 100644 index 0000000..27ad546 --- /dev/null +++ b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp @@ -0,0 +1,1820 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file databasetest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmRouterTest.h" +#include +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +CAmRouterTest::CAmRouterTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pDatabaseHandler(std::string(":memory:")), // + pControlSender(std::string("")), // + pRouter(&pDatabaseHandler, &pControlSender), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pMockInterface(), // + pMockControlInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // + pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); +} + +CAmRouterTest::~CAmRouterTest() +{ +} + +void CAmRouterTest::SetUp() +{ + logInfo("Routing Test started "); +} + +void CAmRouterTest::TearDown() +{ +} + +ACTION(returnConnectionFormat){ +arg4=arg3; +} + +//test that checks just sinks and source in a domain but connectionformats do not match +TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(0, listRoutes.size()); + +} + +//test that checks just sinks and source in a domain +TEST_F(CAmRouterTest,simpleRoute2withDomain) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFree) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFreeNotFree) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am_Connection_s connection,connection1; + am_connectionID_t id1,id2; + connection.sourceID=sourceID; + connection.sinkID=gwSinkID; + connection.connectionFormat=CF_GENIVI_ANALOG; + connection.connectionID=0; + connection1.sourceID=gwSourceID; + connection1.sinkID=sinkID; + connection1.connectionFormat=CF_GENIVI_ANALOG; + connection1.connectionID=0; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(0, listRoutes.size()); + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_2) +{ + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[1]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_1) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways +TEST_F(CAmRouterTest,simpleRoute4Domains2Routes) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource3.domainID = domainID3; + gwSource3.name = "gwsource4"; + gwSource3.sourceState = SS_OFF; + gwSource3.sourceID = 0; + gwSource3.sourceClassID = 5; + gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink3.domainID = domainID2; + gwSink3.name = "gwSink3"; + gwSink3.sinkID = 0; + gwSink3.sinkClassID = 5; + gwSink3.muteState = MS_MUTED; + gwSink3.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3)); + + am_Gateway_s gateway, gateway1, gateway2, gateway3; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + gateway3.controlDomainID = domainID2; + gateway3.gatewayID = 0; + gateway3.sinkID = gwSinkID3; + gateway3.sourceID = gwSourceID3; + gateway3.domainSourceID = domainID3; + gateway3.domainSinkID = domainID2; + gateway3.listSinkFormats = gwSink3.listConnectionFormats; + gateway3.listSourceFormats = gwSource3.listConnectionFormats; + gateway3.convertionMatrix.push_back(true); + gateway3.name = "gateway3"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3)); + + std::vector listRoutes; + std::vector listRoutingElements, listRoutingElements1; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + am_RoutingElement_s hopp2alt; + am_RoutingElement_s hopp3alt; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + hopp2alt.sourceID = gwSourceID; + hopp2alt.sinkID = gwSinkID3; + hopp2alt.domainID = domainID2; + hopp2alt.connectionFormat = gwSink3.listConnectionFormats[0]; + + hopp3alt.sourceID = gwSourceID3; + hopp3alt.sinkID = gwSinkID2; + hopp3alt.domainID = domainID3; + hopp3alt.connectionFormat = gwSink2.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + listRoutingElements1.push_back(hopp1); + listRoutingElements1.push_back(hopp2alt); + listRoutingElements1.push_back(hopp3alt); + listRoutingElements1.push_back(hopp4); + + am_Route_s compareRoute, compareRoute1; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(2, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])); +} + +//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. +TEST_F(CAmRouterTest,simpleRoute3DomainsNoConnection) +{ + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(0, listRoutes.size()); +} +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2Domains) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source but the connectionformat of source +TEST_F(CAmRouterTest,simpleRoute2DomainsNoMatchConnectionFormats) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(0, listRoutes.size()); +} + +//test that checks 3 domains, one sink one source. +TEST_F(CAmRouterTest,simpleRoute3Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 4 domains, one sink and one source. +TEST_F(CAmRouterTest,simpleRoute4Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(1, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +int main(int argc, char **argv) +{ + CAmDltWrapper::instance()->registerApp("routing", "CAmRouterTest"); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h new file mode 100644 index 0000000..53788be --- /dev/null +++ b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h @@ -0,0 +1,83 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file databasetest.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef DATABASETEST_H_ +#define DATABASETEST_H_ + +#define UNIT_TEST 1 + +#include +#include + +#include +#include +#include +#include +#include "CAmDatabaseHandler.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "shared/CAmSocketHandler.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" + +namespace am +{ + +class CAmRouterTest: public ::testing::Test +{ +public: + CAmRouterTest(); + ~CAmRouterTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandler pDatabaseHandler; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmCommandSend pMockInterface; + MockIAmControlSend pMockControlInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + + void createMainConnectionSetup(); +}; + +} + +#endif /* DATABASETEST_H_ */ diff --git a/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt new file mode 100644 index 0000000..3c06729 --- /dev/null +++ b/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt @@ -0,0 +1,81 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger DatbaseTest +# +# \file CMakeLists.txt +# +# \date 20-Oct-2011 3:42:04 PM +# \author Christian Mueller (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 Mueller 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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmRouterTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(SQLITE REQUIRED sqlite3) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB ROUTING_SRCS_CXX + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmControlReceiver.cpp" + "../../src/CAmControlSender.cpp" + "../../src/CAmRouter.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmCommandReceiver.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmRouterTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${GTEST_LIBRARIES} + gmock +) + +INSTALL(TARGETS AmRouterTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp new file mode 100644 index 0000000..3e8cd21 --- /dev/null +++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -0,0 +1,439 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file routingInterfaces.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmRoutingInterfaceTest.h" +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pDatabaseHandler(std::string(":memory:")), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pControlSender(""), // + pRouter(&pDatabaseHandler, &pControlSender), // + pMockInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender); + pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock"); + pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender); +} + +CAmRoutingInterfaceTest::~CAmRoutingInterfaceTest() +{ +} + +void CAmRoutingInterfaceTest::SetUp() +{ + logInfo("RoutingSendInterface Test started "); + +} + +void CAmRoutingInterfaceTest::TearDown() +{ +} + +TEST_F(CAmRoutingInterfaceTest,abort) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //start a connect, expect a call on the routingInterface + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + + //check the correctness of the handle + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); + + //the handle must be inside the handlelist + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); + + //send an abort expect a call on the routing interface + EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.abortAction(handle)); + + //the reaction on the abort is specific for every function + + //now we try to abort a handle that does not exist + handle.handle = 24; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); +} + +TEST_F(CAmRoutingInterfaceTest,abortNonExistent) +{ + EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0); + am_Handle_s handle; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); +} + +TEST_F(CAmRoutingInterfaceTest,alreadyConnected) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + am_Handle_s handle; + am_connectionID_t connectionID; + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkSoundPropertyNoChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_EXAMPLE_TREBLE; + soundProperty.value = 23; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + sink.listSoundProperties.push_back(soundProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).Times(0); + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceState) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + handle.handle = 0; + am_SourceState_e state = SS_PAUSED; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,sourceID,state)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCESTATE); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceSoundProperty) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + std::vector listHandles; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,sourceID,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCESOUNDPROPERTY); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkSoundProperty) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSINKSOUNDPROPERTY); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceVolumeNoChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_RampType_e rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector listHandles; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + source.volume = volume; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).Times(0); + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime)); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles.empty()); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceVolume) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_RampType_e rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector listHandles; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCEVOLUME); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkVolumeNoChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_RampType_e rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + sink.volume = volume; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).Times(0); + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime)); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles.empty()); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_RampType_e rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSINKVOLUME); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,connect) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,disconnect) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = 1; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,connectionID)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_DISCONNECT); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[1].handle==handle.handle); + ASSERT_TRUE(listHandles[1].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,nothingTodisconnect) +{ + am_Handle_s handle; + am_connectionID_t connectionID = 4; + std::vector listHandles; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,connectionID)); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles.empty()); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceStateNoChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + handle.handle = 0; + am_SourceState_e state = SS_PAUSED; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.domainID = 1; + source.sourceState = state; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).Times(0); + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,sourceID,state)); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h new file mode 100644 index 0000000..a66599d --- /dev/null +++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file routingInterfaces.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include +#include +#include +#include +#include +#include +#include "CAmDatabaseHandler.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRouter.h" +#include "../IAmRoutingBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmRoutingSend.h" +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +class CAmRoutingInterfaceTest: public ::testing::Test +{ +public: + CAmRoutingInterfaceTest(); + ~CAmRoutingInterfaceTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandler pDatabaseHandler; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + CAmControlSender pControlSender; + CAmRouter pRouter; + MockIAmRoutingSend pMockInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); +}; + +} + +#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..ac87e8d --- /dev/null +++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt @@ -0,0 +1,84 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger AmRoutingInterfaceTest +# +# \file CMakeLists.txt +# +# \date 20-Oct-2011 3:42:04 PM +# \author Christian Mueller (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 Mueller 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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmRoutingInterfaceTest) + +#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(SQLITE REQUIRED sqlite3) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB ROUTING_INTERFACE_SRCS_CXX + "../../src/CAmControlReceiver.cpp" + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmRouter.cpp" + "../../src/CAmControlSender.cpp" + "../CAmCommonFunctions.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmCommandReceiver.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${GTEST_LIBRARIES} + gmock +) + +INSTALL(TARGETS AmRoutingInterfaceTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + + + diff --git a/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp new file mode 100644 index 0000000..b0b5639 --- /dev/null +++ b/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp @@ -0,0 +1,367 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file sockethandlerTest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmSocketHandlerTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared/CAmSocketHandler.h" + +//todo: expand test, implement more usecases +//todo: test removeFD + +#define SOCK_PATH "/tmp/mysock" + +using namespace testing; +using namespace am; + +CAmSocketHandlerTest::CAmSocketHandlerTest() +{ +} + +CAmSocketHandlerTest::~CAmSocketHandlerTest() +{ +} + +CAmTimerCb::CAmTimerCb(CAmSocketHandler *myHandler) : + pTimer1Callback(this, &CAmTimerCb::timer1Callback), // + pTimer2Callback(this, &CAmTimerCb::timer2Callback), // + pTimer3Callback(this, &CAmTimerCb::timer3Callback), // + pTimer4Callback(this, &CAmTimerCb::timer4Callback), // + mSocketHandler(myHandler) + +{ +} + +am::CAmTimerCb::~CAmTimerCb() +{ +} + +void am::CAmTimerCb::timer1Callback(sh_timerHandle_t handle, void* userData) +{ + (void) handle; + (void) userData; + std::cout << "callback1 called" << std::endl; + timespec timeout; + timeout.tv_nsec = 0; + timeout.tv_sec = 1; + CAmShTimerCallBack *buf = &pTimer1Callback; + sh_timerHandle_t handle_; + mSocketHandler->addTimer(timeout, buf, handle_, NULL); +} + +void am::CAmTimerCb::timer2Callback(sh_timerHandle_t handle, void* userData) +{ + (void) handle; + (void) userData; + std::cout << "callback2 called" << std::endl; + timespec timeout; + timeout.tv_nsec = 0; + timeout.tv_sec = 1; + CAmShTimerCallBack *buf = &pTimer2Callback; + sh_timerHandle_t handle_; + mSocketHandler->addTimer(timeout, buf, handle_, NULL); +} + +void am::CAmTimerCb::timer3Callback(sh_timerHandle_t, void* userData) +{ + (void) userData; + std::cout << "callback3 called" << std::endl; +} + +void am::CAmTimerCb::timer4Callback(sh_timerHandle_t, void* userData) +{ + (void) userData; + std::cout << "callback4 called" << std::endl; + mSocketHandler->stop_listening(); +} + +void* playWithSocketServer(void* data) +{ + (void) data; + CAmSocketHandler myHandler; + CAmSamplePlugin::sockType_e type = CAmSamplePlugin::INET; + CAmSamplePlugin myplugin(&myHandler, type); + myHandler.start_listenting(); + return (NULL); +} + +void* playWithUnixSocketServer(void* data) +{ + (void) data; + CAmSocketHandler myHandler; + CAmSamplePlugin::sockType_e type = CAmSamplePlugin::UNIX; + CAmSamplePlugin myplugin(&myHandler, type); + myHandler.start_listenting(); + return (NULL); +} + +TEST(CAmSocketHandlerTest,playWithUNIXSockets) +{ + pthread_t serverThread; + struct sockaddr_un servAddr; + int socket_; + + //creates a thread that handles the serverpart + pthread_create(&serverThread, NULL, playWithUnixSocketServer, NULL); + + sleep(1); //we need that here because the port needs to be opened + if ((socket_ = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + std::cout << "socket problem" << std::endl; + + } + + memset(&servAddr, 0, sizeof(servAddr)); + strcpy(servAddr.sun_path, SOCK_PATH); + servAddr.sun_family = AF_UNIX; + if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + std::cout << "ERROR: connect() failed\n" << std::endl; + } + + for (int i = 0; i <= 1000; i++) + { + std::string string("Got It?"); + send(socket_, string.c_str(), string.size(), 0); + } + std::string string("finish!"); + send(socket_, string.c_str(), string.size(), 0); + + pthread_join(serverThread, NULL); +} + +TEST(CAmSocketHandlerTest,playWithSockets) +{ + pthread_t serverThread; + struct sockaddr_in servAddr; + unsigned short servPort = 6060; + struct hostent *host; + int socket_; + + //creates a thread that handles the serverpart + pthread_create(&serverThread, NULL, playWithSocketServer, NULL); + + sleep(1); //we need that here because the port needs to be opened + if ((socket_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + std::cout << "socket problem" << std::endl; + + } + + if ((host = (struct hostent*) gethostbyname("localhost")) == 0) + { + std::cout << "ERROR: gethostbyname() failed\n" << std::endl; + exit(1); + } + + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); + servAddr.sin_port = htons(servPort); + + if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + std::cout << "ERROR: connect() failed\n" << std::endl; + } + + for (int i = 0; i <= 1000; i++) + { + std::string string("Got It?"); + send(socket_, string.c_str(), string.size(), 0); + } + std::string string("finish!"); + send(socket_, string.c_str(), string.size(), 0); + + pthread_join(serverThread, NULL); +} + +TEST(CAmSocketHandlerTest,playWithTimers) +{ + gDispatchDone = 0; + CAmSocketHandler myHandler; + CAmTimerCb testCallback(&myHandler); + timespec timeoutTime, timeout2, timeout3, timeout4; + timeoutTime.tv_sec = 3; + timeoutTime.tv_nsec = 0; + timeout2.tv_nsec = 0; + timeout2.tv_sec = 1; + timeout3.tv_nsec = 000000000; + timeout3.tv_sec = 2; + timeout4.tv_nsec = 0; + timeout4.tv_sec = 13; + CAmShTimerCallBack* buf = &testCallback.pTimer1Callback; + CAmShTimerCallBack* buf2 = &testCallback.pTimer2Callback; + CAmShTimerCallBack* buf3 = &testCallback.pTimer3Callback; + CAmShTimerCallBack* buf4 = &testCallback.pTimer4Callback; + sh_timerHandle_t handle; + myHandler.addTimer(timeoutTime, buf, handle, NULL); + myHandler.addTimer(timeout2, buf2, handle, NULL); + myHandler.addTimer(timeout3, buf3, handle, NULL); + myHandler.addTimer(timeout4, buf4, handle, NULL); + myHandler.start_listenting(); + +} + +void CAmSocketHandlerTest::SetUp() +{ +} + +void CAmSocketHandlerTest::TearDown() +{ +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +am::CAmSamplePlugin::CAmSamplePlugin(CAmSocketHandler *mySocketHandler, sockType_e socketType) : + connectFiredCB(this, &CAmSamplePlugin::connectSocket), // + receiveFiredCB(this, &CAmSamplePlugin::receiveData), // + sampleDispatchCB(this, &CAmSamplePlugin::dispatchData), // + sampleCheckCB(this, &CAmSamplePlugin::check), // + mSocketHandler(mySocketHandler), // + mConnecthandle(), // + mReceiveHandle(), // + msgList() +{ + int yes = 1; + + int socketHandle; + struct sockaddr_in servAddr; + struct sockaddr_un unixAddr; + unsigned int servPort = 6060; + + switch (socketType) + { + case UNIX: + socketHandle = socket(AF_UNIX, SOCK_STREAM, 0); + unixAddr.sun_family = AF_UNIX; + strcpy(unixAddr.sun_path, SOCK_PATH); + unlink(unixAddr.sun_path); + bind(socketHandle, (struct sockaddr *) &unixAddr, strlen(unixAddr.sun_path) + sizeof(unixAddr.sun_family)); + break; + case INET: + socketHandle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + setsockopt(socketHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = INADDR_ANY; + servAddr.sin_port = htons(servPort); + bind(socketHandle, (struct sockaddr *) &servAddr, sizeof(servAddr)); + break; + default: + break; + } + + if (listen(socketHandle, 3) < 0) + { + std::cout << "listen ok" << std::endl; + } /* if */ + + int a = 1; + ioctl(socketHandle, FIONBIO, (char *) &a); + setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof(a)); + + short events = 0; + events |= POLLIN; + mySocketHandler->addFDPoll(socketHandle, events, NULL, &connectFiredCB, NULL, NULL, NULL, mConnecthandle); + std::cout << "setup server - listening" << std::endl; +} + +void am::CAmSamplePlugin::connectSocket(const pollfd pollfd1, const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //first, accept the connection, create a new filedescriptor + std::cout << "Got a connection request !" << std::endl; + struct sockaddr answer; + socklen_t len = sizeof(answer); + int receiveFD = accept(pollfd1.fd, (struct sockaddr*) &answer, &len); + + //set the correct event: + short event = 0; + event |= POLLIN; + + //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data + mSocketHandler->addFDPoll(receiveFD, event, NULL, &receiveFiredCB, &sampleCheckCB, &sampleDispatchCB, NULL, mReceiveHandle); + +} + +void am::CAmSamplePlugin::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //initialize buffer + char buffer[10]; + //read until buffer is full or no more data is there + int read = recv(pollfd.fd, buffer, 7, NULL); + if (read > 1) + { + //read the message and store it in a queue + std::string msg = std::string(buffer, read); + msgList.push(msg); + std::cout << "Got a message !" << std::endl; + } +} + +bool am::CAmSamplePlugin::dispatchData(const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //read data from the queue + std::cout << "Data:" << msgList.front() << std::endl; + + //if the message was our finish message, we quit the poll loop + if (msgList.front().compare("finish!") == 0) + { + mSocketHandler->stop_listening(); + } + //remove the message from the queue and return false if there is no more message to read. + msgList.pop(); + if (msgList.size() != 0) + return true; + return false; +} + +bool am::CAmSamplePlugin::check(const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + //checks if there is data to dispatch + std::cout << "check!:" << std::endl; + if (msgList.size() != 0) + return true; + return false; +} + diff --git a/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h b/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h new file mode 100644 index 0000000..f45376e --- /dev/null +++ b/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file sockethandlerTest.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef SOCKETHANDLERTEST_H_ +#define SOCKETHANDLERTEST_H_ + +#include +#include +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +class CAmSamplePlugin +{ +public: + enum sockType_e + { + UNIX, INET + }; + CAmSamplePlugin(CAmSocketHandler *mySocketHandler, sockType_e socketType); + ~CAmSamplePlugin() + { + } + ; + void connectSocket(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); + void receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); + bool dispatchData(const sh_pollHandle_t handle, void* userData); + bool check(const sh_pollHandle_t handle, void* userData); + TAmShPollFired connectFiredCB; + TAmShPollFired receiveFiredCB; + TAmShPollDispatch sampleDispatchCB; + TAmShPollCheck sampleCheckCB; +private: + CAmSocketHandler *mSocketHandler; + sh_pollHandle_t mConnecthandle, mReceiveHandle; + std::queue msgList; +}; + +class CAmTimerCb +{ +public: + CAmTimerCb(CAmSocketHandler *SocketHandler); + virtual ~CAmTimerCb(); + void timer1Callback(sh_timerHandle_t handle, void * userData); + void timer2Callback(sh_timerHandle_t handle, void * userData); + void timer3Callback(sh_timerHandle_t handle, void * userData); + void timer4Callback(sh_timerHandle_t handle, void * userData); + TAmShTimerCallBack pTimer1Callback; + TAmShTimerCallBack pTimer2Callback; + TAmShTimerCallBack pTimer3Callback; + TAmShTimerCallBack pTimer4Callback; + CAmSocketHandler *mSocketHandler; +}; + +class CAmSocketHandlerTest: public ::testing::Test +{ +public: + CAmSocketHandlerTest(); + ~CAmSocketHandlerTest(); + void SetUp(); + void TearDown(); +}; + +} /* namespace am */ +#endif /* SOCKETHANDLERTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt new file mode 100644 index 0000000..692b903 --- /dev/null +++ b/AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt @@ -0,0 +1,78 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger ControlInterfaceTest +# +# \file CMakeLists.txt +# +# \date 20-Oct-2011 3:42:04 PM +# \author Christian Mueller (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 Mueller 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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmSocketHandlerTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +set(STD_INCLUDE_DIRS "/usr/include") +set(DBUS_FOLDER ${CMAKE_SOURCE_DIR}/../../../dbusInterfaces) +set(AUDIO_include_FOLDER ${CMAKE_SOURCE_DIR}/../../../include) +set(DBUS_include_FOLDER ${CMAKE_SOURCE_DIR}/../../../../dbusinclude) +set(include_FOLDER ${CMAKE_SOURCE_DIR}/../../include) + + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB Socket_SRCS_CXX + "../../src/CAmSocketHandler.cpp" + "../../src/CAmDltWrapper.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmSocketHandlerTest ${Socket_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmSocketHandlerTest + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + gtest + gmock +) + +INSTALL(TARGETS AmSocketHandlerTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + + diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp new file mode 100644 index 0000000..2219834 --- /dev/null +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp @@ -0,0 +1,190 @@ +/* + * CAmTelnetServerTest.cpp + * + * Created on: Feb 7, 2012 + * Author: demo + */ + +#include /* for socket(), connect(), (), and recv() */ +#include /* for sockaddr_in and inet_addr() */ +#include /* for struct hostent */ + +#include "CAmTelnetServerTest.h" +#include "CAmCommandReceiver.h" +#include "CAmRoutingReceiver.h" +#include "CAmControlReceiver.h" + + +using namespace testing; +using namespace am; +using namespace std; + + +static std::string controllerPlugin = std::string(CONTROLLER_PLUGIN); +static unsigned short servPort = 6060; +static int staticSocket = -1; +static CAmSocketHandler* mpSocketHandler = NULL; + +void* startSocketHandler(void* data) +{ + CAmEnvironment* Env = static_cast(data); + CAmSocketHandler mySocketHandler; + Env->setSocketHandler(&mySocketHandler); + mySocketHandler.start_listenting(); + Env->setSocketHandler(NULL); + return (NULL); +} + +CAmEnvironment::CAmEnvironment() +: mlistRoutingPluginDirs() +, mlistCommandPluginDirs() +//, mpSocketHandler(NULL) +, mDatabasehandler(std::string(":memory:")) +, mRoutingSender(mlistRoutingPluginDirs) +, mCommandSender(mlistRoutingPluginDirs) +, mControlSender(controllerPlugin) +, mRouter(&mDatabasehandler,&mControlSender) +, mpCommandReceiver(NULL) +, mpRoutingReceiver(NULL) +, mpControlReceiver(NULL) +, mpTelnetServer(NULL) +, mSocketHandlerThread(0) +{ +} + +CAmEnvironment::~CAmEnvironment() +{ + usleep(500); + if(NULL != mpTelnetServer) + delete(mpTelnetServer); + if(NULL != mpControlReceiver) + delete(mpControlReceiver); + if(NULL != mpRoutingReceiver) + delete(mpRoutingReceiver); + if(NULL != mpCommandReceiver) + delete(mpCommandReceiver); +} + +void CAmEnvironment::SetUp() +{ + pthread_create(&mSocketHandlerThread, NULL, startSocketHandler, this); + sleep(1); +} + +void CAmEnvironment::TearDown() +{ + +} + +void CAmEnvironment::setSocketHandler(CAmSocketHandler* pSocketHandler) +{ + mpSocketHandler = pSocketHandler; + + if(NULL != pSocketHandler) + { + mpCommandReceiver = new CAmCommandReceiver(&mDatabasehandler,&mControlSender,mpSocketHandler); + mpRoutingReceiver = new CAmRoutingReceiver(&mDatabasehandler,&mRoutingSender,&mControlSender,mpSocketHandler); + mpControlReceiver = new CAmControlReceiver(&mDatabasehandler,&mRoutingSender,&mCommandSender,mpSocketHandler,&mRouter); + + //startup all the Plugins and Interfaces + mControlSender.startupController(mpControlReceiver); + mCommandSender.startupInterfaces(mpCommandReceiver); + mRoutingSender.startupInterfaces(mpRoutingReceiver); + + //when the routingInterface is done, all plugins are loaded: + mControlSender.setControllerReady(); + + // Starting TelnetServer + mpTelnetServer = new CAmTelnetServer(mpSocketHandler,&mCommandSender,mpCommandReceiver,&mRoutingSender,mpRoutingReceiver,&mControlSender,mpControlReceiver,&mDatabasehandler,&mRouter,servPort,3); + } +} + +void CAmEnvironment::stopSocketHandler() +{ + mpSocketHandler->stop_listening(); +} + +CAmTelnetServerTest::CAmTelnetServerTest() +{ + +} + +CAmTelnetServerTest::~CAmTelnetServerTest() +{ + +} + +void CAmTelnetServerTest::SetUp() +{ + +} + +void CAmTelnetServerTest::TearDown() +{ + +} + +TEST_F(CAmTelnetServerTest,connectTelnetServer) +{ + struct sockaddr_in servAddr; + + staticSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + ASSERT_GE(staticSocket,0); + + struct hostent *host = (struct hostent*) gethostbyname("localhost"); + if (host == 0) + { + std::cout << " ERROR: gethostbyname() failed\n" << std::endl; + return; + } + + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); + servAddr.sin_port = htons(servPort); + + int return_connect = connect(staticSocket, (struct sockaddr *) &servAddr, sizeof(servAddr)); + ASSERT_GE(return_connect,0); + + char buffer[1000]; + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); +} + +TEST_F(CAmTelnetServerTest,sendCmdTelnetServer) +{ + std::string string("help"); + + ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); + ASSERT_EQ(sizesent,string.size()); + + char buffer[1000]; + memset(buffer,0,sizeof(buffer)); + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); +} + +TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) +{ + std::string string ("exit"); + + mpSocketHandler->stop_listening(); + + ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); + ASSERT_EQ(sizesent,string.size()); + + char buffer[1000]; + memset(buffer,0,sizeof(buffer)); + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); + + close(staticSocket); + staticSocket = -1; +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new CAmEnvironment); + (void) env; + return RUN_ALL_TESTS(); +} diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h new file mode 100644 index 0000000..7a87e68 --- /dev/null +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h @@ -0,0 +1,87 @@ +/* + * CAmTelnetServerTest.h + * + * Created on: Feb 7, 2012 + * Author: Frank Herchet + */ + +#ifndef CAMTELNETSERVERTEST_H_ +#define CAMTELNETSERVERTEST_H_ + +#include "gtest/gtest.h" +#include "CAmTelnetServer.h" +#include "CAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "CAmCommandSender.h" +#include "CAmControlSender.h" +#include "CAmRouter.h" + +namespace am +{ + +class CAmSocketHandler; +class CAmDatabaseHandler; +class CAmRoutingSender; +class CAmCommandSender; +class CAmControlSender; +class CAmRouter; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; +class CAmTelnetServer; + + +class CAmEnvironment : public ::testing::Environment +{ + public: + CAmEnvironment(); + + ~CAmEnvironment(); + // Override this to define how to set up the environment. + void SetUp(); + // Override this to define how to tear down the environment. + void TearDown(); + + void setSocketHandler(CAmSocketHandler* pSocketHandler); + + void stopSocketHandler(); + + std::vector mlistRoutingPluginDirs; + std::vector mlistCommandPluginDirs; + + //SocketHandler* mpSocketHandler; + CAmDatabaseHandler mDatabasehandler; + CAmRoutingSender mRoutingSender; + CAmCommandSender mCommandSender; + CAmControlSender mControlSender; + CAmRouter mRouter; + + CAmCommandReceiver* mpCommandReceiver; + CAmRoutingReceiver* mpRoutingReceiver; + CAmControlReceiver* mpControlReceiver; + + CAmTelnetServer* mpTelnetServer; + + pthread_t mSocketHandlerThread; +}; + +class CAmTelnetServerTest : public ::testing::Test +{ + public: + CAmTelnetServerTest(); + ~CAmTelnetServerTest(); + + + void SetUp() ; + + void TearDown() ; + + //int mSocket; +}; + +} + + + + +#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt new file mode 100644 index 0000000..c70ec2d --- /dev/null +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt @@ -0,0 +1,92 @@ +# +# Copyright (C) 2011, BMW AG +# +# GeniviAudioMananger ControlInterfaceTest +# +# \file CMakeLists.txt +# +# \date 13-Feb-2012 +# \author Frank Herchet (frank.fh.herchet@bmw.de) +# +# \section License +# GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause) +# Copyright (C) 2012, BMW AG Frank Herchet frank.fh.herchet@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 . +# 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. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmTelnetServerTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +set(STD_INCLUDE_DIRS "/usr/include") +set(DBUS_FOLDER ${CMAKE_SOURCE_DIR}/../../../dbusInterfaces) +set(AUDIO_include_FOLDER ${CMAKE_SOURCE_DIR}/../../../include) +set(DBUS_include_FOLDER ${CMAKE_SOURCE_DIR}/../../../../dbusinclude) +set(include_FOLDER ${CMAKE_SOURCE_DIR}/../../include) + + +FIND_PACKAGE(PkgConfig) +pkg_check_modules(DLT REQUIRED automotive-dlt) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_include_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_include_FOLDER} + ${CMAKE_SOURCE_DIR} + ${STD_INCLUDE_DIRS} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${GTEST_INCLUDE_DIR} + ${include_FOLDER} +) + +file(GLOB TELNET_SRCS_CXX + "../../src/CAmCommandReceiver.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmControlReceiver.cpp" + "../../src/CAmControlSender.cpp" + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmTelnetServer.cpp" + "../../src/CAmRouter.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmTelnetMenuHelper.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmTelnetServerTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_THREAD_LIBS_INIT} + ${GTEST_LIBRARIES} + gmock +) + +INSTALL(TARGETS AmTelnetServerTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +SET(ADD_DEPEND "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + + diff --git a/AudioManagerDaemon/test/CAmCommonFunctions.cpp b/AudioManagerDaemon/test/CAmCommonFunctions.cpp new file mode 100644 index 0000000..5136e59 --- /dev/null +++ b/AudioManagerDaemon/test/CAmCommonFunctions.cpp @@ -0,0 +1,328 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmCommonFunctions.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmCommonFunctions.h" +#include "IAmCommandBackdoor.h" +#include "IAmRoutingBackdoor.h" +#include "IAmControlBackdoor.h" +#include +#include + +using namespace am; + +IAmCommandBackdoor::IAmCommandBackdoor() +{ +} +IAmCommandBackdoor::~IAmCommandBackdoor() +{ +} + +bool IAmCommandBackdoor::unloadPlugins(CAmCommandSender *CommandSender) +{ + assert(CommandSender != NULL); + CommandSender->unloadLibraries(); + CommandSender->mListInterfaces.clear(); + if (CommandSender->mListInterfaces.empty()) + return true; + return false; +} + +bool IAmCommandBackdoor::injectInterface(CAmCommandSender *CommandSender, IAmCommandSend *CommandSendInterface) +{ + assert(CommandSender != NULL); + assert(CommandSendInterface != NULL); + CommandSender->mListInterfaces.push_back(CommandSendInterface); + return true; +} + +IAmRoutingBackdoor::IAmRoutingBackdoor() +{ +} +IAmRoutingBackdoor::~IAmRoutingBackdoor() +{ +} + +bool IAmRoutingBackdoor::unloadPlugins(CAmRoutingSender *RoutingSender) +{ + assert(RoutingSender != NULL); + RoutingSender->unloadLibraries(); + RoutingSender->mListInterfaces.clear(); + if (RoutingSender->mListInterfaces.empty()) + return true; + return false; +} + +bool IAmRoutingBackdoor::injectInterface(CAmRoutingSender *RoutingSender, IAmRoutingSend *newInterface, const std::string& busname) +{ + assert(RoutingSender != NULL); + assert(newInterface != NULL); + + CAmRoutingSender::InterfaceNamePairs newInterfacePair; + newInterfacePair.routingInterface = newInterface; + newInterfacePair.busName = busname; + RoutingSender->mListInterfaces.push_back(newInterfacePair); + return true; +} + +IAmControlBackdoor::IAmControlBackdoor() +{ +} + +IAmControlBackdoor::~IAmControlBackdoor() +{ +} + +bool IAmControlBackdoor::replaceController(CAmControlSender *controlSender, IAmControlSend *newController) +{ + controlSender->mController = newController; + return true; +} + +//int GetRandomNumber(int nLow, int nHigh) { +// return (rand() % (nHigh - nLow + 1)) + nLow; +//} + +bool equalSoundProperty(const am_SoundProperty_s a, const am_SoundProperty_s b) +{ + return (a.type == b.type && a.value == b.value); +} + +bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b) +{ + return (a.type == b.type && a.value == b.value); +} + +bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b) +{ + return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID && a.sinkID == b.sinkID && a.sourceID == b.sourceID); +} + +bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b) +{ + return (a.classProperty == b.classProperty && a.value == b.value); +} + +std::string int2string(int i) +{ + std::stringstream out; + out << i; + return out.str(); +} + +bool CAmCommonFunctions::compareSource(std::vector::iterator listIterator, const am_Source_s& sourceData) +{ + return (listIterator->available.availability == sourceData.available.availability) && (listIterator->available.availabilityReason == sourceData.available.availabilityReason) && (listIterator->sourceClassID == sourceData.sourceClassID) && (listIterator->domainID == sourceData.domainID) && (listIterator->interruptState == sourceData.interruptState) && (listIterator->visible == sourceData.visible) && (listIterator->name.compare(sourceData.name) == 0) && (listIterator->volume == sourceData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) + && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sourceData.listSoundProperties.begin(), equalSoundProperty); +} + +bool CAmCommonFunctions::compareSink(std::vector::iterator listIterator, const am_Sink_s& sinkData) +{ + return (listIterator->available.availability == sinkData.available.availability) && (listIterator->available.availabilityReason == sinkData.available.availabilityReason) && (listIterator->sinkClassID == sinkData.sinkClassID) && (listIterator->domainID == sinkData.domainID) && (listIterator->mainVolume == sinkData.mainVolume) && (listIterator->muteState == sinkData.muteState) && (listIterator->visible == sinkData.visible) && (listIterator->name.compare(sinkData.name) == 0) && (listIterator->volume == sinkData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sinkData.listConnectionFormats.begin()) + && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sinkData.listSoundProperties.begin(), equalSoundProperty); +} + +bool CAmCommonFunctions::compareGateway(std::vector::iterator listIterator, const am_Gateway_s& gatewayData) +{ + return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->controlDomainID == gatewayData.controlDomainID) && (listIterator->domainSinkID == gatewayData.domainSinkID) && (listIterator->domainSourceID == gatewayData.domainSourceID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData) +{ + return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.controlDomainID == gatewayData.controlDomainID) && (gateway1.domainSinkID == gatewayData.domainSinkID) && (gateway1.domainSourceID == gatewayData.domainSourceID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareSinkMainSink(std::vector::iterator listIterator, const std::vector& sinkList) +{ + std::vector::const_iterator sinkListIterator = sinkList.begin(); + for (; sinkListIterator < sinkList.end(); ++sinkListIterator) + { + if (listIterator->sinkID == sinkListIterator->sinkID) + { + return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->muteState == sinkListIterator->muteState) && (listIterator->volume == sinkListIterator->mainVolume) && (listIterator->sinkClassID == sinkListIterator->sinkClassID); + } + } + return false; +} + +bool CAmCommonFunctions::compareSinkMainSource(std::vector::iterator listIterator, const std::vector& sourceList) +{ + std::vector::const_iterator sinkListIterator = sourceList.begin(); + for (; sinkListIterator < sourceList.end(); ++sinkListIterator) + { + if (listIterator->sourceID == sinkListIterator->sourceID) + { + return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->sourceClassID == sinkListIterator->sourceClassID); + } + } + return false; +} + +bool CAmCommonFunctions::compareRoute(am_Route_s a, am_Route_s b) +{ + bool retVal = true; + std::vector::iterator itA = a.route.begin(), itB = b.route.begin(); + retVal &= a.sourceID == b.sourceID; + retVal &= a.sinkID == b.sinkID; + for (; itA != a.route.end(); ++itA) + { + retVal &= itA->sinkID == itB->sinkID; + retVal &= itA->sourceID == itB->sourceID; + retVal &= itA->connectionFormat == itB->connectionFormat; + retVal &= itA->domainID == itB->domainID; + itB++; + } + return retVal; +} + +std::vector CAmCommonFunctions::getStandardConnectionFormatList() +{ + std::vector list; + list.push_back(CF_GENIVI_ANALOG); + list.push_back(CF_GENIVI_STEREO); + return list; +} + +std::vector CAmCommonFunctions::getStandardSoundPropertyList() +{ + std::vector soundPropertyList; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_EXAMPLE_BASS; + soundProperty.value = 23; + soundPropertyList.push_back(soundProperty); + soundProperty.type = SP_EXAMPLE_MID; + soundProperty.value = 2; + soundPropertyList.push_back(soundProperty); + return soundPropertyList; +} + +std::vector CAmCommonFunctions::getStandardMainSoundPropertyList() +{ + std::vector mainSoundPropertyList; + am_MainSoundProperty_s mainSoundProperty; + mainSoundProperty.type = MSP_UNKNOWN; + mainSoundProperty.value = 23; + mainSoundPropertyList.push_back(mainSoundProperty); + mainSoundProperty.type = MSP_UNKNOWN; + mainSoundProperty.value = 3; + mainSoundPropertyList.push_back(mainSoundProperty); + return mainSoundPropertyList; +} + +void CAmCommonFunctions::createSink(am_Sink_s& sink) const +{ + sink.name = "AnySink"; + sink.domainID = 4; + sink.available.availability = A_AVAILABLE; + sink.available.availabilityReason = AR_GENIVI_NEWMEDIA; + sink.sinkClassID = 1; + sink.listConnectionFormats = getStandardConnectionFormatList(); + sink.listSoundProperties = getStandardSoundPropertyList(); + sink.listMainSoundProperties = getStandardMainSoundPropertyList(); + sink.mainVolume = 12; + sink.muteState = MS_UNMUTED; + sink.visible = true; + sink.volume = 23; + sink.sinkID = 0; +} + +void CAmCommonFunctions::createSource(am_Source_s& source) const +{ + source.name = "AnySource"; + source.domainID = 4; + source.available.availability = A_AVAILABLE; + source.available.availabilityReason = AR_GENIVI_NEWMEDIA; + source.sourceClassID = 1; + source.listConnectionFormats = getStandardConnectionFormatList(); + source.listSoundProperties = getStandardSoundPropertyList(); + source.listMainSoundProperties = getStandardMainSoundPropertyList(); + source.interruptState = IS_OFF; + source.visible = true; + source.volume = 23; + source.sourceID = 0; + source.sourceState = SS_ON; +} + +void CAmCommonFunctions::createDomain(am_Domain_s & domain) const +{ + + domain.domainID = 0; + domain.name = "AnyDomain"; + domain.nodename = "AnyNode"; + domain.busname = "AnyBusname"; + domain.complete = true; + domain.early = true; + domain.state = DS_CONTROLLED; +} + +void CAmCommonFunctions::createGateway(am_Gateway_s & gateway) +{ + gateway.name = "AnyGateway"; + gateway.sinkID = 1; + gateway.sourceID = 2; + gateway.controlDomainID = 1; + gateway.domainSinkID = 3; + gateway.domainSourceID = 4; + gateway.convertionMatrix = getStandardConvertionMatrix(); + gateway.listSourceFormats = getStandardConnectionFormatList(); + gateway.listSinkFormats = getStandardConnectionFormatList(); + gateway.gatewayID = 0; + +} + +void CAmCommonFunctions::createConnection(am_Connection_s & connection) const +{ + connection.connectionID = 0; + connection.sinkID = 1; + connection.sourceID = 2; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; +} + +std::vector CAmCommonFunctions::getStandardConvertionMatrix() +{ + std::vector convMatrix; + convMatrix.push_back(true); + convMatrix.push_back(false); + convMatrix.push_back(true); + convMatrix.push_back(false); + convMatrix.push_back(true); + convMatrix.push_back(true); + return convMatrix; +} + +void CAmCommonFunctions::connectionList2RoutingList(std::vector & routingList, const std::vector& connectionList) +{ + am_RoutingElement_s routingElement; + std::vector::const_iterator cIterator = connectionList.begin(); + for (; cIterator < connectionList.end(); ++cIterator) + { + routingElement.sinkID = cIterator->sinkID; + routingElement.sourceID = cIterator->sourceID; + routingElement.connectionFormat = cIterator->connectionFormat; + routingElement.domainID = 4; //todo: make this test read out the real value + routingList.push_back(routingElement); + } +} + diff --git a/AudioManagerDaemon/test/CAmCommonFunctions.h b/AudioManagerDaemon/test/CAmCommonFunctions.h new file mode 100644 index 0000000..9d6b5e6 --- /dev/null +++ b/AudioManagerDaemon/test/CAmCommonFunctions.h @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file CAmCommonFunctions.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef COMMONHEADERS_H_ +#define COMMONHEADERS_H_ + +#include "audiomanagertypes.h" + +namespace am +{ + +class CAmCommonFunctions +{ +public: + + static std::vector getStandardConnectionFormatList(); + static std::vector getStandardSoundPropertyList(); + static std::vector getStandardMainSoundPropertyList(); + static std::vector getStandardConvertionMatrix(); + bool compareSource(std::vector::iterator listIterator, const am_Source_s& sourceData); + bool compareSink(std::vector::iterator listIterator, const am_Sink_s& sinkData); + bool compareGateway(std::vector::iterator listIterator, const am_Gateway_s& gatewayData); + bool compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData); + bool compareSinkMainSink(std::vector::iterator listIterator, const std::vector& sinkList); + bool compareSinkMainSource(std::vector::iterator listIterator, const std::vector& sourceList); + bool compareRoute(am_Route_s a, am_Route_s b); + void createSink(am_Sink_s& sink) const; + void createSource(am_Source_s& source) const; + void createDomain(am_Domain_s& domain) const; + void createGateway(am_Gateway_s& gateway); + void createConnection(am_Connection_s& connection) const; + void connectionList2RoutingList(std::vector& routingList, const std::vector& connectionList); + + struct sortBySinkID + { + bool operator()(const am_RoutingElement_s & a, const am_RoutingElement_s & b) const + { + return (a.sinkID < b.sinkID); + } + }; + + struct sortByConnectionFormat + { + bool operator()(const am_ConnectionFormat_e & a, const am_ConnectionFormat_e & b) const + { + return (a < b); + } + }; + + struct sortByMainSoundProperty + { + bool operator()(const am_MainSoundProperty_s & a, const am_MainSoundProperty_s & b) const + { + return (a.type > b.type); + } + }; + + struct sortBySoundProperty + { + bool operator()(const am_SoundProperty_s & a, const am_SoundProperty_s & b) const + { + return (a.type < b.type); + } + }; +}; + +} + +#endif /* COMMONHEADERS_H_ */ diff --git a/AudioManagerDaemon/test/CMakeLists.txt b/AudioManagerDaemon/test/CMakeLists.txt index f7243ad..97600a9 100644 --- a/AudioManagerDaemon/test/CMakeLists.txt +++ b/AudioManagerDaemon/test/CMakeLists.txt @@ -27,9 +27,9 @@ cmake_minimum_required(VERSION 2.6) set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) FIND_PACKAGE(GTest REQUIRED) -add_subdirectory (database) -add_subdirectory (routing) -add_subdirectory (routingInterface) -add_subdirectory (controlInterface) -add_subdirectory (sockethandler) -add_subdirectory (telnetserver) +add_subdirectory (AmControlInterfaceTest) +add_subdirectory (AmDatabaseHandlerTest) +add_subdirectory (AmRouterTest) +add_subdirectory (AmRoutingInterfaceTest) +add_subdirectory (AmSocketHandlerTest) +add_subdirectory (AmTelnetServerTest) diff --git a/AudioManagerDaemon/test/CommandInterfaceBackdoor.h b/AudioManagerDaemon/test/CommandInterfaceBackdoor.h deleted file mode 100644 index 5d06fb1..0000000 --- a/AudioManagerDaemon/test/CommandInterfaceBackdoor.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommandInterfaceBackdoor.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef COMMANDINTERFACEBACKDOOR_H_ -#define COMMANDINTERFACEBACKDOOR_H_ - -#include -#include "CommandSender.h" - -namespace am -{ - -class CommandSender; - -class CommandInterfaceBackdoor -{ -public: - CommandInterfaceBackdoor(); - virtual ~CommandInterfaceBackdoor(); - bool unloadPlugins(CommandSender *CommandSender); - bool injectInterface(CommandSender* CommandSender, CommandSendInterface* CommandSendInterface); -}; - -} - -//definitions are in CommonFunctions.cpp! - -#endif /* COMMANDINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/CommonFunctions.cpp b/AudioManagerDaemon/test/CommonFunctions.cpp deleted file mode 100644 index 101548c..0000000 --- a/AudioManagerDaemon/test/CommonFunctions.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommonFunctions.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "CommonFunctions.h" -#include "CommandInterfaceBackdoor.h" -#include "RoutingInterfaceBackdoor.h" -#include "ControlInterfaceBackdoor.h" -#include -#include - -using namespace am; - -CommandInterfaceBackdoor::CommandInterfaceBackdoor() -{ -} -CommandInterfaceBackdoor::~CommandInterfaceBackdoor() -{ -} - -bool CommandInterfaceBackdoor::unloadPlugins(CommandSender *CommandSender) -{ - assert(CommandSender != NULL); - CommandSender->unloadLibraries(); - CommandSender->mListInterfaces.clear(); - if (CommandSender->mListInterfaces.empty()) - return true; - return false; -} - -bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender, CommandSendInterface *CommandSendInterface) -{ - assert(CommandSender != NULL); - assert(CommandSendInterface != NULL); - CommandSender->mListInterfaces.push_back(CommandSendInterface); - return true; -} - -RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() -{ -} -RoutingInterfaceBackdoor::~RoutingInterfaceBackdoor() -{ -} - -bool RoutingInterfaceBackdoor::unloadPlugins(RoutingSender *RoutingSender) -{ - assert(RoutingSender != NULL); - RoutingSender->unloadLibraries(); - RoutingSender->mListInterfaces.clear(); - if (RoutingSender->mListInterfaces.empty()) - return true; - return false; -} - -bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender, RoutingSendInterface *newInterface, const std::string& busname) -{ - assert(RoutingSender != NULL); - assert(newInterface != NULL); - - RoutingSender::InterfaceNamePairs newInterfacePair; - newInterfacePair.routingInterface = newInterface; - newInterfacePair.busName = busname; - RoutingSender->mListInterfaces.push_back(newInterfacePair); - return true; -} - -ControlInterfaceBackdoor::ControlInterfaceBackdoor() -{ -} - -ControlInterfaceBackdoor::~ControlInterfaceBackdoor() -{ -} - -bool ControlInterfaceBackdoor::replaceController(ControlSender *controlSender, ControlSendInterface *newController) -{ - controlSender->mController = newController; - return true; -} - -//int GetRandomNumber(int nLow, int nHigh) { -// return (rand() % (nHigh - nLow + 1)) + nLow; -//} - -bool equalSoundProperty(const am_SoundProperty_s a, const am_SoundProperty_s b) -{ - return (a.type == b.type && a.value == b.value); -} - -bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b) -{ - return (a.type == b.type && a.value == b.value); -} - -bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b) -{ - return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID && a.sinkID == b.sinkID && a.sourceID == b.sourceID); -} - -bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b) -{ - return (a.classProperty == b.classProperty && a.value == b.value); -} - -std::string int2string(int i) -{ - std::stringstream out; - out << i; - return out.str(); -} - -bool CommonFunctions::compareSource(std::vector::iterator listIterator, const am_Source_s& sourceData) -{ - return (listIterator->available.availability == sourceData.available.availability) && (listIterator->available.availabilityReason == sourceData.available.availabilityReason) && (listIterator->sourceClassID == sourceData.sourceClassID) && (listIterator->domainID == sourceData.domainID) && (listIterator->interruptState == sourceData.interruptState) && (listIterator->visible == sourceData.visible) && (listIterator->name.compare(sourceData.name) == 0) && (listIterator->volume == sourceData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) - && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sourceData.listSoundProperties.begin(), equalSoundProperty); -} - -bool CommonFunctions::compareSink(std::vector::iterator listIterator, const am_Sink_s& sinkData) -{ - return (listIterator->available.availability == sinkData.available.availability) && (listIterator->available.availabilityReason == sinkData.available.availabilityReason) && (listIterator->sinkClassID == sinkData.sinkClassID) && (listIterator->domainID == sinkData.domainID) && (listIterator->mainVolume == sinkData.mainVolume) && (listIterator->muteState == sinkData.muteState) && (listIterator->visible == sinkData.visible) && (listIterator->name.compare(sinkData.name) == 0) && (listIterator->volume == sinkData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sinkData.listConnectionFormats.begin()) - && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sinkData.listSoundProperties.begin(), equalSoundProperty); -} - -bool CommonFunctions::compareGateway(std::vector::iterator listIterator, const am_Gateway_s& gatewayData) -{ - return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->controlDomainID == gatewayData.controlDomainID) && (listIterator->domainSinkID == gatewayData.domainSinkID) && (listIterator->domainSourceID == gatewayData.domainSourceID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin()); -} - -bool CommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData) -{ - return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.controlDomainID == gatewayData.controlDomainID) && (gateway1.domainSinkID == gatewayData.domainSinkID) && (gateway1.domainSourceID == gatewayData.domainSourceID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin()); -} - -bool CommonFunctions::compareSinkMainSink(std::vector::iterator listIterator, const std::vector& sinkList) -{ - std::vector::const_iterator sinkListIterator = sinkList.begin(); - for (; sinkListIterator < sinkList.end(); ++sinkListIterator) - { - if (listIterator->sinkID == sinkListIterator->sinkID) - { - return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->muteState == sinkListIterator->muteState) && (listIterator->volume == sinkListIterator->mainVolume) && (listIterator->sinkClassID == sinkListIterator->sinkClassID); - } - } - return false; -} - -bool CommonFunctions::compareSinkMainSource(std::vector::iterator listIterator, const std::vector& sourceList) -{ - std::vector::const_iterator sinkListIterator = sourceList.begin(); - for (; sinkListIterator < sourceList.end(); ++sinkListIterator) - { - if (listIterator->sourceID == sinkListIterator->sourceID) - { - return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->sourceClassID == sinkListIterator->sourceClassID); - } - } - return false; -} - -bool CommonFunctions::compareRoute(am_Route_s a, am_Route_s b) -{ - bool retVal = true; - std::vector::iterator itA = a.route.begin(), itB = b.route.begin(); - retVal &= a.sourceID == b.sourceID; - retVal &= a.sinkID == b.sinkID; - for (; itA != a.route.end(); ++itA) - { - retVal &= itA->sinkID == itB->sinkID; - retVal &= itA->sourceID == itB->sourceID; - retVal &= itA->connectionFormat == itB->connectionFormat; - retVal &= itA->domainID == itB->domainID; - itB++; - } - return retVal; -} - -std::vector CommonFunctions::getStandardConnectionFormatList() -{ - std::vector list; - list.push_back(CF_GENIVI_ANALOG); - list.push_back(CF_GENIVI_STEREO); - return list; -} - -std::vector CommonFunctions::getStandardSoundPropertyList() -{ - std::vector soundPropertyList; - am_SoundProperty_s soundProperty; - soundProperty.type = SP_EXAMPLE_BASS; - soundProperty.value = 23; - soundPropertyList.push_back(soundProperty); - soundProperty.type = SP_EXAMPLE_MID; - soundProperty.value = 2; - soundPropertyList.push_back(soundProperty); - return soundPropertyList; -} - -std::vector CommonFunctions::getStandardMainSoundPropertyList() -{ - std::vector mainSoundPropertyList; - am_MainSoundProperty_s mainSoundProperty; - mainSoundProperty.type = MSP_UNKNOWN; - mainSoundProperty.value = 23; - mainSoundPropertyList.push_back(mainSoundProperty); - mainSoundProperty.type = MSP_UNKNOWN; - mainSoundProperty.value = 3; - mainSoundPropertyList.push_back(mainSoundProperty); - return mainSoundPropertyList; -} - -void CommonFunctions::createSink(am_Sink_s& sink) const -{ - sink.name = "AnySink"; - sink.domainID = 4; - sink.available.availability = A_AVAILABLE; - sink.available.availabilityReason = AR_GENIVI_NEWMEDIA; - sink.sinkClassID = 1; - sink.listConnectionFormats = getStandardConnectionFormatList(); - sink.listSoundProperties = getStandardSoundPropertyList(); - sink.listMainSoundProperties = getStandardMainSoundPropertyList(); - sink.mainVolume = 12; - sink.muteState = MS_UNMUTED; - sink.visible = true; - sink.volume = 23; - sink.sinkID = 0; -} - -void CommonFunctions::createSource(am_Source_s& source) const -{ - source.name = "AnySource"; - source.domainID = 4; - source.available.availability = A_AVAILABLE; - source.available.availabilityReason = AR_GENIVI_NEWMEDIA; - source.sourceClassID = 1; - source.listConnectionFormats = getStandardConnectionFormatList(); - source.listSoundProperties = getStandardSoundPropertyList(); - source.listMainSoundProperties = getStandardMainSoundPropertyList(); - source.interruptState = IS_OFF; - source.visible = true; - source.volume = 23; - source.sourceID = 0; - source.sourceState = SS_ON; -} - -void CommonFunctions::createDomain(am_Domain_s & domain) const -{ - - domain.domainID = 0; - domain.name = "AnyDomain"; - domain.nodename = "AnyNode"; - domain.busname = "AnyBusname"; - domain.complete = true; - domain.early = true; - domain.state = DS_CONTROLLED; -} - -void CommonFunctions::createGateway(am_Gateway_s & gateway) -{ - gateway.name = "AnyGateway"; - gateway.sinkID = 1; - gateway.sourceID = 2; - gateway.controlDomainID = 1; - gateway.domainSinkID = 3; - gateway.domainSourceID = 4; - gateway.convertionMatrix = getStandardConvertionMatrix(); - gateway.listSourceFormats = getStandardConnectionFormatList(); - gateway.listSinkFormats = getStandardConnectionFormatList(); - gateway.gatewayID = 0; - -} - -void CommonFunctions::createConnection(am_Connection_s & connection) const -{ - connection.connectionID = 0; - connection.sinkID = 1; - connection.sourceID = 2; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; -} - -std::vector CommonFunctions::getStandardConvertionMatrix() -{ - std::vector convMatrix; - convMatrix.push_back(true); - convMatrix.push_back(false); - convMatrix.push_back(true); - convMatrix.push_back(false); - convMatrix.push_back(true); - convMatrix.push_back(true); - return convMatrix; -} - -void CommonFunctions::connectionList2RoutingList(std::vector & routingList, const std::vector& connectionList) -{ - am_RoutingElement_s routingElement; - std::vector::const_iterator cIterator = connectionList.begin(); - for (; cIterator < connectionList.end(); ++cIterator) - { - routingElement.sinkID = cIterator->sinkID; - routingElement.sourceID = cIterator->sourceID; - routingElement.connectionFormat = cIterator->connectionFormat; - routingElement.domainID = 4; //todo: make this test read out the real value - routingList.push_back(routingElement); - } -} - diff --git a/AudioManagerDaemon/test/CommonFunctions.h b/AudioManagerDaemon/test/CommonFunctions.h deleted file mode 100644 index 6e5a996..0000000 --- a/AudioManagerDaemon/test/CommonFunctions.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file CommonFunctions.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef COMMONHEADERS_H_ -#define COMMONHEADERS_H_ - -#include "audiomanagertypes.h" - -namespace am -{ - -class CommonFunctions -{ -public: - - static std::vector getStandardConnectionFormatList(); - static std::vector getStandardSoundPropertyList(); - static std::vector getStandardMainSoundPropertyList(); - static std::vector getStandardConvertionMatrix(); - bool compareSource(std::vector::iterator listIterator, const am_Source_s& sourceData); - bool compareSink(std::vector::iterator listIterator, const am_Sink_s& sinkData); - bool compareGateway(std::vector::iterator listIterator, const am_Gateway_s& gatewayData); - bool compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData); - bool compareSinkMainSink(std::vector::iterator listIterator, const std::vector& sinkList); - bool compareSinkMainSource(std::vector::iterator listIterator, const std::vector& sourceList); - bool compareRoute(am_Route_s a, am_Route_s b); - void createSink(am_Sink_s& sink) const; - void createSource(am_Source_s& source) const; - void createDomain(am_Domain_s& domain) const; - void createGateway(am_Gateway_s& gateway); - void createConnection(am_Connection_s& connection) const; - void connectionList2RoutingList(std::vector& routingList, const std::vector& connectionList); - - struct sortBySinkID - { - bool operator()(const am_RoutingElement_s & a, const am_RoutingElement_s & b) const - { - return (a.sinkID < b.sinkID); - } - }; - - struct sortByConnectionFormat - { - bool operator()(const am_ConnectionFormat_e & a, const am_ConnectionFormat_e & b) const - { - return (a < b); - } - }; - - struct sortByMainSoundProperty - { - bool operator()(const am_MainSoundProperty_s & a, const am_MainSoundProperty_s & b) const - { - return (a.type > b.type); - } - }; - - struct sortBySoundProperty - { - bool operator()(const am_SoundProperty_s & a, const am_SoundProperty_s & b) const - { - return (a.type < b.type); - } - }; -}; - -} - -#endif /* COMMONHEADERS_H_ */ diff --git a/AudioManagerDaemon/test/ControlInterfaceBackdoor.h b/AudioManagerDaemon/test/ControlInterfaceBackdoor.h deleted file mode 100644 index 135bc48..0000000 --- a/AudioManagerDaemon/test/ControlInterfaceBackdoor.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file ControlInterfaceBackdoor.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef CONTROLINTERFACEBACKDOOR_H_ -#define CONTROLINTERFACEBACKDOOR_H_ - -#include "control/ControlSendInterface.h" -#include "ControlSender.h" - -namespace am -{ - -class ControlSender; - -class ControlInterfaceBackdoor -{ -public: - ControlInterfaceBackdoor(); - virtual ~ControlInterfaceBackdoor(); - bool replaceController(ControlSender *controlSender, ControlSendInterface *newController); -}; - -} - -#endif /* CONTROLINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/IAmCommandBackdoor.h b/AudioManagerDaemon/test/IAmCommandBackdoor.h new file mode 100644 index 0000000..650d3e1 --- /dev/null +++ b/AudioManagerDaemon/test/IAmCommandBackdoor.h @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file IAmCommandBackdoor + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef COMMANDINTERFACEBACKDOOR_H_ +#define COMMANDINTERFACEBACKDOOR_H_ + +#include +#include "CAmCommandSender.h" + +namespace am +{ + +class CAmCommandSender; + +class IAmCommandBackdoor +{ +public: + IAmCommandBackdoor(); + virtual ~IAmCommandBackdoor(); + bool unloadPlugins(CAmCommandSender *CommandSender); + bool injectInterface(CAmCommandSender* CommandSender, IAmCommandSend* CommandSendInterface); +}; + +} + +//definitions are in CAmCommonFunctions.cpp! + +#endif /* COMMANDINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/IAmControlBackdoor.h b/AudioManagerDaemon/test/IAmControlBackdoor.h new file mode 100644 index 0000000..90a2c67 --- /dev/null +++ b/AudioManagerDaemon/test/IAmControlBackdoor.h @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file IAmControlBackdoor.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef CONTROLINTERFACEBACKDOOR_H_ +#define CONTROLINTERFACEBACKDOOR_H_ + +#include "control/IAmControlSend.h" +#include "CAmControlSender.h" + +namespace am +{ + +class CAmControlSender; + +class IAmControlBackdoor +{ +public: + IAmControlBackdoor(); + virtual ~IAmControlBackdoor(); + bool replaceController(CAmControlSender *controlSender, IAmControlSend *newController); +}; + +} + +#endif /* CONTROLINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/IAmRoutingBackdoor.h b/AudioManagerDaemon/test/IAmRoutingBackdoor.h new file mode 100644 index 0000000..9ffff54 --- /dev/null +++ b/AudioManagerDaemon/test/IAmRoutingBackdoor.h @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file IAmRoutingBackdoor.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef ROUTINGINTERFACEBACKDOOR_H_ +#define ROUTINGINTERFACEBACKDOOR_H_ + +#include "CAmRoutingSender.h" + +namespace am +{ + +class CAmRoutingSender; + +class IAmRoutingBackdoor +{ +public: + IAmRoutingBackdoor(); + virtual ~IAmRoutingBackdoor(); + bool unloadPlugins(CAmRoutingSender *RoutingSender); + bool injectInterface(CAmRoutingSender *RoutingSender, IAmRoutingSend *newInterface, const std::string& busname); +}; + +} + +//definitions are in CAmCommonFunctions.cpp! + +#endif /* ROUTINGINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/MockIAmCommandSend.h b/AudioManagerDaemon/test/MockIAmCommandSend.h new file mode 100644 index 0000000..1833511 --- /dev/null +++ b/AudioManagerDaemon/test/MockIAmCommandSend.h @@ -0,0 +1,82 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file MockInterfaces.h +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#ifndef MOCKCOMMANDINTERFACE_H_ +#define MOCKCOMMANDINTERFACE_H_ + +#include "command/IAmCommandSend.h" +#include +#include + +namespace am { + +class MockIAmCommandSend : public IAmCommandSend { + public: + MOCK_METHOD1(startupInterface, + am_Error_e(IAmCommandReceive* commandreceiveinterface)); + MOCK_METHOD1(setCommandReady, + void(const uint16_t handle)); + MOCK_METHOD1(setCommandRundown, + void(const uint16_t handle)); + MOCK_METHOD1(cbNewMainConnection, + void(const am_MainConnectionType_s mainConnection)); + MOCK_METHOD1(cbRemovedMainConnection, + void(const am_mainConnectionID_t mainConnection)); + MOCK_METHOD1(cbNewSink, + void(const am_SinkType_s& sink)); + MOCK_METHOD1(cbRemovedSink, + void(const am_sinkID_t sinkID)); + MOCK_METHOD1(cbNewSource, + void(const am_SourceType_s& source)); + MOCK_METHOD1(cbRemovedSource, + void(const am_sourceID_t source)); + MOCK_METHOD0(cbNumberOfSinkClassesChanged, + void()); + MOCK_METHOD0(cbNumberOfSourceClassesChanged, + void()); + MOCK_METHOD2(cbMainConnectionStateChanged, + void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); + MOCK_METHOD2(cbMainSinkSoundPropertyChanged, + void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(cbMainSourceSoundPropertyChanged, + void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(cbSinkAvailabilityChanged, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(cbSourceAvailabilityChanged, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(cbVolumeChanged, + void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); + MOCK_METHOD2(cbSinkMuteStateChanged, + void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD1(cbSystemPropertyChanged, + void(const am_SystemProperty_s& systemProperty)); + MOCK_METHOD2(cbTimingInformationChanged, + void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); +}; + +} // namespace am +#endif /* MOCKCOMMANDINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/MockIAmControlSend.h b/AudioManagerDaemon/test/MockIAmControlSend.h new file mode 100644 index 0000000..dc45fab --- /dev/null +++ b/AudioManagerDaemon/test/MockIAmControlSend.h @@ -0,0 +1,134 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file MockInterfaces.h +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#ifndef MOCKCONTROLINTERFACE_H_ +#define MOCKCONTROLINTERFACE_H_ + +#include "control/IAmControlSend.h" +#include +#include + +namespace am { + +class MockIAmControlSend : public IAmControlSend { + public: + MOCK_METHOD1(startupController, + am_Error_e(IAmControlReceive* controlreceiveinterface)); + MOCK_METHOD0(setControllerReady, + void()); + MOCK_METHOD0(setControllerRundown, + void()); + MOCK_METHOD3(hookUserConnectionRequest, + am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); + MOCK_METHOD1(hookUserDisconnectionRequest, + am_Error_e(const am_mainConnectionID_t connectionID)); + MOCK_METHOD2(hookUserSetMainSinkSoundProperty, + am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(hookUserSetMainSourceSoundProperty, + am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD1(hookUserSetSystemProperty, + am_Error_e(const am_SystemProperty_s& property)); + MOCK_METHOD2(hookUserVolumeChange, + am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); + MOCK_METHOD2(hookUserVolumeStep, + am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); + MOCK_METHOD2(hookUserSetSinkMuteState, + am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD2(hookSystemRegisterDomain, + am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); + MOCK_METHOD1(hookSystemDeregisterDomain, + am_Error_e(const am_domainID_t domainID)); + MOCK_METHOD1(hookSystemDomainRegistrationComplete, + void(const am_domainID_t domainID)); + MOCK_METHOD2(hookSystemRegisterSink, + am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); + MOCK_METHOD1(hookSystemDeregisterSink, + am_Error_e(const am_sinkID_t sinkID)); + MOCK_METHOD2(hookSystemRegisterSource, + am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); + MOCK_METHOD1(hookSystemDeregisterSource, + am_Error_e(const am_sourceID_t sourceID)); + MOCK_METHOD2(hookSystemRegisterGateway, + am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); + MOCK_METHOD1(hookSystemDeregisterGateway, + am_Error_e(const am_gatewayID_t gatewayID)); + MOCK_METHOD2(hookSystemRegisterCrossfader, + am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); + MOCK_METHOD1(hookSystemDeregisterCrossfader, + am_Error_e(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD3(hookSystemSinkVolumeTick, + void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); + MOCK_METHOD3(hookSystemSourceVolumeTick, + void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); + MOCK_METHOD2(hookSystemInterruptStateChange, + void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); + MOCK_METHOD2(hookSystemSinkAvailablityStateChange, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemSourceAvailablityStateChange, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemDomainStateChange, + void(const am_domainID_t domainID, const am_DomainState_e state)); + MOCK_METHOD1(hookSystemReceiveEarlyData, + void(const std::vector& data)); + MOCK_METHOD1(hookSystemSpeedChange, + void(const am_speed_t speed)); + MOCK_METHOD2(hookSystemTimingInformationChanged, + void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); + MOCK_METHOD2(cbAckConnect, + void(const am_Handle_s handle, const am_Error_e errorID)); + MOCK_METHOD2(cbAckDisconnect, + void(const am_Handle_s handle, const am_Error_e errorID)); + MOCK_METHOD3(cbAckCrossFade, + void(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error)); + MOCK_METHOD3(cbAckSetSinkVolumeChange, + void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); + MOCK_METHOD3(cbAckSetSourceVolumeChange, + void(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceState, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD5(getConnectionFormatChoice, + am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats)); + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD0(confirmCommandReady, + void()); + MOCK_METHOD0(confirmRoutingReady, + void()); + MOCK_METHOD0(confirmCommandRundown, + void()); + MOCK_METHOD0(confirmRoutingRundown, + void()); +}; + +} // namespace am +#endif /* MOCKCONTROLINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/MockIAmRoutingSend.h b/AudioManagerDaemon/test/MockIAmRoutingSend.h new file mode 100644 index 0000000..4e6c6cb --- /dev/null +++ b/AudioManagerDaemon/test/MockIAmRoutingSend.h @@ -0,0 +1,76 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file MockInterfaces.h +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#ifndef MOCKROUTINGINTERFACE_H_ +#define MOCKROUTINGINTERFACE_H_ + +#include "routing/IAmRoutingSend.h" +#include +#include + +namespace am { + +class MockIAmRoutingSend : public IAmRoutingSend { + public: + MOCK_METHOD1(startupInterface, + am_Error_e(IAmRoutingReceive* routingreceiveinterface)); + MOCK_METHOD1(setRoutingReady, + void(const uint16_t handle)); + MOCK_METHOD1(setRoutingRundown, + void(const uint16_t handle)); + MOCK_METHOD1(asyncAbort, + am_Error_e(const am_Handle_s handle)); + MOCK_METHOD5(asyncConnect, + am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)); + MOCK_METHOD2(asyncDisconnect, + am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); + MOCK_METHOD5(asyncSetSinkVolume, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); + MOCK_METHOD5(asyncSetSourceVolume, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); + MOCK_METHOD3(asyncSetSourceState, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); + MOCK_METHOD3(asyncSetSinkSoundProperties, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties)); + MOCK_METHOD3(asyncSetSinkSoundProperty, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)); + MOCK_METHOD3(asyncSetSourceSoundProperties, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties)); + MOCK_METHOD3(asyncSetSourceSoundProperty, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); + MOCK_METHOD5(asyncCrossFade, + am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)); + MOCK_METHOD2(setDomainState, + am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); + MOCK_CONST_METHOD1(returnBusName, + am_Error_e(std::string& BusName)); + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); +}; + +} // namespace am + + +#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/RoutingInterfaceBackdoor.h b/AudioManagerDaemon/test/RoutingInterfaceBackdoor.h deleted file mode 100644 index ff7ffdb..0000000 --- a/AudioManagerDaemon/test/RoutingInterfaceBackdoor.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingInterfaceBackdoor.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef ROUTINGINTERFACEBACKDOOR_H_ -#define ROUTINGINTERFACEBACKDOOR_H_ - -#include "RoutingSender.h" - -namespace am -{ - -class RoutingSender; - -class RoutingInterfaceBackdoor -{ -public: - RoutingInterfaceBackdoor(); - virtual ~RoutingInterfaceBackdoor(); - bool unloadPlugins(RoutingSender *RoutingSender); - bool injectInterface(RoutingSender *RoutingSender, RoutingSendInterface *newInterface, const std::string& busname); -}; - -} - -//definitions are in CommonFunctions.cpp! - -#endif /* ROUTINGINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerDaemon/test/controlInterface/CMakeLists.txt b/AudioManagerDaemon/test/controlInterface/CMakeLists.txt deleted file mode 100644 index bdf8ac5..0000000 --- a/AudioManagerDaemon/test/controlInterface/CMakeLists.txt +++ /dev/null @@ -1,85 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger ControlInterfaceTest -# -# \file CMakeLists.txt -# -# \date 20-Oct-2011 3:42:04 PM -# \author Christian Mueller (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 Mueller 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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(controlInterfacetest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(SQLITE REQUIRED sqlite3) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${GTEST_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB CONTROL_INTERFACE_SRCS_CXX - "../../src/DatabaseHandler.cpp" - "../../src/DatabaseObserver.cpp" - "../../src/RoutingSender.cpp" - "../../src/RoutingReceiver.cpp" - "../../src/CommandSender.cpp" - "../../src/ControlReceiver.cpp" - "../../src/ControlSender.cpp" - "../../src/Router.cpp" - "../../src/DLTWrapper.cpp" - "../../src/SocketHandler.cpp" - "../../src/CommandReceiver.cpp" - "../CommonFunctions.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(controlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(controlInterfaceTest - ${SQLITE_LIBRARIES} - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${GTEST_LIBRARIES} - gmock -) - -INSTALL(TARGETS controlInterfaceTest - DESTINATION "~/AudioManagerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - - - - diff --git a/AudioManagerDaemon/test/controlInterface/MockInterfaces.h b/AudioManagerDaemon/test/controlInterface/MockInterfaces.h deleted file mode 100644 index a341eee..0000000 --- a/AudioManagerDaemon/test/controlInterface/MockInterfaces.h +++ /dev/null @@ -1,182 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file MockInterfaces.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -*/ - -#ifndef MOCKROUTINGINTERFACE_H_ -#define MOCKROUTINGINTERFACE_H_ - -#include -#include -#include -#include - -namespace am { - -class MockRoutingSendInterface : public RoutingSendInterface { - public: - MOCK_METHOD1(startupInterface, - am_Error_e(RoutingReceiveInterface* routingreceiveinterface)); - MOCK_METHOD1(setRoutingReady, - void(const uint16_t handle)); - MOCK_METHOD1(setRoutingRundown, - void(const uint16_t handle)); - MOCK_METHOD1(asyncAbort, - am_Error_e(const am_Handle_s handle)); - MOCK_METHOD5(asyncConnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)); - MOCK_METHOD2(asyncDisconnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); - MOCK_METHOD5(asyncSetSinkVolume, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD5(asyncSetSourceVolume, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD3(asyncSetSourceState, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); - MOCK_METHOD3(asyncSetSinkSoundProperties, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties)); - MOCK_METHOD3(asyncSetSinkSoundProperty, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)); - MOCK_METHOD3(asyncSetSourceSoundProperties, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties)); - MOCK_METHOD3(asyncSetSourceSoundProperty, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); - MOCK_METHOD5(asyncCrossFade, - am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)); - MOCK_METHOD2(setDomainState, - am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); - MOCK_CONST_METHOD1(returnBusName, - am_Error_e(std::string& BusName)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - -}; - - - -class MockControlSendInterface : public ControlSendInterface { - public: - MOCK_METHOD1(startupController, - am_Error_e(ControlReceiveInterface* controlreceiveinterface)); - MOCK_METHOD0(setControllerReady, - void()); - MOCK_METHOD0(setControllerRundown, - void()); - MOCK_METHOD3(hookUserConnectionRequest, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); - MOCK_METHOD1(hookUserDisconnectionRequest, - am_Error_e(const am_mainConnectionID_t connectionID)); - MOCK_METHOD2(hookUserSetMainSinkSoundProperty, - am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(hookUserSetMainSourceSoundProperty, - am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD1(hookUserSetSystemProperty, - am_Error_e(const am_SystemProperty_s& property)); - MOCK_METHOD2(hookUserVolumeChange, - am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); - MOCK_METHOD2(hookUserVolumeStep, - am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); - MOCK_METHOD2(hookUserSetSinkMuteState, - am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD2(hookSystemRegisterDomain, - am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); - MOCK_METHOD1(hookSystemDeregisterDomain, - am_Error_e(const am_domainID_t domainID)); - MOCK_METHOD1(hookSystemDomainRegistrationComplete, - void(const am_domainID_t domainID)); - MOCK_METHOD2(hookSystemRegisterSink, - am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); - MOCK_METHOD1(hookSystemDeregisterSink, - am_Error_e(const am_sinkID_t sinkID)); - MOCK_METHOD2(hookSystemRegisterSource, - am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); - MOCK_METHOD1(hookSystemDeregisterSource, - am_Error_e(const am_sourceID_t sourceID)); - MOCK_METHOD2(hookSystemRegisterGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(hookSystemDeregisterGateway, - am_Error_e(const am_gatewayID_t gatewayID)); - MOCK_METHOD2(hookSystemRegisterCrossfader, - am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); - MOCK_METHOD1(hookSystemDeregisterCrossfader, - am_Error_e(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD3(hookSystemSinkVolumeTick, - void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); - MOCK_METHOD3(hookSystemSourceVolumeTick, - void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); - MOCK_METHOD2(hookSystemInterruptStateChange, - void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); - MOCK_METHOD2(hookSystemSinkAvailablityStateChange, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemSourceAvailablityStateChange, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemDomainStateChange, - void(const am_domainID_t domainID, const am_DomainState_e state)); - MOCK_METHOD1(hookSystemReceiveEarlyData, - void(const std::vector& data)); - MOCK_METHOD1(hookSystemSpeedChange, - void(const am_speed_t speed)); - MOCK_METHOD2(hookSystemTimingInformationChanged, - void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); - MOCK_METHOD2(cbAckConnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD2(cbAckDisconnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD3(cbAckCrossFade, - void(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSinkVolumeChange, - void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSourceVolumeChange, - void(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceState, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD5(getConnectionFormatChoice, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD0(confirmCommandReady, - void()); - MOCK_METHOD0(confirmRoutingReady, - void()); - MOCK_METHOD0(confirmCommandRundown, - void()); - MOCK_METHOD0(confirmRoutingRundown, - void()); - -}; - - - - -} // namespace am - - - -#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.cpp b/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.cpp deleted file mode 100644 index c262692..0000000 --- a/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.cpp +++ /dev/null @@ -1,529 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file controlInterfaceTest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "controlInterfaceTest.h" -#include -#include -#include -#include -#include "DLTWrapper.h" - -using namespace am; -using namespace testing; - -controlInterfaceTest::controlInterfaceTest() : - pSocketHandler(), // - pDBusWrapper((DBusWrapper*) 1), // - plistCommandPluginDirs(), // - plistRoutingPluginDirs(), // - pDatabaseHandler(std::string(":memory:")), // - pRoutingSender(plistRoutingPluginDirs), //RoutingReceiver - pCommandSender(plistCommandPluginDirs), // - pMockControlInterface(), // - pMockRoutingInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlInterfaceBackdoor(), // - pControlSender(std::string("")), // - pRouter(&pDatabaseHandler,&pControlSender), // - pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler, pDBusWrapper) -{ - pDatabaseHandler.registerObserver(&pDatabaseObserver); - pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); - pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock"); - -} - -controlInterfaceTest::~controlInterfaceTest() -{ -} - -void controlInterfaceTest::SetUp() -{ - logInfo("RoutingSendInterface Test started"); -} - -void controlInterfaceTest::TearDown() -{ -} - -TEST_F(controlInterfaceTest,registerDomain) -{ - - am_Domain_s domain; - am_domainID_t domainID; - pCF.createDomain(domain); - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemRegisterDomain(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); - ASSERT_EQ(E_OK, pRoutingReceiver.registerDomain(domain,domainID)); - ASSERT_EQ(domainID, 2); -} - -TEST_F(controlInterfaceTest,deregisterDomain) -{ - am_domainID_t domainID = 34; - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemDeregisterDomain(34)).WillRepeatedly(Return(E_OK)); - ASSERT_EQ(E_OK, pRoutingReceiver.deregisterDomain(domainID)); -} - -TEST_F(controlInterfaceTest,registerSink) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemRegisterSink(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); - ASSERT_EQ(E_OK, pRoutingReceiver.registerSink(sink,sinkID)); - ASSERT_EQ(sinkID, 2); -} - -TEST_F(controlInterfaceTest,deregisterSink) -{ - am_sinkID_t sinkID = 12; - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSink(12)).WillRepeatedly(Return(E_OK)); - ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSink(sinkID)); -} - -TEST_F(controlInterfaceTest,registerSource) -{ - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemRegisterSource(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); - ASSERT_EQ(E_OK, pRoutingReceiver.registerSource(source,sourceID)); - ASSERT_EQ(sourceID, 2); -} - -TEST_F(controlInterfaceTest,deregisterSource) -{ - am_sourceID_t sourceID = 12; - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSource(12)).WillRepeatedly(Return(E_OK)); - ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSource(sourceID)); -} - -TEST_F(controlInterfaceTest,registerGateway) -{ - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - pCF.createGateway(gateway); - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemRegisterGateway(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); - ASSERT_EQ(E_OK, pRoutingReceiver.registerGateway(gateway,gatewayID)); - ASSERT_EQ(gatewayID, 2); -} - -TEST_F(controlInterfaceTest,deregisterGateway) -{ - am_gatewayID_t gatewayID = 12; - - //When we run this test, we expect the call on the control interface - EXPECT_CALL(pMockControlInterface,hookSystemDeregisterGateway(12)).WillRepeatedly(Return(E_OK)); - ASSERT_EQ(E_OK, pRoutingReceiver.deregisterGateway(gatewayID)); -} - -TEST_F(controlInterfaceTest,ackConnect) -{ - am_connectionID_t connectionID; - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - std::vector connectionList; - std::vector handlesList; - am_Handle_s handle; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - - //prepare the stage - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //when asyncConnect is called, we expect a call on the routingInterface - EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); - - //The handle should have the correct type - ASSERT_EQ(handle.handleType, H_CONNECT); - ASSERT_EQ(handle.handle, 1); - ASSERT_EQ(connectionID, 1); - - //The list of handles shall have the handle inside - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, handle.handleType); - - //we check the list of connections - but it must be empty because the ack did not arrive yet - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(connectionList.empty()); - - //finally we answer via the RoutingInterface and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); - pRoutingReceiver.ackConnect(handle, connectionID, E_OK); - - //the list of handles must be empty now - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //but the connection must be in the connectionlist - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(!connectionList.empty()); - - //no we try the same, but do expect a no_change answer directly and no call because connection already exists - ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); -} - -TEST_F(controlInterfaceTest,ackDisconnect) -{ - am_connectionID_t connectionID; - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - std::vector connectionList; - std::vector handlesList; - am_Handle_s handle; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - - //prepare the stage - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //now we first need to connect, we expect a call on the routing interface - EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); - - //answer with an ack to insert the connection in the database - EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); - pRoutingReceiver.ackConnect(handle, connectionID, E_OK); - - //now we can start to disconnect and expect a call on the routing interface - EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); - - //during the disconnection, the connection is still in the list! - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(!connectionList.empty()); - - //then we fire the ack and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1); - pRoutingReceiver.ackDisconnect(handle, connectionID, E_OK); - - //make sure the handle is gone - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //make sure the connection is gone - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(connectionList.empty()); - - //Now let's try to disconnect what is not existing... - ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,2)); -} - -TEST_F(controlInterfaceTest,setSourceState) -{ - - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - std::vector handlesList; - am_Handle_s handle; - am_SourceState_e state; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - - //prepare the stage - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - //we set the sourcestate and expect a call on the routingInterface - EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); - - //we want our handle in the list and let the type be the right one - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESTATE); - - //the state must be unchanged because did not get the ack - ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); - ASSERT_EQ(state, SS_ON); - - //now we sent out the ack and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1); - pRoutingReceiver.ackSetSourceState(handle, E_OK); - - //finally we need the sourcestate to be changed - ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); - ASSERT_EQ(state, SS_PAUSED); - - //make sure the handle is gone - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //we try again but expect a no change error - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); -} - -TEST_F(controlInterfaceTest,SetSinkVolumeChange) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_volume_t volume; - std::vector handlesList; - am_Handle_s handle; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - sink.volume = 10; - - //setup environment, we need a domain and a sink - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //set the volume and expect a call on the routing interface - EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); - - //check the list of handles. The handle must be in there and have the right type - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, H_SETSINKVOLUME); - - //now we read out the volume, but we expect no change because the ack did not arrive yet - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); - ASSERT_EQ(sink.volume, volume); - - //lets send the answer and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1); - pRoutingReceiver.ackSetSinkVolumeChange(handle, 11, E_OK); - - //finally, the new value must be in the database - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); - ASSERT_EQ(11, volume); - - //and the handle must be destroyed - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //Now we try again, but the value is unchanged - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); -} - -TEST_F(controlInterfaceTest,ackSetSourceVolumeChange) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_volume_t volume; - std::vector handlesList; - am_Handle_s handle; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - source.volume = 12; - - //prepare the scene - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - //change the sinkVolume, expect a call on the routingInterface - EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); - - //check the list of handles. The handle must be in there and have the right type - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, H_SETSOURCEVOLUME); - - //now we read out the volume, but we expect no change because the ack did not arrive yet - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); - ASSERT_EQ(source.volume, volume); - - //lets send the answer and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1); - pRoutingReceiver.ackSetSourceVolumeChange(handle, 11, E_OK); - - //finally, the new value must be in the database - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); - ASSERT_EQ(11, volume); - - //and the handle must be destroyed - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //Now we try again, but the value is unchanged - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); -} - -TEST_F(controlInterfaceTest,ackSetSinkSoundProperty) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - std::vector handlesList; - am_Handle_s handle; - am_SoundProperty_s soundProperty; - uint16_t oldvalue; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - soundProperty.type = SP_EXAMPLE_BASS; - soundProperty.value = 244; - - //setup environment, we need a domain and a sink - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //change the soundproperty, expect a call on the routinginterface - EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,2,_)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); - - //check the list of handles. The handle must be in there and have the right type - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, H_SETSINKSOUNDPROPERTY); - - //read out this property. There is no change, because the ack did not arrive yet. - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(2,SP_EXAMPLE_BASS,oldvalue)); - ASSERT_EQ(sink.listSoundProperties[0].value, oldvalue); - - //lets send the answer and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1); - pRoutingReceiver.ackSetSinkSoundProperty(handle, E_OK); - - //finally, the new value must be in the database - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_EXAMPLE_BASS,oldvalue)); - ASSERT_EQ(soundProperty.value, oldvalue); - - //and the handle must be destroyed - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //Now we try again, but the value is unchanged - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); -} - -TEST_F(controlInterfaceTest,ackSetSourceSoundProperty) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - std::vector handlesList; - am_Handle_s handle; - am_SoundProperty_s soundProperty; - uint16_t oldvalue; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - soundProperty.type = SP_EXAMPLE_BASS; - soundProperty.value = 244; - - //prepare the scene - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - //we trigger the change and wait for a call on the routinginterface - EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,2,_)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); - - //check the list of handles. The handle must be in there and have the right type - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_EQ(handlesList[0].handle, handle.handle); - ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESOUNDPROPERTY); - - //read out this property. There is no change, because the ack did not arrive yet. - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(2,SP_EXAMPLE_BASS,oldvalue)); - ASSERT_EQ(source.listSoundProperties[0].value, oldvalue); - - //lets send the answer and expect a call on the controlInterface - EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1); - pRoutingReceiver.ackSetSourceSoundProperty(handle, E_OK); - - //finally, the new value must be in the database - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_EXAMPLE_BASS,oldvalue)); - ASSERT_EQ(soundProperty.value, oldvalue); - - //and the handle must be destroyed - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //Now we try again, but the value is unchanged - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); -} - -TEST_F(controlInterfaceTest,crossFading) -{ - //todo: implement crossfading test -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.h b/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.h deleted file mode 100644 index 72e2f63..0000000 --- a/AudioManagerDaemon/test/controlInterface/controlInterfaceTest.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file controlInterfaceTest.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef ROUTINGINTERFACETEST_H_ -#define ROUTINGINTERFACETEST_H_ - -#include -#include - -#include -#include "MockInterfaces.h" -#include "DatabaseHandler.h" -#include "ControlReceiver.h" -#include "RoutingReceiver.h" -#include "DatabaseObserver.h" -#include "ControlSender.h" -#include "RoutingSender.h" -#include "SocketHandler.h" -#include "Router.h" -#include "../RoutingInterfaceBackdoor.h" -#include "../CommandInterfaceBackdoor.h" -#include "../ControlInterfaceBackdoor.h" -#include "../CommonFunctions.h" - -namespace am -{ - -class controlInterfaceTest: public ::testing::Test -{ -public: - controlInterfaceTest(); - ~controlInterfaceTest(); - SocketHandler pSocketHandler; - DBusWrapper* pDBusWrapper; - std::vector plistCommandPluginDirs; - std::vector plistRoutingPluginDirs; - DatabaseHandler pDatabaseHandler; - RoutingSender pRoutingSender; - CommandSender pCommandSender; - MockControlSendInterface pMockControlInterface; - MockRoutingSendInterface pMockRoutingInterface; - RoutingInterfaceBackdoor pRoutingInterfaceBackdoor; - CommandInterfaceBackdoor pCommandInterfaceBackdoor; - ControlInterfaceBackdoor pControlInterfaceBackdoor; - ControlSender pControlSender; - Router pRouter; - DatabaseObserver pDatabaseObserver; - ControlReceiver pControlReceiver; - RoutingReceiver pRoutingReceiver; - CommonFunctions pCF; - void SetUp(); - void TearDown(); -}; - -} - -#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerDaemon/test/database/CMakeLists.txt b/AudioManagerDaemon/test/database/CMakeLists.txt deleted file mode 100644 index 18e2883..0000000 --- a/AudioManagerDaemon/test/database/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger DatbaseTest -# -# \file CMakeLists.txt -# -# \date 20-Oct-2011 3:42:04 PM -# \author Christian Mueller (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 Mueller 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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(datbaseTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(SQLITE REQUIRED sqlite3) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB DATABASE_SRCS_CXX - "../../src/DatabaseHandler.cpp" - "../../src/DatabaseObserver.cpp" - "../../src/CommandSender.cpp" - "../../src/RoutingSender.cpp" - "../../src/ControlReceiver.cpp" - "../../src/ControlSender.cpp" - "../../src/Router.cpp" - "../../src/DLTWrapper.cpp" - "../../src/SocketHandler.cpp" - "../../src/CommandReceiver.cpp" - "../../src/RoutingReceiver.cpp" - "../CommonFunctions.cpp" - "*.cpp" - ) - -ADD_EXECUTABLE( databasetest ${DATABASE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES( databasetest - ${SQLITE_LIBRARIES} - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${GTEST_LIBRARIES} - gmock -) - -INSTALL(TARGETS databasetest - DESTINATION "~/AudioManagerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - diff --git a/AudioManagerDaemon/test/database/MockInterfaces.h b/AudioManagerDaemon/test/database/MockInterfaces.h deleted file mode 100644 index 453add8..0000000 --- a/AudioManagerDaemon/test/database/MockInterfaces.h +++ /dev/null @@ -1,189 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file MockInterfaces.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#ifndef MOCKROUTINGINTERFACE_H_ -#define MOCKROUTINGINTERFACE_H_ - -#include -#include -#include -#include - -namespace am { - -class MockCommandSendInterface : public CommandSendInterface { - public: - MOCK_METHOD1(startupInterface, - am_Error_e(CommandReceiveInterface* commandreceiveinterface)); - MOCK_METHOD1(setCommandReady, - void(const uint16_t handle)); - MOCK_METHOD1(setCommandRundown, - void(const uint16_t handle)); - MOCK_METHOD1(cbNewMainConnection, - void(const am_MainConnectionType_s mainConnection)); - MOCK_METHOD1(cbRemovedMainConnection, - void(const am_mainConnectionID_t mainConnection)); - MOCK_METHOD1(cbNewSink, - void(const am_SinkType_s& sink)); - MOCK_METHOD1(cbRemovedSink, - void(const am_sinkID_t sinkID)); - MOCK_METHOD1(cbNewSource, - void(const am_SourceType_s& source)); - MOCK_METHOD1(cbRemovedSource, - void(const am_sourceID_t source)); - MOCK_METHOD0(cbNumberOfSinkClassesChanged, - void()); - MOCK_METHOD0(cbNumberOfSourceClassesChanged, - void()); - MOCK_METHOD2(cbMainConnectionStateChanged, - void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); - MOCK_METHOD2(cbMainSinkSoundPropertyChanged, - void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(cbMainSourceSoundPropertyChanged, - void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(cbSinkAvailabilityChanged, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(cbSourceAvailabilityChanged, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(cbVolumeChanged, - void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); - MOCK_METHOD2(cbSinkMuteStateChanged, - void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD1(cbSystemPropertyChanged, - void(const am_SystemProperty_s& systemProperty)); - MOCK_METHOD2(cbTimingInformationChanged, - void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - -}; - - - - -class MockControlSendInterface : public ControlSendInterface { - public: - MOCK_METHOD1(startupController, - am_Error_e(ControlReceiveInterface* controlreceiveinterface)); - MOCK_METHOD0(setControllerReady, - void()); - MOCK_METHOD0(setControllerRundown, - void()); - MOCK_METHOD3(hookUserConnectionRequest, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); - MOCK_METHOD1(hookUserDisconnectionRequest, - am_Error_e(const am_mainConnectionID_t connectionID)); - MOCK_METHOD2(hookUserSetMainSinkSoundProperty, - am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(hookUserSetMainSourceSoundProperty, - am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD1(hookUserSetSystemProperty, - am_Error_e(const am_SystemProperty_s& property)); - MOCK_METHOD2(hookUserVolumeChange, - am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); - MOCK_METHOD2(hookUserVolumeStep, - am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); - MOCK_METHOD2(hookUserSetSinkMuteState, - am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD2(hookSystemRegisterDomain, - am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); - MOCK_METHOD1(hookSystemDeregisterDomain, - am_Error_e(const am_domainID_t domainID)); - MOCK_METHOD1(hookSystemDomainRegistrationComplete, - void(const am_domainID_t domainID)); - MOCK_METHOD2(hookSystemRegisterSink, - am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); - MOCK_METHOD1(hookSystemDeregisterSink, - am_Error_e(const am_sinkID_t sinkID)); - MOCK_METHOD2(hookSystemRegisterSource, - am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); - MOCK_METHOD1(hookSystemDeregisterSource, - am_Error_e(const am_sourceID_t sourceID)); - MOCK_METHOD2(hookSystemRegisterGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(hookSystemDeregisterGateway, - am_Error_e(const am_gatewayID_t gatewayID)); - MOCK_METHOD2(hookSystemRegisterCrossfader, - am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); - MOCK_METHOD1(hookSystemDeregisterCrossfader, - am_Error_e(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD3(hookSystemSinkVolumeTick, - void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); - MOCK_METHOD3(hookSystemSourceVolumeTick, - void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); - MOCK_METHOD2(hookSystemInterruptStateChange, - void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); - MOCK_METHOD2(hookSystemSinkAvailablityStateChange, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemSourceAvailablityStateChange, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemDomainStateChange, - void(const am_domainID_t domainID, const am_DomainState_e state)); - MOCK_METHOD1(hookSystemReceiveEarlyData, - void(const std::vector& data)); - MOCK_METHOD1(hookSystemSpeedChange, - void(const am_speed_t speed)); - MOCK_METHOD2(hookSystemTimingInformationChanged, - void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); - MOCK_METHOD2(cbAckConnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD2(cbAckDisconnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD3(cbAckCrossFade, - void(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSinkVolumeChange, - void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSourceVolumeChange, - void(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceState, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD5(getConnectionFormatChoice, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD0(confirmCommandReady, - void()); - MOCK_METHOD0(confirmRoutingReady, - void()); - MOCK_METHOD0(confirmCommandRundown, - void()); - MOCK_METHOD0(confirmRoutingRundown, - void()); - -}; - -} // namespace am - - - -#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/database/databaseTest.cpp b/AudioManagerDaemon/test/database/databaseTest.cpp deleted file mode 100644 index a43e436..0000000 --- a/AudioManagerDaemon/test/database/databaseTest.cpp +++ /dev/null @@ -1,1941 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file databasetest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "databaseTest.h" -#include -#include -#include -#include -#include "DLTWrapper.h" - -using namespace am; -using namespace testing; - -//extern int GetRandomNumber(int nLow, int nHigh); -//extern bool equalSoundProperty (const am_SoundProperty_s a, const am_SoundProperty_s b); -extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b); -//extern bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b); -extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b); -extern std::string int2string(int i); - -databasetest::databasetest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(),// - pDatabaseHandler(std::string(":memory:")), // - pRoutingSender(plistRoutingPluginDirs), // - pCommandSender(plistCommandPluginDirs), // - pMockInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlSender(""), // - pRouter(&pDatabaseHandler, &pControlSender), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&pObserver); - pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); -} - -databasetest::~databasetest() -{ -} - -void databasetest::createMainConnectionSetup() -{ - //fill the connection database - am_Connection_s connection; - am_Source_s source; - am_Sink_s sink; - std::vector connectionList; - - //we create 9 sources and sinks: - - - - for (uint16_t i = 1; i < 10; i++) - { - am_sinkID_t forgetSink; - am_sourceID_t forgetSource; - am_connectionID_t connectionID; - - pCF.createSink(sink); - sink.sinkID = i; - sink.name = "sink" + int2string(i); - sink.domainID = 4; - pCF.createSource(source); - source.sourceID = i; - source.name = "source" + int2string(i); - source.domainID = 4; - - connection.sinkID = i; - connection.sourceID = i; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; - connection.connectionID = 0; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - connectionList.push_back(connectionID); - - } - - //create a mainConnection - am_MainConnection_s mainConnection; - am_mainConnectionID_t mainConnectionID; - std::vector mainConnectionList; - mainConnection.listConnectionID = connectionList; - mainConnection.mainConnectionID = 0; - mainConnection.sinkID = 1; - mainConnection.sourceID = 1; - mainConnection.connectionState = CS_CONNECTED; - mainConnection.delay = -1; - - //enter mainconnection in database - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_NE(0, mainConnectionID); - - //read out the mainconnections and check if they are equal to the data written. - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList)); - bool equal = true; - std::vector::iterator listIterator = mainConnectionList.begin(); - for (; listIterator < mainConnectionList.end(); ++listIterator) - { - if (listIterator->mainConnectionID == mainConnectionID) - { - equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->sinkID == mainConnection.sinkID) && (listIterator->sourceID == mainConnection.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); - } - } - ASSERT_EQ(true, equal); -} - -void databasetest::SetUp() -{ -} - -void databasetest::TearDown() -{ -} - -TEST_F(databasetest,getMainConnectionInfo) -{ - //fill the connection database - am_Connection_s connection; - am_Source_s source; - am_Sink_s sink; - std::vector connectionList; - - //we create 9 sources and sinks: - - - - for (uint16_t i = 1; i < 10; i++) - { - am_sinkID_t forgetSink; - am_sourceID_t forgetSource; - am_connectionID_t connectionID; - - pCF.createSink(sink); - sink.sinkID = i; - sink.name = "sink" + int2string(i); - sink.domainID = 4; - pCF.createSource(source); - source.sourceID = i; - source.name = "source" + int2string(i); - source.domainID = 4; - - connection.sinkID = i; - connection.sourceID = i; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; - connection.connectionID = 0; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - connectionList.push_back(connectionID); - - } - - //create a mainConnection - am_MainConnection_s mainConnection; - am_mainConnectionID_t mainConnectionID; - std::vector mainConnectionList; - mainConnection.listConnectionID = connectionList; - mainConnection.mainConnectionID = 0; - mainConnection.sinkID = 1; - mainConnection.sourceID = 1; - mainConnection.connectionState = CS_CONNECTED; - mainConnection.delay = -1; - - //enter mainconnection in database - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_NE(0, mainConnectionID); - - //read out the mainconnections and check if they are equal to the data written. - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList)); - bool equal = true; - std::vector::iterator listIterator = mainConnectionList.begin(); - for (; listIterator < mainConnectionList.end(); ++listIterator) - { - if (listIterator->mainConnectionID == mainConnectionID) - { - equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->sinkID == mainConnection.sinkID) && (listIterator->sourceID == mainConnection.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); - } - }ASSERT_EQ(true, equal); - - am_MainConnection_s mainConnectionT; - ASSERT_EQ(E_OK, pDatabaseHandler.getMainConnectionInfoDB(mainConnectionID,mainConnectionT)); - ASSERT_TRUE( (mainConnection.connectionState==mainConnectionT.connectionState) && (mainConnection.delay==mainConnectionT.delay) && (std::equal(mainConnection.listConnectionID.begin(),mainConnection.listConnectionID.end(),mainConnectionT.listConnectionID.begin())) && (mainConnection.sinkID==mainConnectionT.sinkID) && (mainConnection.sourceID==mainConnectionT.sourceID) && (mainConnectionID==mainConnectionT.mainConnectionID)); - -} - -TEST_F(databasetest,getSinKInfo) -{ - //fill the connection database - am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; - am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; - std::vector sinkList; - - pCF.createSink(staticSink); - staticSink.sinkID = 4; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) - << "ERROR: database error"; - ASSERT_EQ(staticSink.sinkID,staticSinkID) - << "ERROR: ID not the one given in staticSink"; - - pCF.createSink(firstDynamicSink); - firstDynamicSink.name = "firstdynamic"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) - << "ERROR: database error"; - ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) - << "ERROR: ID not the one given in firstDynamicSink"; - - pCF.createSink(secondDynamicSink); - secondDynamicSink.name = "seconddynamic"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) - << "ERROR: database error"; - ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) - << "ERROR: ID not the one given in secondDynamicSink"; - - //now read back and check the returns agains the given values - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) - << "ERROR: database error"; - bool equal = true; - - std::vector::iterator listIterator = sinkList.begin(); - for (; listIterator < sinkList.end(); ++listIterator) - { - if (listIterator->sinkID == staticSinkID) - { - equal = equal && pCF.compareSink(listIterator, staticSink); - } - - if (listIterator->sinkID == firstDynamicSinkID) - { - equal = equal && pCF.compareSink(listIterator, firstDynamicSink); - } - - if (listIterator->sinkID == secondDynamicSinkID) - { - equal = equal && pCF.compareSink(listIterator, secondDynamicSink); - } - }ASSERT_EQ(true, equal); - - am_Sink_s sinkData; - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkInfoDB(secondDynamicSinkID,sinkData)); - ASSERT_TRUE( (secondDynamicSink.available.availability == sinkData.available.availability) && (secondDynamicSink.available.availabilityReason == sinkData.available.availabilityReason) && (secondDynamicSink.sinkClassID == sinkData.sinkClassID) && (secondDynamicSink.domainID == sinkData.domainID) && (secondDynamicSink.visible == sinkData.visible) && (secondDynamicSink.name.compare(sinkData.name) == 0) && (secondDynamicSink.volume == sinkData.volume) && std::equal(secondDynamicSink.listConnectionFormats.begin(), secondDynamicSink.listConnectionFormats.end(), sinkData.listConnectionFormats.begin()) && std::equal(secondDynamicSink.listMainSoundProperties.begin(), secondDynamicSink.listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty)); - -} - -TEST_F(databasetest,getSourceInfo) -{ - //fill the connection database - am_Source_s staticSource, firstDynamicSource, secondDynamicSource; - am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; - std::vector sourceList; - - pCF.createSource(staticSource); - staticSource.sourceID = 4; - staticSource.name = "Static"; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) - << "ERROR: database error"; - ASSERT_EQ(staticSource.sourceID,staticSourceID) - << "ERROR: ID not the one given in staticSource"; - - pCF.createSource(firstDynamicSource); - firstDynamicSource.name = "firstDynamicSource"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) - << "ERROR: database error"; - ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) - << "ERROR: ID not the one given in firstDynamicSink"; - - pCF.createSource(secondDynamicSource); - secondDynamicSource.name = "secondDynamicSource"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) - << "ERROR: database error"; - ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) - << "ERROR: ID not the one given in secondDynamicSink"; - - //now read back and check the returns agains the given values - ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) - << "ERROR: database error"; - bool equal = true; - - std::vector::iterator listIterator = sourceList.begin(); - for (; listIterator < sourceList.end(); ++listIterator) - { - if (listIterator->sourceID == staticSourceID) - { - equal = equal && pCF.compareSource(listIterator, staticSource); - } - - if (listIterator->sourceID == firstDynamicSourceID) - { - equal = equal && pCF.compareSource(listIterator, firstDynamicSource); - } - - if (listIterator->sourceID == secondDynamicSourceID) - { - equal = equal && pCF.compareSource(listIterator, secondDynamicSource); - } - pCF.compareSource(listIterator, secondDynamicSource); - - }ASSERT_EQ(true, equal); - - am_Source_s sourceData; - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceInfoDB(secondDynamicSourceID,sourceData)); - ASSERT_TRUE( - (secondDynamicSource.available.availability == sourceData.available.availability) && (secondDynamicSource.available.availabilityReason == sourceData.available.availabilityReason) && (secondDynamicSource.sourceClassID == sourceData.sourceClassID) && (secondDynamicSource.domainID == sourceData.domainID) && (secondDynamicSource.interruptState == sourceData.interruptState) && (secondDynamicSource.visible == sourceData.visible) && (secondDynamicSource.name.compare(sourceData.name) == 0) && (secondDynamicSource.volume == sourceData.volume) && std::equal(secondDynamicSource.listConnectionFormats.begin(), secondDynamicSource.listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) && std::equal(secondDynamicSource.listMainSoundProperties.begin(), secondDynamicSource.listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty)); - -} - -TEST_F(databasetest, peekSourceID) -{ - - std::string sourceName("myClassID"); - am_sourceClass_t sourceClassID, peekID; - am_SourceClass_s sourceClass; - am_ClassProperty_s classProperty; - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 13; - sourceClass.name = sourceName; - sourceClass.sourceClassID = 0; - sourceClass.listClassProperties.push_back(classProperty); - - //first we peek without an existing class - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); - - //now we enter the class into the database - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - - //first we peek without an existing class - ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID)); - ASSERT_EQ(sourceClassID, peekID); -} - -TEST_F(databasetest, peekSinkID) -{ - - std::string sinkName("myClassID"); - am_sinkClass_t sinkClassID, peekID; - am_SinkClass_s sinkClass; - am_ClassProperty_s classProperty; - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 13; - sinkClass.name = sinkName; - sinkClass.sinkClassID = 0; - sinkClass.listClassProperties.push_back(classProperty); - - //first we peek without an existing class - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); - - //now we enter the class into the database - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - - //first we peek without an existing class - ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID)); - ASSERT_EQ(sinkClassID, peekID); -} - -TEST_F(databasetest,crossfaders) -{ - - - - am_Crossfader_s crossfader; - am_crossfaderID_t crossfaderID; - am_Sink_s sinkA, sinkB; - am_Source_s source; - am_sourceID_t sourceID; - am_sinkID_t sinkAID, sinkBID; - pCF.createSink(sinkA); - pCF.createSink(sinkB); - sinkB.name = "sinkB"; - pCF.createSource(source); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); - - crossfader.crossfaderID = 0; - crossfader.hotSink = HS_SINKA; - crossfader.sinkID_A = sinkAID; - crossfader.sinkID_B = sinkBID; - crossfader.sourceID = sourceID; - crossfader.name = "Crossfader"; - crossfader.hotSink = HS_UNKNOWN; - - std::vector listCrossfaders; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfaders(listCrossfaders)); - ASSERT_EQ(crossfader.sinkID_A, listCrossfaders[0].sinkID_A); - ASSERT_EQ(crossfader.sinkID_B, listCrossfaders[0].sinkID_B); - ASSERT_EQ(crossfader.sourceID, listCrossfaders[0].sourceID); - ASSERT_EQ(crossfader.hotSink, listCrossfaders[0].hotSink); - ASSERT_EQ(100, listCrossfaders[0].crossfaderID); - ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0); -} - -TEST_F(databasetest,crossfadersGetFromDomain) -{ - - - - am_Crossfader_s crossfader; - am_crossfaderID_t crossfaderID; - am_Sink_s sinkA, sinkB; - am_Source_s source; - am_sourceID_t sourceID; - am_sinkID_t sinkAID, sinkBID; - am_domainID_t domainID; - am_Domain_s domain; - pCF.createSink(sinkA); - pCF.createSink(sinkB); - pCF.createDomain(domain); - sinkB.name = "sinkB"; - pCF.createSource(source); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - source.domainID = domainID; - sinkA.domainID = domainID; - sinkB.domainID = domainID; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); - - crossfader.crossfaderID = 0; - crossfader.hotSink = HS_SINKA; - crossfader.sinkID_A = sinkAID; - crossfader.sinkID_B = sinkBID; - crossfader.sourceID = sourceID; - crossfader.name = "Crossfader"; - crossfader.hotSink = HS_UNKNOWN; - - std::vector listCrossfaders; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfadersOfDomain(source.domainID,listCrossfaders)); - ASSERT_EQ(100, listCrossfaders[0]); - -} - -TEST_F(databasetest,sourceState) -{ - am_Source_s source; - am_sourceID_t sourceID; - std::vector listSources; - pCF.createSource(source); - source.sourceState = SS_OFF; - - //prepare the test - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - //change the source state - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceState(sourceID,SS_ON)); - - //read out the changed values - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(listSources[0].sourceState, SS_ON); -} - -TEST_F(databasetest,sinkVolumeChange) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - std::vector listSinks; - pCF.createSink(sink); - sink.volume = 23; - - //prepare the test - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //change the volume and check the read out - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkVolume(sinkID,34)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(listSinks[0].volume, 34); -} - -TEST_F(databasetest,sourceVolumeChange) -{ - am_Source_s source; - am_sourceID_t sourceID; - std::vector listSources; - pCF.createSource(source); - source.volume = 23; - - //prepare test - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - //change the volume and check the read out - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceVolume(sourceID,34)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(listSources[0].volume, 34); -} - -TEST_F(databasetest, peekSource) -{ - std::vector listSources; - am_sourceID_t sourceID, source2ID, source3ID; - am_Source_s source; - pCF.createSource(source); - - //peek a source that does not exits - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); - - //make sure it is not in the list - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_TRUE(listSources.empty()); - ASSERT_EQ(sourceID, 100); - - //now enter the source with the same name and make sure it does not get a new ID - source.name = "newsource"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(sourceID, source2ID); - ASSERT_TRUE(listSources[0].sourceID==sourceID); - - //now we peek again. This time, the source exists - ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(source.name,source3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_TRUE(listSources.size()==1); - ASSERT_EQ(source3ID, source2ID); -} - -TEST_F(databasetest, peekSourceDouble) -{ - std::vector listSources; - am_sourceID_t sourceID; - am_sourceID_t source2ID; - am_sourceID_t source3ID; - am_Source_s source; - pCF.createSource(source); - - //peek a source that does not exits - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); - - //peek a second source that does not exits - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID)); - - //make sure they are is not in the list - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_TRUE(listSources.empty()); - ASSERT_EQ(sourceID, 100); - source.name = "newsource"; - - //now enter the source with the same name than the first peek and make sure it does not get a new ID - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(sourceID, source3ID); - ASSERT_TRUE(listSources[0].sourceID==sourceID); -} - -TEST_F(databasetest, peekSink) -{ - std::vector listSinks; - am_sinkID_t sinkID, sink2ID, sink3ID; - am_Sink_s sink; - pCF.createSink(sink); - - //peek a sink that does not exits - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); - - //make sure it is not in the list - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_TRUE(listSinks.empty()); - ASSERT_EQ(sinkID, 100); - sink.name = "newsink"; - - //now enter the source with the same name and make sure it does not get a new ID - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(sinkID, sink2ID); - ASSERT_TRUE(listSinks[0].sinkID==sinkID); - - //now we peek again, this time, the sink exists - ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(sink.name,sink3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_TRUE(listSinks.size()==1); - ASSERT_EQ(sink3ID, sink2ID); -} - -TEST_F(databasetest, peekSinkDouble) -{ - std::vector listSinks; - am_sinkID_t sinkID; - am_sinkID_t sink2ID; - am_sinkID_t sink3ID; - am_Sink_s sink; - pCF.createSink(sink); - - //peek a sink that does not exits - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); - - //peek again - - ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID)); - - //make sure they are is not in the list - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_TRUE(listSinks.empty()); - ASSERT_EQ(sinkID, 100); - sink.name = "newsink"; - - //now enter the sink with the same name than the first peek and make sure it does not get a new ID - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(sinkID, sink3ID); - ASSERT_TRUE(listSinks[0].sinkID==sinkID); -} - -TEST_F(databasetest,changeConnectionTimingInformationCheckMainConnection) -{ - std::vector connectionList; - std::vector mainList; - - //prepare the test, it is one mainconnection, so we expect one callback - createMainConnectionSetup(); - - //first get all visible mainconnections and make sure, the delay is set to -1 for the first entry - ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); - ASSERT_EQ(mainList[0].delay, -1); - - //no go through all connections and set the delay time to 24 for each connection - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - std::vector::iterator iteratorConnectionList = connectionList.begin(); - for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList) - { - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24)); - } - - //we read the result again and expect that the value is now different from -1 - ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); - ASSERT_EQ(mainList[0].delay, 216); -} - -TEST_F(databasetest,changeConnectionTimingInformation) -{ - am_Connection_s connection; - am_connectionID_t connectionID; - std::vector connectionList; - pCF.createConnection(connection); - - //enter a connection - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - - //change the timing and check it - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(connectionID,24)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(connectionList[0].delay==24); -} - -TEST_F(databasetest,getSinkClassOfSink) -{ - std::vector sinkClassList; - std::vector classPropertyList; - am_SinkClass_s sinkClass, returnClass; - am_ClassProperty_s classProperty; - am_sinkClass_t sinkClassID; - am_Sink_s sink; - am_sinkID_t sinkID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sinkClass.name = "test"; - sinkClass.sinkClassID = 4; - sinkClass.listClassProperties = classPropertyList; - pCF.createSink(sink); - sink.sinkClassID = 4; - - //prepare test - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //enter a new sinkclass, read out again and check - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 4); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkClassInfoDB(sinkID,returnClass)); - ASSERT_EQ(sinkClassList[0].name, returnClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, returnClass.sinkClassID); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),returnClass.listClassProperties.begin(),equalClassProperties)); -} - -TEST_F(databasetest,getSourceClassOfSource) -{ - std::vector sourceClassList; - std::vector classPropertyList; - am_SourceClass_s sourceClass, sinkSourceClass; - am_ClassProperty_s classProperty; - am_sourceClass_t sourceClassID; - am_Source_s source; - am_sourceID_t sourceID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sourceClass.name = "test"; - sourceClass.sourceClassID = 1; - sourceClass.listClassProperties = classPropertyList; - pCF.createSource(source); - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 1); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceClassInfoDB(sourceID,sinkSourceClass)); - ASSERT_EQ(sourceClassList[0].name, sinkSourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, sinkSourceClass.sourceClassID); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),sinkSourceClass.listClassProperties.begin(),equalClassProperties)); -} - -TEST_F(databasetest,removeSourceClass) -{ - std::vector sourceClassList; - std::vector classPropertyList; - am_SourceClass_s sourceClass; - am_ClassProperty_s classProperty; - am_sourceClass_t sourceClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sourceClass.name = "test"; - sourceClass.sourceClassID = 3; - sourceClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 3); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.removeSourceClassDB(3)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_TRUE(sourceClassList.empty()); -} - -TEST_F(databasetest,updateSourceClass) -{ - std::vector sourceClassList; - std::vector classPropertyList, changedPropertyList; - am_SourceClass_s sourceClass, changedClass; - am_ClassProperty_s classProperty; - am_sourceClass_t sourceClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sourceClass.name = "test"; - sourceClass.sourceClassID = 0; - sourceClass.listClassProperties = classPropertyList; - changedClass = sourceClass; - changedClass.listClassProperties[1].value = 6; - changedPropertyList = changedClass.listClassProperties; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - changedClass.sourceClassID = sourceClassID; - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 100); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceClassInfoDB(changedClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 100); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest,enterSourceClass) -{ - std::vector sourceClassList; - std::vector classPropertyList; - am_SourceClass_s sourceClass; - am_ClassProperty_s classProperty; - am_sourceClass_t sourceClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sourceClass.name = "test"; - sourceClass.sourceClassID = 0; - sourceClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 100); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest,enterSourceClassStatic) -{ - std::vector sourceClassList; - std::vector classPropertyList; - am_SourceClass_s sourceClass; - am_ClassProperty_s classProperty; - am_sourceClass_t sourceClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sourceClass.name = "test"; - sourceClass.sourceClassID = 3; - sourceClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); - ASSERT_EQ(sourceClassList[0].name, sourceClass.name); - ASSERT_EQ(sourceClassList[0].sourceClassID, 3); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest,removeSinkClass) -{ - std::vector sinkClassList; - std::vector classPropertyList; - am_SinkClass_s sinkClass; - am_ClassProperty_s classProperty; - am_sinkClass_t sinkClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sinkClass.name = "test"; - sinkClass.sinkClassID = 0; - sinkClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 100); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkClassDB(sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_TRUE(sinkClassList.empty()); -} - -TEST_F(databasetest,updateSinkClass) -{ - std::vector sinkClassList; - std::vector classPropertyList, changedPropertyList; - am_SinkClass_s sinkClass, changedClass; - am_ClassProperty_s classProperty; - am_sinkClass_t sinkClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sinkClass.name = "test"; - sinkClass.sinkClassID = 0; - sinkClass.listClassProperties = classPropertyList; - changedClass = sinkClass; - changedClass.listClassProperties[1].value = 6; - changedPropertyList = changedClass.listClassProperties; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - changedClass.sinkClassID = sinkClassID; - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 100); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkClassInfoDB(changedClass)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 100); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest,enterSinkClass) -{ - std::vector sinkClassList; - std::vector classPropertyList; - am_SinkClass_s sinkClass; - am_ClassProperty_s classProperty; - am_sinkClass_t sinkClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sinkClass.name = "test"; - sinkClass.sinkClassID = 0; - sinkClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 100); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest,enterSinkClassStatic) -{ - std::vector sinkClassList; - std::vector classPropertyList; - am_SinkClass_s sinkClass; - am_ClassProperty_s classProperty; - am_sinkClass_t sinkClassID; - classProperty.classProperty = CP_GENIVI_SINK_TYPE; - classProperty.value = 1; - classPropertyList.push_back(classProperty); - classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; - classProperty.value = 4; - classPropertyList.push_back(classProperty); - sinkClass.name = "test"; - sinkClass.sinkClassID = 4; - sinkClass.listClassProperties = classPropertyList; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); - ASSERT_EQ(sinkClassList[0].name, sinkClass.name); - ASSERT_EQ(sinkClassList[0].sinkClassID, 4); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(databasetest, changeSystemProperty) -{ - std::vector listSystemProperties, listReturn; - am_SystemProperty_s systemProperty; - - systemProperty.type = SYP_UNKNOWN; - systemProperty.value = 33; - listSystemProperties.push_back(systemProperty); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); - systemProperty.value = 444; - ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); - ASSERT_EQ(listReturn[0].type, systemProperty.type); - ASSERT_EQ(listReturn[0].value, systemProperty.value); -} - -TEST_F(databasetest, systemProperties) -{ - std::vector listSystemProperties, listReturn; - am_SystemProperty_s systemProperty; - - systemProperty.type = SYP_UNKNOWN; - systemProperty.value = 33; - listSystemProperties.push_back(systemProperty); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); - ASSERT_EQ(listReturn[0].type, systemProperty.type); - ASSERT_EQ(listReturn[0].value, systemProperty.value); -} - -TEST_F(databasetest,enterSourcesCorrect) -{ - //fill the connection database - am_Source_s staticSource, firstDynamicSource, secondDynamicSource; - am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; - std::vector sourceList; - - pCF.createSource(staticSource); - staticSource.sourceID = 4; - staticSource.name = "Static"; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) - << "ERROR: database error"; - ASSERT_EQ(staticSource.sourceID,staticSourceID) - << "ERROR: ID not the one given in staticSource"; - - pCF.createSource(firstDynamicSource); - firstDynamicSource.name = "firstDynamicSource"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) - << "ERROR: database error"; - ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) - << "ERROR: ID not the one given in firstDynamicSink"; - - pCF.createSource(secondDynamicSource); - secondDynamicSource.name = "secondDynamicSource"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) - << "ERROR: database error"; - ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) - << "ERROR: ID not the one given in secondDynamicSink"; - - //now read back and check the returns agains the given values - ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) - << "ERROR: database error"; - bool equal = true; - - std::vector::iterator listIterator = sourceList.begin(); - for (; listIterator < sourceList.end(); ++listIterator) - { - if (listIterator->sourceID == staticSourceID) - { - equal = equal && pCF.compareSource(listIterator, staticSource); - } - - if (listIterator->sourceID == firstDynamicSourceID) - { - equal = equal && pCF.compareSource(listIterator, firstDynamicSource); - } - - if (listIterator->sourceID == secondDynamicSourceID) - { - equal = equal && pCF.compareSource(listIterator, secondDynamicSource); - } - - } - ASSERT_EQ(true, equal); -} - -TEST_F(databasetest, changeSourceMainSoundProperty) -{ - std::vector listSources; - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - am_MainSoundProperty_s property; - property.type = MSP_UNKNOWN; - property.value = 33; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB(property,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - std::vector::iterator listIterator = listSources[0].listMainSoundProperties.begin(); - for (; listIterator < listSources[0].listMainSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - { - ASSERT_EQ(listIterator->value, property.value); - } - } -} - -TEST_F(databasetest, changeSinkMuteState) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_MuteState_e muteState = MS_MUTED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(muteState, listSinks[0].muteState); -} - -TEST_F(databasetest, changeSinkMainSoundProperty) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_MainSoundProperty_s property; - property.type = MSP_UNKNOWN; - property.value = 33; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - std::vector::iterator listIterator = listSinks[0].listMainSoundProperties.begin(); - for (; listIterator < listSinks[0].listMainSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - { - ASSERT_EQ(listIterator->value, property.value); - } - } -} - -TEST_F(databasetest, peekDomain) -{ - std::vector listDomains; - am_Domain_s domain; - am_domainID_t domainID; - am_domainID_t domain2ID; - pCF.createDomain(domain); - ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_TRUE(listDomains.empty()); - ASSERT_EQ(domainID, 1); - domain.name = "newdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domainID, domain2ID); - ASSERT_TRUE(listDomains[0].domainID==domainID); -} - -TEST_F(databasetest, peekDomainFirstEntered) -{ - std::vector listDomains; - am_Domain_s domain; - am_domainID_t domainID; - am_domainID_t domain2ID; - pCF.createDomain(domain); - domain.name = "newdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID)); - ASSERT_EQ(domainID, domain2ID); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_TRUE(listDomains.size()==1); -} - -TEST_F(databasetest, changeDomainState) -{ - std::vector listDomains; - am_Domain_s domain; - am_domainID_t domainID; - pCF.createDomain(domain); - am_DomainState_e newState = DS_INDEPENDENT_STARTUP; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changDomainStateDB(newState,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(newState, listDomains[0].state); -} - -TEST_F(databasetest, changeMainConnectionState) -{ - std::vector listMainConnections; - createMainConnectionSetup(); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); - ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState); -} - -TEST_F(databasetest, changeSinkAvailability) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_Availability_s availability; - availability.availability = A_UNKNOWN; - availability.availabilityReason = AR_GENIVI_TEMPERATURE; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(availability.availability, listSinks[0].available.availability); - ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason); -} - -TEST_F(databasetest, changeSourceAvailability) -{ - std::vector listSources; - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - am_Availability_s availability; - availability.availability = A_UNKNOWN; - availability.availabilityReason = AR_GENIVI_TEMPERATURE; - source.visible = true; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(availability.availability, listSources[0].available.availability); - ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason); -} - -TEST_F(databasetest,changeMainConnectionRoute) -{ - std::vector originalList; - std::vector newList; - createMainConnectionSetup(); - //fill the connection database - am_Connection_s connection; - am_Source_s source; - am_Sink_s sink; - std::vector listConnectionID; - - - - for (uint16_t i = 1; i < 10; i++) - { - am_sinkID_t forgetSink; - am_sourceID_t forgetSource; - am_connectionID_t connectionID; - - connection.sinkID = i + 20; - connection.sourceID = i + 20; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; - connection.connectionID = 0; - - pCF.createSink(sink); - sink.sinkID = i + 20; - sink.name = "sink" + int2string(i + 20); - sink.domainID = 4; - pCF.createSource(source); - source.sourceID = i + 20; - source.name = "source" + int2string(i + 30); - source.domainID = 4; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - listConnectionID.push_back(connectionID); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(originalList)); - - } - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(1,listConnectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(newList)); - ASSERT_FALSE(std::equal(newList[0].listConnectionID.begin(),newList[0].listConnectionID.end(),originalList[0].listConnectionID.begin())); -} - -TEST_F(databasetest,changeMainSinkVolume) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_mainVolume_t newVol = 20; - std::vector listSinks; - pCF.createSink(sink); - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(listSinks[0].mainVolume, newVol); -} - -TEST_F(databasetest,getMainSourceSoundProperties) -{ - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - std::vector mainSoundProperties = source.listMainSoundProperties; - std::vector listMainSoundProperties; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties)); - ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); -} - -TEST_F(databasetest,getMainSinkSoundProperties) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - std::vector mainSoundProperties = sink.listMainSoundProperties; - std::vector listMainSoundProperties; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties)); - ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); -} - -TEST_F(databasetest,getMainSources) -{ - am_Source_s source, source1, source2; - am_sourceID_t sourceID; - pCF.createSource(source); - pCF.createSource(source1); - pCF.createSource(source2); - source1.name = "source1"; - source2.name = "source2"; - bool equal = true; - source1.visible = false; - std::vector listMainSources; - std::vector listSources; - - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - source.sourceID = sourceID; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source2,sourceID)); - source2.sourceID = sourceID; - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listMainSources)); - listSources.push_back(source); - listSources.push_back(source2); - std::vector::iterator listIterator = listMainSources.begin(); - for (; listIterator < listMainSources.end(); ++listIterator) - { - equal = equal && pCF.compareSinkMainSource(listIterator, listSources); - } - ASSERT_TRUE(equal); -} - -TEST_F(databasetest,getMainSinks) -{ - am_Sink_s sink, sink1, sink2; - am_sinkID_t sinkID; - pCF.createSink(sink); - pCF.createSink(sink1); - pCF.createSink(sink2); - sink1.name = "sink1"; - sink2.name = "sink2"; - bool equal = true; - sink1.visible = false; - std::vector listMainSinks; - std::vector listSinks; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - sink.sinkID = sinkID; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink2,sinkID)); - sink2.sinkID = sinkID; - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listMainSinks)); - listSinks.push_back(sink); - listSinks.push_back(sink2); - std::vector::iterator listIterator = listMainSinks.begin(); - for (; listIterator < listMainSinks.end(); ++listIterator) - { - equal = equal && pCF.compareSinkMainSink(listIterator, listSinks); - } - ASSERT_TRUE(equal); -} - -TEST_F(databasetest,getVisibleMainConnections) -{ - createMainConnectionSetup(); - std::vector listVisibleMainConnections; - std::vector listMainConnections; - ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(listVisibleMainConnections)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); - ASSERT_EQ(listMainConnections[0].mainConnectionID, listVisibleMainConnections[0].mainConnectionID); - ASSERT_EQ(listMainConnections[0].connectionState, listVisibleMainConnections[0].connectionState); - ASSERT_EQ(listMainConnections[0].delay, listVisibleMainConnections[0].delay); - ASSERT_EQ(listMainConnections[0].sinkID, listVisibleMainConnections[0].sinkID); - ASSERT_EQ(listMainConnections[0].sourceID, listVisibleMainConnections[0].sourceID); -} - -TEST_F(databasetest,getListSourcesOfDomain) -{ - am_Source_s source, source2; - am_Domain_s domain; - am_domainID_t domainID; - am_sourceID_t sourceID; - std::vector sourceList, sourceCheckList; - pCF.createSource(source); - source.sourceID = 1; - source.name = "testSource"; - source.domainID = 1; - pCF.createSource(source2); - source2.sourceID = 0; - source2.name = "testSource2"; - source2.domainID = 5; - pCF.createDomain(domain); - sourceCheckList.push_back(1); //sink.sinkID); - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source2,sourceID)) - << "ERROR: database error"; - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSourcesOfDomain(2,sourceList)) - << "ERROR: database error";ASSERT_TRUE(sourceList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListSourcesOfDomain(1,sourceList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty()); -} - -TEST_F(databasetest,getListSinksOfDomain) -{ - am_Sink_s sink, sink2; - am_Domain_s domain; - am_domainID_t domainID; - am_sinkID_t sinkID; - std::vector sinkList, sinkCheckList; - pCF.createSink(sink); - sink.sinkID = 1; - sink.domainID = 1; - pCF.createSink(sink2); - sink2.domainID = 5; - sink2.name = "sink2"; - pCF.createDomain(domain); - sinkCheckList.push_back(1); //sink.sinkID); - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,sinkID)) - << "ERROR: database error"; - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSinksOfDomain(2,sinkList)) - << "ERROR: database error";ASSERT_TRUE(sinkList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(1,sinkList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty()); -} - -TEST_F(databasetest,getListGatewaysOfDomain) -{ - - - am_Gateway_s gateway, gateway2; - am_gatewayID_t gatewayID; - am_domainID_t domainID; - am_Domain_s domain; - std::vector gatewayList, gatewayCheckList; - pCF.createGateway(gateway); - gateway.gatewayID = 1; - gateway.name = "testGateway"; - gateway.controlDomainID = 1; - gateway.sourceID = 1; - gateway.sinkID = 1; - gateway.domainSinkID = 1; - gateway.domainSourceID = 1; - pCF.createGateway(gateway2); - gateway2.gatewayID = 2; - gateway2.name = "testGateway2"; - gateway2.controlDomainID = 4; - gateway2.sourceID = 1; - gateway2.sinkID = 1; - gateway2.domainSinkID = 1; - gateway2.domainSourceID = 1; - pCF.createDomain(domain); - gatewayCheckList.push_back(gateway.gatewayID); - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - pCF.createSource(source); - sink.sinkID = 1; - source.sourceID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList)) - << "ERROR: database error";ASSERT_TRUE(gatewayList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(1,gatewayList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty()); -} - -TEST_F(databasetest,removeDomain) -{ - am_Domain_s domain; - am_domainID_t domainID; - std::vector listDomains; - pCF.createDomain(domain); - ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(listDomains)) - << "ERROR: database error"; - ASSERT_TRUE(listDomains.empty()); -} - -TEST_F(databasetest,removeGateway) -{ - - - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - std::vector listGateways; - pCF.createGateway(gateway); - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - pCF.createSource(source); - sink.sinkID = 1; - source.sourceID = 2; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(listGateways)) - << "ERROR: database error"; - ASSERT_TRUE(listGateways.empty()); -} - -TEST_F(databasetest,removeSink) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - std::vector listSinks; - pCF.createSink(sink); - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - ASSERT_TRUE(listSinks.empty()); -} - -TEST_F(databasetest,removeSource) -{ - //fill the connection database - am_Source_s source; - am_sourceID_t sourceID; - std::vector listSources; - pCF.createSource(source); - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) - << "ERROR: database error"; - ASSERT_TRUE(listSources.empty()); -} - -TEST_F(databasetest, removeMainConnection) -{ - createMainConnectionSetup(); - - - ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1)) - << "ERROR: database error"; -} - -TEST_F(databasetest,removeNonexistentMainConnectionFail) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34)) - << "ERROR: database error"; -} - -TEST_F(databasetest,removeNonexistentSource) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3)) - << "ERROR: database error"; -} - -TEST_F(databasetest,removeNonexistentSink) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2)) - << "ERROR: database error"; -} - -TEST_F(databasetest,removeNonexistentGateway) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12)) - << "ERROR: database error"; -} - -TEST_F(databasetest,registerGatewayCorrect) -{ - - - //initialize gateway - std::vector returnList; - am_Gateway_s gateway, gateway1, gateway2; - am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; - - pCF.createGateway(gateway); - pCF.createGateway(gateway1); - gateway1.gatewayID = 20; - pCF.createGateway(gateway2); - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - pCF.createSource(source); - sink.sinkID = 1; - source.sourceID = 2; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(100,gatewayID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.gatewayID,gatewayID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) - << "ERROR: database error"; - ASSERT_EQ(101,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); - bool equal = true; - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->gatewayID == gatewayID) - { - equal = equal && pCF.compareGateway(listIterator, gateway); - } - - if (listIterator->gatewayID == gatewayID1) - { - equal = equal && pCF.compareGateway(listIterator, gateway1); - } - - if (listIterator->gatewayID == gatewayID2) - { - equal = equal && pCF.compareGateway(listIterator, gateway2); - } - } - - ASSERT_EQ(true, equal); -} - -TEST_F(databasetest,getGatewayInfo) -{ - - - //initialize gateway - std::vector returnList; - am_Gateway_s gateway, gateway1, gateway2; - am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; - - pCF.createGateway(gateway); - pCF.createGateway(gateway1); - gateway1.gatewayID = 20; - pCF.createGateway(gateway2); - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - pCF.createSource(source); - sink.sinkID = 1; - source.sourceID = 2; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(100,gatewayID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.gatewayID,gatewayID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) - << "ERROR: database error"; - ASSERT_EQ(101,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); - bool equal = true; - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->gatewayID == gatewayID) - { - equal = equal && pCF.compareGateway(listIterator, gateway); - } - - if (listIterator->gatewayID == gatewayID1) - { - equal = equal && pCF.compareGateway(listIterator, gateway1); - } - - if (listIterator->gatewayID == gatewayID2) - { - equal = equal && pCF.compareGateway(listIterator, gateway2); - } - } - - ASSERT_EQ(true, equal); - - am_Gateway_s gatewayInfo; - ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo)); - ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo)); - -} - -TEST_F(databasetest,enterSinkThatAlreadyExistFail) -{ - //fill the connection database - am_Sink_s staticSink, SecondSink; - am_sinkID_t staticSinkID, SecondSinkID; - - pCF.createSink(staticSink); - staticSink.sinkID = 43; - staticSink.name = "Static"; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) - << "ERROR: database error"; - ASSERT_EQ(staticSink.sinkID,staticSinkID) - << "ERROR: ID not the one given in staticSink"; - - pCF.createSink(SecondSink); - SecondSink.sinkID = 43; - SecondSink.name = "SecondSink"; - - ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID)) - << "ERROR: database error"; -} - -TEST_F(databasetest,enterSourcesThatAlreadyExistFail) -{ - //fill the connection database - am_Source_s staticSource, SecondSource; - am_sourceID_t staticSourceID, SecondSourceID; - pCF.createSource(staticSource); - staticSource.sourceID = 4; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) - << "ERROR: database error"; - ASSERT_EQ(staticSource.sourceID,staticSourceID) - << "ERROR: ID not the one given in staticSource"; - - pCF.createSource(SecondSource); - SecondSource.sourceID = 4; - - ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID)) - << "ERROR: database error"; -} - -TEST_F(databasetest,registerDomainCorrect) -{ - //initialize domain - std::vector returnList; - am_Domain_s domain; - am_domainID_t domainID = 0; - pCF.createDomain(domain); - - ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) - << "ERROR: database error"; - ASSERT_NE(0,domainID) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); - bool equal = true; - std::vector::iterator listIterator = returnList.begin(); - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->domainID == domainID) - { - equal = equal && (listIterator->name.compare(domain.name) == 0) && (listIterator->busname.compare(domain.busname) == 0) && (listIterator->complete == domain.complete) && (listIterator->early == domain.early) && (listIterator->state == domain.state); - } - } - ASSERT_EQ(true, equal); -} - -TEST_F(databasetest,registerConnectionCorrect) -{ - am_Connection_s connection; - am_connectionID_t connectionID; - std::vector returnList; - pCF.createConnection(connection); - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID)) - << "ERROR: database error";; - ASSERT_NE(0,connectionID) - << "ERROR: connectionID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(returnList)); - bool equal = false; - std::vector::iterator listIterator = returnList.begin(); - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->connectionID == connectionID) - { - equal = (listIterator->sourceID == connection.sourceID) && (listIterator->sinkID == connection.sinkID) && (listIterator->delay == connection.delay) && (listIterator->connectionFormat = connection.connectionFormat); - } - } - ASSERT_EQ(true, equal); -} - -TEST_F(databasetest,enterMainConnectionCorrect) -{ - createMainConnectionSetup(); -} - -TEST_F(databasetest,enterSinksCorrect) -{ - //fill the connection database - am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; - am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; - std::vector sinkList; - - pCF.createSink(staticSink); - staticSink.sinkID = 4; - - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) - << "ERROR: database error"; - ASSERT_EQ(staticSink.sinkID,staticSinkID) - << "ERROR: ID not the one given in staticSink"; - - pCF.createSink(firstDynamicSink); - firstDynamicSink.name = "firstdynamic"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) - << "ERROR: database error"; - ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) - << "ERROR: ID not the one given in firstDynamicSink"; - - pCF.createSink(secondDynamicSink); - secondDynamicSink.name = "seconddynamic"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) - << "ERROR: database error"; - ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) - << "ERROR: ID not the one given in secondDynamicSink"; - - //now read back and check the returns agains the given values - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) - << "ERROR: database error"; - bool equal = true; - - std::vector::iterator listIterator = sinkList.begin(); - for (; listIterator < sinkList.end(); ++listIterator) - { - if (listIterator->sinkID == staticSinkID) - { - equal = equal && pCF.compareSink(listIterator, staticSink); - } - - if (listIterator->sinkID == firstDynamicSinkID) - { - equal = equal && pCF.compareSink(listIterator, firstDynamicSink); - } - - if (listIterator->sinkID == secondDynamicSinkID) - { - equal = equal && pCF.compareSink(listIterator, secondDynamicSink); - } - } - ASSERT_EQ(true, equal); -} - -//Commented out - gives always a warning.. -//TEST_F(databaseTest,registerDomainFailonID0) -//{ -// am_Domain_s domain; -// am_domainID_t domainID=5; -// pCF.createDomain(domain); -// domain.domainID=1; -// ASSERT_DEATH(pDatabaseHandler.enterDomainDB(domain,domainID),"Assertion `domainData.domainID==0'"); -//} - -int main(int argc, char **argv) -{ - DLTWrapper::instance()->registerApp("databse", "databasetest"); - logInfo("Database Test started "); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/AudioManagerDaemon/test/database/databaseTest.h b/AudioManagerDaemon/test/database/databaseTest.h deleted file mode 100644 index 4dba9c6..0000000 --- a/AudioManagerDaemon/test/database/databaseTest.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file databasetest.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef DATABASETEST_H_ -#define DATABASETEST_H_ - -#define UNIT_TEST 1 - -#include -#include - -#include "MockInterfaces.h" -#include "DatabaseHandler.h" -#include "ControlReceiver.h" -#include "ControlSender.h" -#include "DatabaseObserver.h" -#include "RoutingSender.h" -#include "Router.h" -#include "ControlSender.h" -#include "SocketHandler.h" -#include "../ControlInterfaceBackdoor.h" -#include "../CommandInterfaceBackdoor.h" -#include "../CommonFunctions.h" - -namespace am -{ - -class databasetest: public ::testing::Test -{ -public: - databasetest(); - ~databasetest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - SocketHandler pSocketHandler; - DatabaseHandler pDatabaseHandler; - RoutingSender pRoutingSender; - CommandSender pCommandSender; - MockCommandSendInterface pMockInterface; - RoutingInterfaceBackdoor pRoutingInterfaceBackdoor; - CommandInterfaceBackdoor pCommandInterfaceBackdoor; - ControlSender pControlSender; - Router pRouter; - ControlReceiver pControlReceiver; - DatabaseObserver pObserver; - CommonFunctions pCF; - void SetUp(); - void TearDown(); - - void createMainConnectionSetup(); -}; - -} - -#endif /* DATABASETEST_H_ */ diff --git a/AudioManagerDaemon/test/routing/CMakeLists.txt b/AudioManagerDaemon/test/routing/CMakeLists.txt deleted file mode 100644 index a7c70f9..0000000 --- a/AudioManagerDaemon/test/routing/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger DatbaseTest -# -# \file CMakeLists.txt -# -# \date 20-Oct-2011 3:42:04 PM -# \author Christian Mueller (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 Mueller 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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(routingTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(SQLITE REQUIRED sqlite3) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB ROUTING_SRCS_CXX - "../../src/DatabaseHandler.cpp" - "../../src/DatabaseObserver.cpp" - "../../src/CommandSender.cpp" - "../../src/RoutingSender.cpp" - "../../src/ControlReceiver.cpp" - "../../src/ControlSender.cpp" - "../../src/Router.cpp" - "../../src/DLTWrapper.cpp" - "../../src/SocketHandler.cpp" - "../../src/CommandReceiver.cpp" - "../../src/RoutingReceiver.cpp" - "../CommonFunctions.cpp" - "*.cpp" - ) - -ADD_EXECUTABLE( routingtest ${ROUTING_SRCS_CXX}) - -TARGET_LINK_LIBRARIES( routingtest - ${SQLITE_LIBRARIES} - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${GTEST_LIBRARIES} - gmock -) - -INSTALL(TARGETS routingtest - DESTINATION "~/AudioManagerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - diff --git a/AudioManagerDaemon/test/routing/MockInterfaces.h b/AudioManagerDaemon/test/routing/MockInterfaces.h deleted file mode 100644 index ea527ac..0000000 --- a/AudioManagerDaemon/test/routing/MockInterfaces.h +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file MockInterfaces.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef MOCKROUTINGINTERFACE_H_ -#define MOCKROUTINGINTERFACE_H_ - -#include -#include -#include -#include - -namespace am -{ - -class MockCommandSendInterface : public CommandSendInterface { - public: - MOCK_METHOD1(startupInterface, - am_Error_e(CommandReceiveInterface* commandreceiveinterface)); - MOCK_METHOD1(setCommandReady, - void(const uint16_t handle)); - MOCK_METHOD1(setCommandRundown, - void(const uint16_t handle)); - MOCK_METHOD1(cbNewMainConnection, - void(const am_MainConnectionType_s mainConnection)); - MOCK_METHOD1(cbRemovedMainConnection, - void(const am_mainConnectionID_t mainConnection)); - MOCK_METHOD1(cbNewSink, - void(const am_SinkType_s& sink)); - MOCK_METHOD1(cbRemovedSink, - void(const am_sinkID_t sinkID)); - MOCK_METHOD1(cbNewSource, - void(const am_SourceType_s& source)); - MOCK_METHOD1(cbRemovedSource, - void(const am_sourceID_t source)); - MOCK_METHOD0(cbNumberOfSinkClassesChanged, - void()); - MOCK_METHOD0(cbNumberOfSourceClassesChanged, - void()); - MOCK_METHOD2(cbMainConnectionStateChanged, - void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); - MOCK_METHOD2(cbMainSinkSoundPropertyChanged, - void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(cbMainSourceSoundPropertyChanged, - void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(cbSinkAvailabilityChanged, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(cbSourceAvailabilityChanged, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(cbVolumeChanged, - void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); - MOCK_METHOD2(cbSinkMuteStateChanged, - void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD1(cbSystemPropertyChanged, - void(const am_SystemProperty_s& systemProperty)); - MOCK_METHOD2(cbTimingInformationChanged, - void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - -}; - - -class MockControlSendInterface : public ControlSendInterface { - public: - MOCK_METHOD1(startupController, - am_Error_e(ControlReceiveInterface* controlreceiveinterface)); - MOCK_METHOD0(setControllerReady, - void()); - MOCK_METHOD0(setControllerRundown, - void()); - MOCK_METHOD3(hookUserConnectionRequest, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); - MOCK_METHOD1(hookUserDisconnectionRequest, - am_Error_e(const am_mainConnectionID_t connectionID)); - MOCK_METHOD2(hookUserSetMainSinkSoundProperty, - am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(hookUserSetMainSourceSoundProperty, - am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD1(hookUserSetSystemProperty, - am_Error_e(const am_SystemProperty_s& property)); - MOCK_METHOD2(hookUserVolumeChange, - am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); - MOCK_METHOD2(hookUserVolumeStep, - am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); - MOCK_METHOD2(hookUserSetSinkMuteState, - am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD2(hookSystemRegisterDomain, - am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); - MOCK_METHOD1(hookSystemDeregisterDomain, - am_Error_e(const am_domainID_t domainID)); - MOCK_METHOD1(hookSystemDomainRegistrationComplete, - void(const am_domainID_t domainID)); - MOCK_METHOD2(hookSystemRegisterSink, - am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); - MOCK_METHOD1(hookSystemDeregisterSink, - am_Error_e(const am_sinkID_t sinkID)); - MOCK_METHOD2(hookSystemRegisterSource, - am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); - MOCK_METHOD1(hookSystemDeregisterSource, - am_Error_e(const am_sourceID_t sourceID)); - MOCK_METHOD2(hookSystemRegisterGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(hookSystemDeregisterGateway, - am_Error_e(const am_gatewayID_t gatewayID)); - MOCK_METHOD2(hookSystemRegisterCrossfader, - am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); - MOCK_METHOD1(hookSystemDeregisterCrossfader, - am_Error_e(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD3(hookSystemSinkVolumeTick, - void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); - MOCK_METHOD3(hookSystemSourceVolumeTick, - void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); - MOCK_METHOD2(hookSystemInterruptStateChange, - void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); - MOCK_METHOD2(hookSystemSinkAvailablityStateChange, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemSourceAvailablityStateChange, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemDomainStateChange, - void(const am_domainID_t domainID, const am_DomainState_e state)); - MOCK_METHOD1(hookSystemReceiveEarlyData, - void(const std::vector& data)); - MOCK_METHOD1(hookSystemSpeedChange, - void(const am_speed_t speed)); - MOCK_METHOD2(hookSystemTimingInformationChanged, - void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); - MOCK_METHOD2(cbAckConnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD2(cbAckDisconnect, - void(const am_Handle_s handle, const am_Error_e errorID)); - MOCK_METHOD3(cbAckCrossFade, - void(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSinkVolumeChange, - void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); - MOCK_METHOD3(cbAckSetSourceVolumeChange, - void(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceState, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD5(getConnectionFormatChoice, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD0(confirmCommandReady, - void()); - MOCK_METHOD0(confirmRoutingReady, - void()); - MOCK_METHOD0(confirmCommandRundown, - void()); - MOCK_METHOD0(confirmRoutingRundown, - void()); - -}; - - -} // namespace am - -#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/routing/routingTest.cpp b/AudioManagerDaemon/test/routing/routingTest.cpp deleted file mode 100644 index aa3f333..0000000 --- a/AudioManagerDaemon/test/routing/routingTest.cpp +++ /dev/null @@ -1,1829 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file databasetest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "routingTest.h" -#include "MockInterfaces.h" -#include "DatabaseHandler.h" -#include "ControlReceiver.h" -#include "ControlSender.h" -#include "DatabaseObserver.h" -#include "Router.h" -#include "../ControlInterfaceBackdoor.h" -#include "../CommandInterfaceBackdoor.h" -#include "../CommonFunctions.h" -#include "DLTWrapper.h" -#include - -using namespace am; -using namespace testing; - -routingTest::routingTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pDatabaseHandler(std::string(":memory:")), // - pControlSender(std::string("")), // - pRouter(&pDatabaseHandler, &pControlSender), // - pRoutingSender(plistRoutingPluginDirs), // - pCommandSender(plistCommandPluginDirs), // - pMockInterface(), // - pMockControlInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlInterfaceBackdoor(), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // - pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&pObserver); - pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); - pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); -} - -routingTest::~routingTest() -{ -} - -void routingTest::SetUp() -{ - logInfo("Routing Test started "); -} - -void routingTest::TearDown() -{ -} - -ACTION(returnConnectionFormat){ -arg4=arg3; -} - -//test that checks just sinks and source in a domain but connectionformats do not match -TEST_F(routingTest,simpleRoute2withDomainNoMatchFormats) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1; - am_domainID_t domainID1; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - - am_Source_s source; - am_sourceID_t sourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - am_Sink_s sink; - am_sinkID_t sinkID; - - sink.domainID = domainID1; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - - hopp1.sinkID = sinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); - -} - -//test that checks just sinks and source in a domain -TEST_F(routingTest,simpleRoute2withDomain) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1; - am_domainID_t domainID1; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - - am_Source_s source; - am_sourceID_t sourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - am_Sink_s sink; - am_sinkID_t sinkID; - - sink.domainID = domainID1; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - - hopp1.sinkID = sinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); - -} - -//test that checks just 2 domains, one sink one source with only one connection format each -TEST_F(routingTest,simpleRoute2DomainsOnlyFree) -{ - - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2; - am_domainID_t domainID1, domainID2; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - - am_Source_s source, gwSource; - am_sourceID_t sourceID, gwSourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - - am_Sink_s sink, gwSink; - am_sinkID_t sinkID, gwSinkID; - - sink.domainID = domainID2; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sinkID = gwSinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sinkID = sinkID; - hopp2.sourceID = gwSourceID; - hopp2.domainID = domainID2; - hopp2.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); - -} - -//test that checks just 2 domains, one sink one source with only one connection format each -TEST_F(routingTest,simpleRoute2DomainsOnlyFreeNotFree) -{ - - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2; - am_domainID_t domainID1, domainID2; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - - am_Source_s source, gwSource; - am_sourceID_t sourceID, gwSourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - - am_Sink_s sink, gwSink; - am_sinkID_t sinkID, gwSinkID; - - sink.domainID = domainID2; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sinkID = gwSinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sinkID = sinkID; - hopp2.sourceID = gwSourceID; - hopp2.domainID = domainID2; - hopp2.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - am_Connection_s connection,connection1; - am_connectionID_t id1,id2; - connection.sourceID=sourceID; - connection.sinkID=gwSinkID; - connection.connectionFormat=CF_GENIVI_ANALOG; - connection.connectionID=0; - connection1.sourceID=gwSourceID; - connection1.sinkID=sinkID; - connection1.connectionFormat=CF_GENIVI_ANALOG; - connection1.connectionID=0; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); - - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks 3 domains, one sink one source, longer lists of connectionformats. -TEST_F(routingTest,simpleRoute3DomainsListConnectionFormats_2) -{ - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3; - am_domainID_t domainID1, domainID2, domainID3; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - - am_Source_s source, gwSource, gwSource1; - am_sourceID_t sourceID, gwSourceID, gwSourceID1; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_STEREO); - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - - am_Sink_s sink, gwSink, gwSink1; - am_sinkID_t sinkID, gwSinkID, gwSinkID1; - - sink.domainID = domainID3; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - - am_Gateway_s gateway, gateway1; - am_gatewayID_t gatewayID, gatewayID1; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(true); - gateway.convertionMatrix.push_back(true); - gateway.convertionMatrix.push_back(false); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(false); - gateway1.convertionMatrix.push_back(false); - gateway1.convertionMatrix.push_back(false); - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway1"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[1]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[1]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = sinkID; - hopp3.domainID = domainID3; - hopp3.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks 3 domains, one sink one source, longer lists of connectionformats. -TEST_F(routingTest,simpleRoute3DomainsListConnectionFormats_1) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3; - am_domainID_t domainID1, domainID2, domainID3; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - - am_Source_s source, gwSource, gwSource1; - am_sourceID_t sourceID, gwSourceID, gwSourceID1; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_STEREO); - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - - am_Sink_s sink, gwSink, gwSink1; - am_sinkID_t sinkID, gwSinkID, gwSinkID1; - - sink.domainID = domainID3; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - - am_Gateway_s gateway, gateway1; - am_gatewayID_t gatewayID, gatewayID1; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(true); - gateway.convertionMatrix.push_back(false); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = sinkID; - hopp3.domainID = domainID3; - hopp3.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - - -//test that checks 3 domains, one sink one source, longer lists of connectionformats. -TEST_F(routingTest,simpleRoute3DomainsListConnectionFormats) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3; - am_domainID_t domainID1, domainID2, domainID3; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - - am_Source_s source, gwSource, gwSource1; - am_sourceID_t sourceID, gwSourceID, gwSourceID1; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_STEREO); - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - - am_Sink_s sink, gwSink, gwSink1; - am_sinkID_t sinkID, gwSinkID, gwSinkID1; - - sink.domainID = domainID3; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - - am_Gateway_s gateway, gateway1; - am_gatewayID_t gatewayID, gatewayID1; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(false); - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[1]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = sinkID; - hopp3.domainID = domainID3; - hopp3.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - - -//test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways -TEST_F(routingTest,simpleRoute4Domains2Routes) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3, domain4; - am_domainID_t domainID1, domainID2, domainID3, domainID4; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - domain4.domainID = 0; - domain4.name = "domain4"; - domain4.busname = "domain4bus"; - domain4.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); - - am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3; - am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource2.domainID = domainID4; - gwSource2.name = "gwsource3"; - gwSource2.sourceState = SS_OFF; - gwSource2.sourceID = 0; - gwSource2.sourceClassID = 5; - gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - gwSource3.domainID = domainID3; - gwSource3.name = "gwsource4"; - gwSource3.sourceState = SS_OFF; - gwSource3.sourceID = 0; - gwSource3.sourceClassID = 5; - gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3)); - - am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3; - am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3; - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSink2.domainID = domainID3; - gwSink2.name = "gwSink2"; - gwSink2.sinkID = 0; - gwSink2.sinkClassID = 5; - gwSink2.muteState = MS_MUTED; - gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink3.domainID = domainID2; - gwSink3.name = "gwSink3"; - gwSink3.sinkID = 0; - gwSink3.sinkClassID = 5; - gwSink3.muteState = MS_MUTED; - gwSink3.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - sink.domainID = domainID4; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3)); - - am_Gateway_s gateway, gateway1, gateway2, gateway3; - am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway1"; - - gateway2.controlDomainID = domainID3; - gateway2.gatewayID = 0; - gateway2.sinkID = gwSinkID2; - gateway2.sourceID = gwSourceID2; - gateway2.domainSourceID = domainID4; - gateway2.domainSinkID = domainID3; - gateway2.listSinkFormats = gwSink2.listConnectionFormats; - gateway2.listSourceFormats = gwSource2.listConnectionFormats; - gateway2.convertionMatrix.push_back(true); - gateway2.name = "gateway2"; - - gateway3.controlDomainID = domainID2; - gateway3.gatewayID = 0; - gateway3.sinkID = gwSinkID3; - gateway3.sourceID = gwSourceID3; - gateway3.domainSourceID = domainID3; - gateway3.domainSinkID = domainID2; - gateway3.listSinkFormats = gwSink3.listConnectionFormats; - gateway3.listSourceFormats = gwSource3.listConnectionFormats; - gateway3.convertionMatrix.push_back(true); - gateway3.name = "gateway3"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3)); - - std::vector listRoutes; - std::vector listRoutingElements, listRoutingElements1; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - am_RoutingElement_s hopp4; - am_RoutingElement_s hopp2alt; - am_RoutingElement_s hopp3alt; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = gwSinkID2; - hopp3.domainID = domainID3; - hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; - - hopp4.sourceID = gwSourceID2; - hopp4.sinkID = sinkID; - hopp4.domainID = domainID4; - hopp4.connectionFormat = sink.listConnectionFormats[0]; - - hopp2alt.sourceID = gwSourceID; - hopp2alt.sinkID = gwSinkID3; - hopp2alt.domainID = domainID2; - hopp2alt.connectionFormat = gwSink3.listConnectionFormats[0]; - - hopp3alt.sourceID = gwSourceID3; - hopp3alt.sinkID = gwSinkID2; - hopp3alt.domainID = domainID3; - hopp3alt.connectionFormat = gwSink2.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - listRoutingElements.push_back(hopp4); - listRoutingElements1.push_back(hopp1); - listRoutingElements1.push_back(hopp2alt); - listRoutingElements1.push_back(hopp3alt); - listRoutingElements1.push_back(hopp4); - - am_Route_s compareRoute, compareRoute1; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - compareRoute1.route = listRoutingElements1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(2, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])); -} - -//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. -TEST_F(routingTest,simpleRoute3DomainsNoConnection) -{ - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3; - am_domainID_t domainID1, domainID2, domainID3; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - - am_Source_s source, gwSource, gwSource1; - am_sourceID_t sourceID, gwSourceID, gwSourceID1; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - - am_Sink_s sink, gwSink, gwSink1; - am_sinkID_t sinkID, gwSinkID, gwSinkID1; - - sink.domainID = domainID3; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - - am_Gateway_s gateway, gateway1; - am_gatewayID_t gatewayID, gatewayID1; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = sinkID; - hopp3.domainID = domainID3; - hopp3.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); -} -//test that checks just 2 domains, one sink one source with only one connection format each -TEST_F(routingTest,simpleRoute2Domains) -{ - - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2; - am_domainID_t domainID1, domainID2; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - - am_Source_s source, gwSource; - am_sourceID_t sourceID, gwSourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - - am_Sink_s sink, gwSink; - am_sinkID_t sinkID, gwSinkID; - - sink.domainID = domainID2; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sinkID = gwSinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sinkID = sinkID; - hopp2.sourceID = gwSourceID; - hopp2.domainID = domainID2; - hopp2.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); - -} - -//test that checks just 2 domains, one sink one source but the connectionformat of source -TEST_F(routingTest,simpleRoute2DomainsNoMatchConnectionFormats) -{ - - - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2; - am_domainID_t domainID1, domainID2; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - - am_Source_s source, gwSource; - am_sourceID_t sourceID, gwSourceID; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - - am_Sink_s sink, gwSink; - am_sinkID_t sinkID, gwSinkID; - - sink.domainID = domainID2; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - - am_Gateway_s gateway; - am_gatewayID_t gatewayID; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sinkID = gwSinkID; - hopp1.sourceID = sourceID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sinkID = sinkID; - hopp2.sourceID = gwSourceID; - hopp2.domainID = domainID2; - hopp2.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); -} - -//test that checks 3 domains, one sink one source. -TEST_F(routingTest,simpleRoute3Domains) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3; - am_domainID_t domainID1, domainID2, domainID3; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - - am_Source_s source, gwSource, gwSource1; - am_sourceID_t sourceID, gwSourceID, gwSourceID1; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - - am_Sink_s sink, gwSink, gwSink1; - am_sinkID_t sinkID, gwSinkID, gwSinkID1; - - sink.domainID = domainID3; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - - am_Gateway_s gateway, gateway1; - am_gatewayID_t gatewayID, gatewayID1; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = sinkID; - hopp3.domainID = domainID3; - hopp3.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks 4 domains, one sink and one source. -TEST_F(routingTest,simpleRoute4Domains) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - //initialize 2 domains - am_Domain_s domain1, domain2, domain3, domain4; - am_domainID_t domainID1, domainID2, domainID3, domainID4; - - domain1.domainID = 0; - domain1.name = "domain1"; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - domain2.domainID = 0; - domain2.name = "domain2"; - domain2.busname = "domain2bus"; - domain2.state = DS_CONTROLLED; - domain3.domainID = 0; - domain3.name = "domain3"; - domain3.busname = "domain3bus"; - domain3.state = DS_CONTROLLED; - domain4.domainID = 0; - domain4.name = "domain4"; - domain4.busname = "domain4bus"; - domain4.state = DS_CONTROLLED; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); - - am_Source_s source, gwSource, gwSource1, gwSource2; - am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2; - - source.domainID = domainID1; - source.name = "source1"; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource.domainID = domainID2; - gwSource.name = "gwsource1"; - gwSource.sourceState = SS_ON; - gwSource.sourceID = 0; - gwSource.sourceClassID = 5; - gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSource1.domainID = domainID3; - gwSource1.name = "gwsource2"; - gwSource1.sourceState = SS_ON; - gwSource1.sourceID = 0; - gwSource1.sourceClassID = 5; - gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSource2.domainID = domainID4; - gwSource2.name = "gwsource3"; - gwSource2.sourceState = SS_OFF; - gwSource2.sourceID = 0; - gwSource2.sourceClassID = 5; - gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); - - am_Sink_s sink, gwSink, gwSink1, gwSink2; - am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2; - - gwSink.domainID = domainID1; - gwSink.name = "gwSink"; - gwSink.sinkID = 0; - gwSink.sinkClassID = 5; - gwSink.muteState = MS_MUTED; - gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); - - gwSink1.domainID = domainID2; - gwSink1.name = "gwSink1"; - gwSink1.sinkID = 0; - gwSink1.sinkClassID = 5; - gwSink1.muteState = MS_MUTED; - gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - gwSink2.domainID = domainID3; - gwSink2.name = "gwSink2"; - gwSink2.sinkID = 0; - gwSink2.sinkClassID = 5; - gwSink2.muteState = MS_MUTED; - gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); - - sink.domainID = domainID4; - sink.name = "sink1"; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); - - am_Gateway_s gateway, gateway1, gateway2; - am_gatewayID_t gatewayID, gatewayID1, gatewayID2; - - gateway.controlDomainID = domainID1; - gateway.gatewayID = 0; - gateway.sinkID = gwSinkID; - gateway.sourceID = gwSourceID; - gateway.domainSourceID = domainID2; - gateway.domainSinkID = domainID1; - gateway.listSinkFormats = gwSink.listConnectionFormats; - gateway.listSourceFormats = gwSource.listConnectionFormats; - gateway.convertionMatrix.push_back(true); - gateway.name = "gateway"; - - gateway1.controlDomainID = domainID2; - gateway1.gatewayID = 0; - gateway1.sinkID = gwSinkID1; - gateway1.sourceID = gwSourceID1; - gateway1.domainSourceID = domainID3; - gateway1.domainSinkID = domainID2; - gateway1.listSinkFormats = gwSink1.listConnectionFormats; - gateway1.listSourceFormats = gwSource1.listConnectionFormats; - gateway1.convertionMatrix.push_back(true); - gateway1.name = "gateway1"; - - gateway2.controlDomainID = domainID3; - gateway2.gatewayID = 0; - gateway2.sinkID = gwSinkID2; - gateway2.sourceID = gwSourceID2; - gateway2.domainSourceID = domainID4; - gateway2.domainSinkID = domainID3; - gateway2.listSinkFormats = gwSink2.listConnectionFormats; - gateway2.listSourceFormats = gwSource2.listConnectionFormats; - gateway2.convertionMatrix.push_back(true); - gateway2.name = "gateway2"; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - am_RoutingElement_s hopp3; - am_RoutingElement_s hopp4; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = source.listConnectionFormats[0]; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = gwSinkID1; - hopp2.domainID = domainID2; - hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; - - hopp3.sourceID = gwSourceID1; - hopp3.sinkID = gwSinkID2; - hopp3.domainID = domainID3; - hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; - - hopp4.sourceID = gwSourceID2; - hopp4.sinkID = sinkID; - hopp4.domainID = domainID4; - hopp4.connectionFormat = sink.listConnectionFormats[0]; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - listRoutingElements.push_back(hopp3); - listRoutingElements.push_back(hopp4); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -int main(int argc, char **argv) -{ - DLTWrapper::instance()->registerApp("routing", "routingtest"); - logInfo("Routing Test started "); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/AudioManagerDaemon/test/routing/routingTest.h b/AudioManagerDaemon/test/routing/routingTest.h deleted file mode 100644 index 64ed8c5..0000000 --- a/AudioManagerDaemon/test/routing/routingTest.h +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file databasetest.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef DATABASETEST_H_ -#define DATABASETEST_H_ - -#define UNIT_TEST 1 - -#include -#include -#include -#include -#include -#include -#include "MockInterfaces.h" -#include "DatabaseHandler.h" -#include "ControlReceiver.h" -#include "ControlSender.h" -#include "DatabaseObserver.h" -#include "RoutingSender.h" -#include "Router.h" -#include "SocketHandler.h" -#include "../ControlInterfaceBackdoor.h" -#include "../CommandInterfaceBackdoor.h" -#include "../CommonFunctions.h" - -namespace am -{ - -class routingTest: public ::testing::Test -{ -public: - routingTest(); - ~routingTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - SocketHandler pSocketHandler; - DatabaseHandler pDatabaseHandler; - ControlSender pControlSender; - Router pRouter; - RoutingSender pRoutingSender; - CommandSender pCommandSender; - MockCommandSendInterface pMockInterface; - MockControlSendInterface pMockControlInterface; - RoutingInterfaceBackdoor pRoutingInterfaceBackdoor; - CommandInterfaceBackdoor pCommandInterfaceBackdoor; - ControlInterfaceBackdoor pControlInterfaceBackdoor; - ControlReceiver pControlReceiver; - DatabaseObserver pObserver; - CommonFunctions pCF; - void SetUp(); - void TearDown(); - - void createMainConnectionSetup(); -}; - -} - -#endif /* DATABASETEST_H_ */ diff --git a/AudioManagerDaemon/test/routingInterface/CMakeLists.txt b/AudioManagerDaemon/test/routingInterface/CMakeLists.txt deleted file mode 100644 index fbb4ac1..0000000 --- a/AudioManagerDaemon/test/routingInterface/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger RoutingInterfaceTest -# -# \file CMakeLists.txt -# -# \date 20-Oct-2011 3:42:04 PM -# \author Christian Mueller (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 Mueller 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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(routingInterfaceTest) - -#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(SQLITE REQUIRED sqlite3) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB ROUTING_INTERFACE_SRCS_CXX - "../../src/ControlReceiver.cpp" - "../../src/DatabaseHandler.cpp" - "../../src/DatabaseObserver.cpp" - "../../src/CommandSender.cpp" - "../../src/RoutingSender.cpp" - "../../src/Router.cpp" - "../../src/ControlSender.cpp" - "../CommonFunctions.cpp" - "../../src/DLTWrapper.cpp" - "../../src/SocketHandler.cpp" - "../../src/RoutingReceiver.cpp" - "../../src/CommandReceiver.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(routinginterfacetest ${ROUTING_INTERFACE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(routinginterfacetest - ${SQLITE_LIBRARIES} - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${GTEST_LIBRARIES} - gmock -) - -INSTALL(TARGETS routinginterfacetest - DESTINATION "~/AudioManagerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - - - diff --git a/AudioManagerDaemon/test/routingInterface/MockRoutingInterface.h b/AudioManagerDaemon/test/routingInterface/MockRoutingInterface.h deleted file mode 100644 index 2c21fe6..0000000 --- a/AudioManagerDaemon/test/routingInterface/MockRoutingInterface.h +++ /dev/null @@ -1,76 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file MockInterfaces.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#ifndef MOCKROUTINGINTERFACE_H_ -#define MOCKROUTINGINTERFACE_H_ - -#include -#include -#include - -namespace am { - -class MockRoutingSendInterface : public RoutingSendInterface { - public: - MOCK_METHOD1(startupInterface, - am_Error_e(RoutingReceiveInterface* routingreceiveinterface)); - MOCK_METHOD1(setRoutingReady, - void(const uint16_t handle)); - MOCK_METHOD1(setRoutingRundown, - void(const uint16_t handle)); - MOCK_METHOD1(asyncAbort, - am_Error_e(const am_Handle_s handle)); - MOCK_METHOD5(asyncConnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)); - MOCK_METHOD2(asyncDisconnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); - MOCK_METHOD5(asyncSetSinkVolume, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD5(asyncSetSourceVolume, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD3(asyncSetSourceState, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); - MOCK_METHOD3(asyncSetSinkSoundProperties, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties)); - MOCK_METHOD3(asyncSetSinkSoundProperty, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)); - MOCK_METHOD3(asyncSetSourceSoundProperties, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties)); - MOCK_METHOD3(asyncSetSourceSoundProperty, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); - MOCK_METHOD5(asyncCrossFade, - am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)); - MOCK_METHOD2(setDomainState, - am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); - MOCK_CONST_METHOD1(returnBusName, - am_Error_e(std::string& BusName)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); -}; - -} // namespace am - - -#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.cpp b/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.cpp deleted file mode 100644 index a827ebe..0000000 --- a/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file routingInterfaces.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "routingInterfaceTest.h" -#include "DLTWrapper.h" - -using namespace am; -using namespace testing; - -routingInterfaceTest::routingInterfaceTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pDatabaseHandler(std::string(":memory:")), // - pRoutingSender(plistRoutingPluginDirs), // - pCommandSender(plistCommandPluginDirs), // - pControlSender(""), // - pRouter(&pDatabaseHandler, &pControlSender), // - pMockInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&pObserver); - pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender); - pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock"); - pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender); -} - -routingInterfaceTest::~routingInterfaceTest() -{ -} - -void routingInterfaceTest::SetUp() -{ - logInfo("RoutingSendInterface Test started "); - -} - -void routingInterfaceTest::TearDown() -{ -} - -TEST_F(routingInterfaceTest,abort) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_connectionID_t connectionID; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - - //prepare the stage - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - //start a connect, expect a call on the routingInterface - EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); - - //check the correctness of the handle - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_CONNECT); - - //the handle must be inside the handlelist - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); - - //send an abort expect a call on the routing interface - EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.abortAction(handle)); - - //the reaction on the abort is specific for every function - - //now we try to abort a handle that does not exist - handle.handle = 24; - ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); -} - -TEST_F(routingInterfaceTest,abortNonExistent) -{ - EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0); - am_Handle_s handle; - ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); -} - -TEST_F(routingInterfaceTest,alreadyConnected) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); - am_Handle_s handle; - am_connectionID_t connectionID; - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_CONNECT); -} - -TEST_F(routingInterfaceTest,setSinkSoundPropertyNoChange) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_SoundProperty_s soundProperty; - soundProperty.type = SP_EXAMPLE_TREBLE; - soundProperty.value = 23; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - sink.listSoundProperties.push_back(soundProperty); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).Times(0); - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); -} - -TEST_F(routingInterfaceTest,setSourceState) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - handle.handle = 0; - am_SourceState_e state = SS_PAUSED; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,sourceID,state)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_SETSOURCESTATE); -} - -TEST_F(routingInterfaceTest,setSourceSoundProperty) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_SoundProperty_s soundProperty; - std::vector listHandles; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,sourceID,_)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_SETSOURCESOUNDPROPERTY); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,setSinkSoundProperty) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_SoundProperty_s soundProperty; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_SETSINKSOUNDPROPERTY); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,setSourceVolumeNoChange) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_volume_t volume = 34; - am_RampType_e rampType = RAMP_GENIVI_DIRECT; - am_time_t rampTime = 300; - std::vector listHandles; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - source.volume = volume; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).Times(0); - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime)); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles.empty()); -} - -TEST_F(routingInterfaceTest,setSourceVolume) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_volume_t volume = 34; - am_RampType_e rampType = RAMP_GENIVI_DIRECT; - am_time_t rampTime = 300; - std::vector listHandles; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_SETSOURCEVOLUME); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,setSinkVolumeNoChange) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_volume_t volume = 34; - am_RampType_e rampType = RAMP_GENIVI_DIRECT; - am_time_t rampTime = 300; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - sink.volume = volume; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).Times(0); - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime)); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles.empty()); -} - -TEST_F(routingInterfaceTest,setSinkVolume) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_volume_t volume = 34; - am_RampType_e rampType = RAMP_GENIVI_DIRECT; - am_time_t rampTime = 300; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_SETSINKVOLUME); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,connect) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_connectionID_t connectionID; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_CONNECT); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[0].handle==handle.handle); - ASSERT_TRUE(listHandles[0].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,disconnect) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - am_connectionID_t connectionID; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = 1; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,connectionID)); - ASSERT_NE(handle.handle, 0); - ASSERT_EQ(handle.handleType, H_DISCONNECT); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles[1].handle==handle.handle); - ASSERT_TRUE(listHandles[1].handleType==handle.handleType); -} - -TEST_F(routingInterfaceTest,nothingTodisconnect) -{ - am_Handle_s handle; - am_connectionID_t connectionID = 4; - std::vector listHandles; - ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,connectionID)); - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); - ASSERT_TRUE(listHandles.empty()); -} - -TEST_F(routingInterfaceTest,setSourceStateNoChange) -{ - am_Source_s source; - am_sourceID_t sourceID; - am_Domain_s domain; - am_domainID_t domainID; - am_Handle_s handle; - handle.handle = 0; - am_SourceState_e state = SS_PAUSED; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.domainID = 1; - source.sourceState = state; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).Times(0); - ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,sourceID,state)); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.h b/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.h deleted file mode 100644 index f102221..0000000 --- a/AudioManagerDaemon/test/routingInterface/routingInterfaceTest.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file routingInterfaces.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef ROUTINGINTERFACETEST_H_ -#define ROUTINGINTERFACETEST_H_ - -#include -#include -#include -#include -#include -#include -#include "MockRoutingInterface.h" -#include "DatabaseHandler.h" -#include "ControlReceiver.h" -#include "ControlSender.h" -#include "DatabaseObserver.h" -#include "SocketHandler.h" -#include "Router.h" -#include "../RoutingInterfaceBackdoor.h" -#include "../CommandInterfaceBackdoor.h" -#include "../CommonFunctions.h" - -namespace am -{ - -class routingInterfaceTest: public ::testing::Test -{ -public: - routingInterfaceTest(); - ~routingInterfaceTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - SocketHandler pSocketHandler; - DatabaseHandler pDatabaseHandler; - RoutingSender pRoutingSender; - CommandSender pCommandSender; - ControlSender pControlSender; - Router pRouter; - MockRoutingSendInterface pMockInterface; - RoutingInterfaceBackdoor pRoutingInterfaceBackdoor; - CommandInterfaceBackdoor pCommandInterfaceBackdoor; - ControlReceiver pControlReceiver; - DatabaseObserver pObserver; - CommonFunctions pCF; - void SetUp(); - void TearDown(); -}; - -} - -#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerDaemon/test/sockethandler/CMakeLists.txt b/AudioManagerDaemon/test/sockethandler/CMakeLists.txt deleted file mode 100644 index 8858e5a..0000000 --- a/AudioManagerDaemon/test/sockethandler/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger ControlInterfaceTest -# -# \file CMakeLists.txt -# -# \date 20-Oct-2011 3:42:04 PM -# \author Christian Mueller (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 Mueller 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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(socketHandlerTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set(STD_INCLUDE_DIRS "/usr/include") -set(DBUS_FOLDER ${CMAKE_SOURCE_DIR}/../../../dbusInterfaces) -set(AUDIO_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../../includes) -set(DBUS_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../../../dbusIncludes) -set(INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../include) - - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB Socket_SRCS_CXX - "../../src/SocketHandler.cpp" - "../../src/DLTWrapper.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(socketHandlerTest ${Socket_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(socketHandlerTest - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - gtest - gmock -) - -INSTALL(TARGETS socketHandlerTest - DESTINATION "~/AudioManagerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - - diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp deleted file mode 100644 index 91eee2c..0000000 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file sockethandlerTest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "sockethandlerTest.h" -#include -#include /* for socket(), connect(), (), and recv() */ -#include /* for sockaddr_in and inet_addr() */ -#include -#include -#include -#include -#include - -//todo: expand test, implement more usecases -//todo: test removeFD - -#define SOCK_PATH "/tmp/mysock" - -using namespace testing; -using namespace am; - -sockethandlerTest::sockethandlerTest() -{ -} - -sockethandlerTest::~sockethandlerTest() -{ -} - -timerCallBack::timerCallBack(SocketHandler *myHandler) : - pTimer1Callback(this, &timerCallBack::timer1Callback), // - pTimer2Callback(this, &timerCallBack::timer2Callback), // - pTimer3Callback(this, &timerCallBack::timer3Callback), // - pTimer4Callback(this, &timerCallBack::timer4Callback), // - mSocketHandler(myHandler) - -{ -} - -am::timerCallBack::~timerCallBack() -{ -} - -void am::timerCallBack::timer1Callback(sh_timerHandle_t handle, void* userData) -{ - (void) handle; - (void) userData; - std::cout << "callback1 called" << std::endl; - timespec timeout; - timeout.tv_nsec = 0; - timeout.tv_sec = 1; - shTimerCallBack *buf = &pTimer1Callback; - sh_timerHandle_t handle_; - mSocketHandler->addTimer(timeout, buf, handle_, NULL); -} - -void am::timerCallBack::timer2Callback(sh_timerHandle_t handle, void* userData) -{ - (void) handle; - (void) userData; - std::cout << "callback2 called" << std::endl; - timespec timeout; - timeout.tv_nsec = 0; - timeout.tv_sec = 1; - shTimerCallBack *buf = &pTimer2Callback; - sh_timerHandle_t handle_; - mSocketHandler->addTimer(timeout, buf, handle_, NULL); -} - -void am::timerCallBack::timer3Callback(sh_timerHandle_t, void* userData) -{ - (void) userData; - std::cout << "callback3 called" << std::endl; -} - -void am::timerCallBack::timer4Callback(sh_timerHandle_t, void* userData) -{ - (void) userData; - std::cout << "callback4 called" << std::endl; - mSocketHandler->stop_listening(); -} - -void* playWithSocketServer(void* data) -{ - (void) data; - SocketHandler myHandler; - SamplePlugin::sockType_e type = SamplePlugin::INET; - SamplePlugin myplugin(&myHandler, type); - myHandler.start_listenting(); - return (NULL); -} - -void* playWithUnixSocketServer(void* data) -{ - (void) data; - SocketHandler myHandler; - SamplePlugin::sockType_e type = SamplePlugin::UNIX; - SamplePlugin myplugin(&myHandler, type); - myHandler.start_listenting(); - return (NULL); -} - -TEST(sockethandlerTest,playWithUNIXSockets) -{ - pthread_t serverThread; - struct sockaddr_un servAddr; - int socket_; - - //creates a thread that handles the serverpart - pthread_create(&serverThread, NULL, playWithUnixSocketServer, NULL); - - sleep(1); //we need that here because the port needs to be opened - if ((socket_ = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - std::cout << "socket problem" << std::endl; - - } - - memset(&servAddr, 0, sizeof(servAddr)); - strcpy(servAddr.sun_path, SOCK_PATH); - servAddr.sun_family = AF_UNIX; - if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) - { - std::cout << "ERROR: connect() failed\n" << std::endl; - } - - for (int i = 0; i <= 1000; i++) - { - std::string string("Got It?"); - send(socket_, string.c_str(), string.size(), 0); - } - std::string string("finish!"); - send(socket_, string.c_str(), string.size(), 0); - - pthread_join(serverThread, NULL); -} - -TEST(sockethandlerTest,playWithSockets) -{ - pthread_t serverThread; - struct sockaddr_in servAddr; - unsigned short servPort = 6060; - struct hostent *host; - int socket_; - - //creates a thread that handles the serverpart - pthread_create(&serverThread, NULL, playWithSocketServer, NULL); - - sleep(1); //we need that here because the port needs to be opened - if ((socket_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) - { - std::cout << "socket problem" << std::endl; - - } - - if ((host = (struct hostent*) gethostbyname("localhost")) == 0) - { - std::cout << "ERROR: gethostbyname() failed\n" << std::endl; - exit(1); - } - - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); - servAddr.sin_port = htons(servPort); - - if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) - { - std::cout << "ERROR: connect() failed\n" << std::endl; - } - - for (int i = 0; i <= 1000; i++) - { - std::string string("Got It?"); - send(socket_, string.c_str(), string.size(), 0); - } - std::string string("finish!"); - send(socket_, string.c_str(), string.size(), 0); - - pthread_join(serverThread, NULL); -} - -TEST(sockethandlerTest,playWithTimers) -{ - gDispatchDone = 0; - SocketHandler myHandler; - timerCallBack testCallback(&myHandler); - timespec timeoutTime, timeout2, timeout3, timeout4; - timeoutTime.tv_sec = 3; - timeoutTime.tv_nsec = 0; - timeout2.tv_nsec = 0; - timeout2.tv_sec = 1; - timeout3.tv_nsec = 000000000; - timeout3.tv_sec = 2; - timeout4.tv_nsec = 0; - timeout4.tv_sec = 13; - shTimerCallBack* buf = &testCallback.pTimer1Callback; - shTimerCallBack* buf2 = &testCallback.pTimer2Callback; - shTimerCallBack* buf3 = &testCallback.pTimer3Callback; - shTimerCallBack* buf4 = &testCallback.pTimer4Callback; - sh_timerHandle_t handle; - myHandler.addTimer(timeoutTime, buf, handle, NULL); - myHandler.addTimer(timeout2, buf2, handle, NULL); - myHandler.addTimer(timeout3, buf3, handle, NULL); - myHandler.addTimer(timeout4, buf4, handle, NULL); - myHandler.start_listenting(); - -} - -void sockethandlerTest::SetUp() -{ -} - -void sockethandlerTest::TearDown() -{ -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -am::SamplePlugin::SamplePlugin(SocketHandler *mySocketHandler, sockType_e socketType) : - connectFiredCB(this, &SamplePlugin::connectSocket), // - receiveFiredCB(this, &SamplePlugin::receiveData), // - sampleDispatchCB(this, &SamplePlugin::dispatchData), // - sampleCheckCB(this, &SamplePlugin::check), // - mSocketHandler(mySocketHandler), // - mConnecthandle(), // - mReceiveHandle(), // - msgList() -{ - int yes = 1; - - int socketHandle; - struct sockaddr_in servAddr; - struct sockaddr_un unixAddr; - unsigned int servPort = 6060; - - switch (socketType) - { - case UNIX: - socketHandle = socket(AF_UNIX, SOCK_STREAM, 0); - unixAddr.sun_family = AF_UNIX; - strcpy(unixAddr.sun_path, SOCK_PATH); - unlink(unixAddr.sun_path); - bind(socketHandle, (struct sockaddr *) &unixAddr, strlen(unixAddr.sun_path) + sizeof(unixAddr.sun_family)); - break; - case INET: - socketHandle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - setsockopt(socketHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = INADDR_ANY; - servAddr.sin_port = htons(servPort); - bind(socketHandle, (struct sockaddr *) &servAddr, sizeof(servAddr)); - break; - default: - break; - } - - if (listen(socketHandle, 3) < 0) - { - std::cout << "listen ok" << std::endl; - } /* if */ - - int a = 1; - ioctl(socketHandle, FIONBIO, (char *) &a); - setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof(a)); - - short events = 0; - events |= POLLIN; - mySocketHandler->addFDPoll(socketHandle, events, NULL, &connectFiredCB, NULL, NULL, NULL, mConnecthandle); - std::cout << "setup server - listening" << std::endl; -} - -void am::SamplePlugin::connectSocket(const pollfd pollfd1, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //first, accept the connection, create a new filedescriptor - std::cout << "Got a connection request !" << std::endl; - struct sockaddr answer; - socklen_t len = sizeof(answer); - int receiveFD = accept(pollfd1.fd, (struct sockaddr*) &answer, &len); - - //set the correct event: - short event = 0; - event |= POLLIN; - - //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data - mSocketHandler->addFDPoll(receiveFD, event, NULL, &receiveFiredCB, &sampleCheckCB, &sampleDispatchCB, NULL, mReceiveHandle); - -} - -void am::SamplePlugin::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //initialize buffer - char buffer[10]; - //read until buffer is full or no more data is there - int read = recv(pollfd.fd, buffer, 7, NULL); - if (read > 1) - { - //read the message and store it in a queue - std::string msg = std::string(buffer, read); - msgList.push(msg); - std::cout << "Got a message !" << std::endl; - } -} - -bool am::SamplePlugin::dispatchData(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //read data from the queue - std::cout << "Data:" << msgList.front() << std::endl; - - //if the message was our finish message, we quit the poll loop - if (msgList.front().compare("finish!") == 0) - { - mSocketHandler->stop_listening(); - } - //remove the message from the queue and return false if there is no more message to read. - msgList.pop(); - if (msgList.size() != 0) - return true; - return false; -} - -bool am::SamplePlugin::check(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //checks if there is data to dispatch - std::cout << "check!:" << std::endl; - if (msgList.size() != 0) - return true; - return false; -} - diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h deleted file mode 100644 index abb8ace..0000000 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file sockethandlerTest.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef SOCKETHANDLERTEST_H_ -#define SOCKETHANDLERTEST_H_ - -#include -#include -#include "SocketHandler.h" - -namespace am -{ - -class SamplePlugin -{ -public: - enum sockType_e - { - UNIX, INET - }; - SamplePlugin(SocketHandler *mySocketHandler, sockType_e socketType); - ~SamplePlugin() - { - } - ; - void connectSocket(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - void receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - bool dispatchData(const sh_pollHandle_t handle, void* userData); - bool check(const sh_pollHandle_t handle, void* userData); - shPollFired_T connectFiredCB; - shPollFired_T receiveFiredCB; - shPollDispatch_T sampleDispatchCB; - shPollCheck_T sampleCheckCB; -private: - SocketHandler *mSocketHandler; - sh_pollHandle_t mConnecthandle, mReceiveHandle; - std::queue msgList; -}; - -class timerCallBack -{ -public: - timerCallBack(SocketHandler *SocketHandler); - virtual ~timerCallBack(); - void timer1Callback(sh_timerHandle_t handle, void * userData); - void timer2Callback(sh_timerHandle_t handle, void * userData); - void timer3Callback(sh_timerHandle_t handle, void * userData); - void timer4Callback(sh_timerHandle_t handle, void * userData); - shTimerCallBack_T pTimer1Callback; - shTimerCallBack_T pTimer2Callback; - shTimerCallBack_T pTimer3Callback; - shTimerCallBack_T pTimer4Callback; - SocketHandler *mSocketHandler; -}; - -class sockethandlerTest: public ::testing::Test -{ -public: - sockethandlerTest(); - ~sockethandlerTest(); - void SetUp(); - void TearDown(); -}; - -} /* namespace am */ -#endif /* SOCKETHANDLERTEST_H_ */ diff --git a/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.cpp b/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.cpp deleted file mode 100644 index d727fff..0000000 --- a/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * CAmTelnetServerTest.cpp - * - * Created on: Feb 7, 2012 - * Author: demo - */ - -#include /* for socket(), connect(), (), and recv() */ -#include /* for sockaddr_in and inet_addr() */ -#include /* for struct hostent */ - -#include "CAmTelnetServerTest.h" -#include "CommandReceiver.h" -#include "RoutingReceiver.h" -#include "ControlReceiver.h" - - -using namespace testing; -using namespace am; -using namespace std; - - -static std::string controllerPlugin = std::string(CONTROLLER_PLUGIN); -static unsigned short servPort = 6060; -static int staticSocket = -1; -static SocketHandler* mpSocketHandler = NULL; - -void* startSocketHandler(void* data) -{ - MyEnvironment* Env = static_cast(data); - SocketHandler mySocketHandler; - Env->setSocketHandler(&mySocketHandler); - mySocketHandler.start_listenting(); - Env->setSocketHandler(NULL); - return (NULL); -} - -MyEnvironment::MyEnvironment() -: mlistRoutingPluginDirs() -, mlistCommandPluginDirs() -//, mpSocketHandler(NULL) -, mDatabasehandler(std::string(":memory:")) -, mRoutingSender(mlistRoutingPluginDirs) -, mCommandSender(mlistRoutingPluginDirs) -, mControlSender(controllerPlugin) -, mRouter(&mDatabasehandler,&mControlSender) -, mpCommandReceiver(NULL) -, mpRoutingReceiver(NULL) -, mpControlReceiver(NULL) -, mpTelnetServer(NULL) -, mSocketHandlerThread(0) -{ -} - -MyEnvironment::~MyEnvironment() -{ - usleep(500); - if(NULL != mpTelnetServer) - delete(mpTelnetServer); - if(NULL != mpControlReceiver) - delete(mpControlReceiver); - if(NULL != mpRoutingReceiver) - delete(mpRoutingReceiver); - if(NULL != mpCommandReceiver) - delete(mpCommandReceiver); -} - -void MyEnvironment::SetUp() -{ - pthread_create(&mSocketHandlerThread, NULL, startSocketHandler, this); - sleep(1); -} - -void MyEnvironment::TearDown() -{ - -} - -void MyEnvironment::setSocketHandler(SocketHandler* pSocketHandler) -{ - mpSocketHandler = pSocketHandler; - - if(NULL != pSocketHandler) - { - mpCommandReceiver = new CommandReceiver(&mDatabasehandler,&mControlSender,mpSocketHandler); - mpRoutingReceiver = new RoutingReceiver(&mDatabasehandler,&mRoutingSender,&mControlSender,mpSocketHandler); - mpControlReceiver = new ControlReceiver(&mDatabasehandler,&mRoutingSender,&mCommandSender,mpSocketHandler,&mRouter); - - //startup all the Plugins and Interfaces - mControlSender.startupController(mpControlReceiver); - mCommandSender.startupInterfaces(mpCommandReceiver); - mRoutingSender.startupInterfaces(mpRoutingReceiver); - - //when the routingInterface is done, all plugins are loaded: - mControlSender.setControllerReady(); - - // Starting TelnetServer - mpTelnetServer = new TelnetServer(mpSocketHandler,&mCommandSender,mpCommandReceiver,&mRoutingSender,mpRoutingReceiver,&mControlSender,mpControlReceiver,&mDatabasehandler,&mRouter,servPort,3); - } -} - -void MyEnvironment::stopSocketHandler() -{ - mpSocketHandler->stop_listening(); -} - -CAmTelnetServerTest::CAmTelnetServerTest() -{ - -} - -CAmTelnetServerTest::~CAmTelnetServerTest() -{ - -} - -void CAmTelnetServerTest::SetUp() -{ - -} - -void CAmTelnetServerTest::TearDown() -{ - -} - -TEST_F(CAmTelnetServerTest,connectTelnetServer) -{ - struct sockaddr_in servAddr; - - staticSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - ASSERT_GE(staticSocket,0); - - struct hostent *host = (struct hostent*) gethostbyname("localhost"); - if (host == 0) - { - std::cout << " ERROR: gethostbyname() failed\n" << std::endl; - return; - } - - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); - servAddr.sin_port = htons(servPort); - - int return_connect = connect(staticSocket, (struct sockaddr *) &servAddr, sizeof(servAddr)); - ASSERT_GE(return_connect,0); - - char buffer[1000]; - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); -} - -TEST_F(CAmTelnetServerTest,sendCmdTelnetServer) -{ - std::string string("help"); - - ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); - ASSERT_EQ(sizesent,string.size()); - - char buffer[1000]; - memset(buffer,0,sizeof(buffer)); - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); -} - -TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) -{ - std::string string ("exit"); - - mpSocketHandler->stop_listening(); - - ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); - ASSERT_EQ(sizesent,string.size()); - - char buffer[1000]; - memset(buffer,0,sizeof(buffer)); - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); - - close(staticSocket); - staticSocket = -1; -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new MyEnvironment); - (void) env; - return RUN_ALL_TESTS(); -} diff --git a/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.h b/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.h deleted file mode 100644 index 182dfa1..0000000 --- a/AudioManagerDaemon/test/telnetserver/CAmTelnetServerTest.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * CAmTelnetServerTest.h - * - * Created on: Feb 7, 2012 - * Author: Frank Herchet - */ - -#ifndef CAMTELNETSERVERTEST_H_ -#define CAMTELNETSERVERTEST_H_ - -#include "gtest/gtest.h" -#include "TelnetServer.h" -#include "DatabaseHandler.h" -#include "RoutingSender.h" -#include "CommandSender.h" -#include "ControlSender.h" -#include "Router.h" - -namespace am -{ - -class SocketHandler; -class DatabaseHandler; -class RoutingSender; -class CommandSender; -class ControlSender; -class Router; -class CommandReceiver; -class RoutingReceiver; -class ControlReceiver; -class TelnetServer; - - -class MyEnvironment : public ::testing::Environment -{ - public: - MyEnvironment(); - - ~MyEnvironment(); - // Override this to define how to set up the environment. - void SetUp(); - // Override this to define how to tear down the environment. - void TearDown(); - - void setSocketHandler(SocketHandler* pSocketHandler); - - void stopSocketHandler(); - - std::vector mlistRoutingPluginDirs; - std::vector mlistCommandPluginDirs; - - //SocketHandler* mpSocketHandler; - DatabaseHandler mDatabasehandler; - RoutingSender mRoutingSender; - CommandSender mCommandSender; - ControlSender mControlSender; - Router mRouter; - - CommandReceiver* mpCommandReceiver; - RoutingReceiver* mpRoutingReceiver; - ControlReceiver* mpControlReceiver; - - TelnetServer* mpTelnetServer; - - pthread_t mSocketHandlerThread; -}; - -class CAmTelnetServerTest : public ::testing::Test -{ - public: - CAmTelnetServerTest(); - ~CAmTelnetServerTest(); - - - void SetUp() ; - - void TearDown() ; - - //int mSocket; -}; - -} - - - - -#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerDaemon/test/telnetserver/CMakeLists.txt b/AudioManagerDaemon/test/telnetserver/CMakeLists.txt deleted file mode 100644 index ff6d90d..0000000 --- a/AudioManagerDaemon/test/telnetserver/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -# -# Copyright (C) 2011, BMW AG -# -# GeniviAudioMananger ControlInterfaceTest -# -# \file CMakeLists.txt -# -# \date 13-Feb-2012 -# \author Frank Herchet (frank.fh.herchet@bmw.de) -# -# \section License -# GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause) -# Copyright (C) 2012, BMW AG Frank Herchet frank.fh.herchet@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 . -# 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. -# - -cmake_minimum_required(VERSION 2.6) - -PROJECT(telnetServerText) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set(STD_INCLUDE_DIRS "/usr/include") -set(DBUS_FOLDER ${CMAKE_SOURCE_DIR}/../../../dbusInterfaces) -set(AUDIO_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../../includes) -set(DBUS_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../../../dbusIncludes) -set(INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/../../include) - - -FIND_PACKAGE(PkgConfig) -pkg_check_modules(DLT REQUIRED automotive-dlt) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${DLT_INCLUDE_DIRS} - ${DBUS_INCLUDE_DIR} - ${GTEST_INCLUDE_DIR} - ${INCLUDES_FOLDER} -) - -file(GLOB TELNET_SRCS_CXX - "../../src/CommandReceiver.cpp" - "../../src/CommandSender.cpp" - "../../src/ControlReceiver.cpp" - "../../src/ControlSender.cpp" - "../../src/DatabaseHandler.cpp" - "../../src/DatabaseObserver.cpp" - "../../src/RoutingReceiver.cpp" - "../../src/RoutingSender.cpp" - "../../src/SocketHandler.cpp" - "../../src/TelnetServer.cpp" - "../../src/Router.cpp" - "../../src/DLTWrapper.cpp" - "../../src/CAmTelnetMenuHelper.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(telnetServerTest ${TELNET_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(telnetServerTest - ${SQLITE_LIBRARIES} - ${DLT_LIBRARIES} - ${DBUS_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${CMAKE_THREAD_LIBS_INIT} - ${GTEST_LIBRARIES} - gmock -) - -INSTALL(TARGETS telnetServerTest - DESTINATION "~/TelnetServerTest/" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - -SET(ADD_DEPEND "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "libgtest-dev(>=1.6.0-1)" "google-mock" "libpthread-stubs0") -set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") - - diff --git a/CMakeLists.txt b/CMakeLists.txt index aa944de..f847ec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,14 +118,13 @@ else(USE_BUILD_LIBS) endif(USE_BUILD_LIBS) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) -SET(AUDIO_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/includes) +SET(AUDIO_include_FOLDER ${CMAKE_SOURCE_DIR}/include) SET(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/doc) SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) SET(TEST_EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/test) SET(DOXY_FILE ${CMAKE_SOURCE_DIR}/cmake/DoxyFile.in) -SET(INTROSPECTION_COMMAND_XML_FILE "${AUDIO_INCLUDES_FOLDER}/dbus/CommandInterface.xml") -CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/config.cmake ${CMAKE_SOURCE_DIR}/includes/config.h ) +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/config.cmake ${CMAKE_SOURCE_DIR}/include/config.h ) IF(WITH_DLT) @@ -239,7 +238,7 @@ STRING(REGEX REPLACE ".$" "" all_DEPENDENCIES ${all_DEPENDENCIES}) execute_process(COMMAND cp ${CMAKE_MODULE_PATH}/add_package_dependencies.sh ${CMAKE_CURRENT_BINARY_DIR}) #component based dep package generation is only supported above 2.8.5 -IF (${CMAKE_VERSION} VERSION_GREATER 2.9.4) +IF (${CMAKE_VERSION} VERSION_GREATER 2.8.5) SET(CPACK_COMPONENTS_ALL bin sampleplugins tests dev) SET(CPACK_COMPONENTS_IGNORE_GROUPS 1) @@ -252,12 +251,12 @@ IF (${CMAKE_VERSION} VERSION_GREATER 2.9.4) COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-tests.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${tests_DEPENDENCIES}\" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-dev.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${dev_DEPENDENCIES}\" ) -ELSE (${CMAKE_VERSION} VERSION_GREATER 2.9.4) +ELSE (${CMAKE_VERSION} VERSION_GREATER 2.8.5) IF(${CMAKE_VERSION} VERSION_GREATER 2.8.3) ADD_CUSTOM_TARGET(genivi_package COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DUSE_BUILD_LIBS=ON COMMAND make package - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${all_DEPENDENCIES}\" + COMMAND ${CMAKE_CURRENT_BINARY_DIR}A logical block opening on t/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${all_DEPENDENCIES}\" ) ELSE(${CMAKE_VERSION} VERSION_GREATER 2.8.3) ADD_CUSTOM_TARGET(genivi_package @@ -268,7 +267,7 @@ ELSE (${CMAKE_VERSION} VERSION_GREATER 2.9.4) COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${all_DEPENDENCIES}\" ) ENDIF(${CMAKE_VERSION} VERSION_GREATER 2.8.3) -ENDIF (${CMAKE_VERSION} VERSION_GREATER 2.9.4) +ENDIF (${CMAKE_VERSION} VERSION_GREATER 2.8.5) INCLUDE(CPack) diff --git a/PluginCommandInterfaceDbus/CMakeLists.txt b/PluginCommandInterfaceDbus/CMakeLists.txt index 7c4c776..2d5c6cc 100644 --- a/PluginCommandInterfaceDbus/CMakeLists.txt +++ b/PluginCommandInterfaceDbus/CMakeLists.txt @@ -4,9 +4,9 @@ PROJECT(PluginCommandInterfaceDbus) set(LIBRARY_OUTPUT_PATH ${PLUGINS_OUTPUT_PATH}/command) set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/CommandDBusPlugin) -set(INCLUDES_FOLDER "include") +set(include_FOLDER "include") -FILE(READ "${AUDIO_INCLUDES_FOLDER}/command/CommandSendInterface.h" VERSION_BUFFER LIMIT 6000) +FILE(READ "${AUDIO_include_FOLDER}/command/IAmCommandSend.h" VERSION_BUFFER LIMIT 6000) STRING(REGEX MATCH "CommandSendVersion*.[^0-9]*[0-9].[0-9]*[0-9]" LIB_INTERFACE_VERSION_STRING ${VERSION_BUFFER}) STRING(REGEX REPLACE "CommandSendVersion*.." "" LIB_INTERFACE_VERSION ${LIB_INTERFACE_VERSION_STRING}) MESSAGE(STATUS "Building against command interface version ${LIB_INTERFACE_VERSION}") @@ -18,9 +18,9 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR} - ${AUDIO_INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} ${DLT_INCLUDE_DIRS} - ${INCLUDES_FOLDER} + ${include_FOLDER} ) # all source files go here @@ -38,7 +38,7 @@ TARGET_LINK_LIBRARIES(PluginCommandInterfaceDbus ) IF(WITH_TESTS) -# add_subdirectory (test) + add_subdirectory (test) ENDIF(WITH_TESTS) #IF(WITH_DOCUMENTATION) @@ -56,5 +56,7 @@ INSTALL(TARGETS PluginCommandInterfaceDbus COMPONENT sampleplugins ) +execute_process(COMMAND cp "${CMAKE_SOURCE_DIR}/PluginCommandInterfaceDbus/${include_FOLDER}/CommandInterface.xml" ${EXECUTABLE_OUTPUT_PATH}/CommandInterface.xml) + SET(ADD_DEPEND "audiomanager-bin" "dlt" "libdbus-1-3(>=1.2.16)") set_property(GLOBAL APPEND PROPERTY sampleplugins_prop "${ADD_DEPEND}") diff --git a/PluginCommandInterfaceDbus/include/CAmCommandSenderDbus.h b/PluginCommandInterfaceDbus/include/CAmCommandSenderDbus.h new file mode 100644 index 0000000..ad625dc --- /dev/null +++ b/PluginCommandInterfaceDbus/include/CAmCommandSenderDbus.h @@ -0,0 +1,123 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CommandSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef DBUSCOMMANDSENDER_H_ +#define DBUSCOMMANDSENDER_H_ + +#include +#include +#include "shared/CAmDbusWrapper.h" +#include "CAmDbusMessageHandler.h" +#include "IAmCommandReceiverShadow.h" +#include "command/IAmCommandSend.h" + +#ifdef UNIT_TEST +#include "../test/CAmCommandSenderDbusBackdoor.h" +#endif + + + +namespace am +{ + +const char MY_NODE[] = "CommandInterface"; + +/** + * Dbus Implementation of CommandSendInterface + */ +class CAmCommandSenderDbus: public IAmCommandSend +{ +public: + CAmCommandSenderDbus(); + virtual ~CAmCommandSenderDbus(); + am_Error_e startupInterface(IAmCommandReceive* commandreceiveinterface); + void setCommandReady(const uint16_t handle); + void setCommandRundown(const uint16_t handle); + void cbNewMainConnection(const am_MainConnectionType_s mainConnection); + void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection); + void cbNewSink(const am_SinkType_s& sink); + void cbRemovedSink(const am_sinkID_t sinkID); + void cbNewSource(const am_SourceType_s& source); + void cbRemovedSource(const am_sourceID_t source); + void cbNumberOfSinkClassesChanged(); + void cbNumberOfSourceClassesChanged(); + void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); + void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); + void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); + void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); + void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); + void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); + void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); + void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty); + void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); + void getInterfaceVersion(std::string& version) const; + +#ifdef UNIT_TEST + friend class CAmCommandSenderDbusBackdoor; +#endif +private: + CAmDbusMessageHandler mCAmDbusMessageHandler; ///< ! instance of message handler + IAmCommandReceiverShadow mIAmCommandReceiverShadow; ///< ! instance of shadow + CAmDbusWrapper* mpCAmDbusWrapper; ///< ! pointer to dbus wrapper + IAmCommandReceive* mpIAmCommandReceive; ///< ! pointer to commandReceive Interface + bool mReady; ///< ! if false, calls shall be ignored. + + /** + * list of sinks, needed to send out only deltas + */ + std::vector mlistSinks; + + /** + * list of sources, needed to send out only deltas + */ + std::vector mlistSources; + + /** + * used as comparison function for am_SinkType_s + */ + struct sortBySinkID + { + bool operator()(const am_SinkType_s & a, const am_SinkType_s & b) + { + return (a.sinkID < b.sinkID); + } + }; + + /** + * used as comparison function for am_SourceType_s + */ + struct sortBySourceID + { + bool operator()(const am_SourceType_s & a, const am_SourceType_s & b) + { + return (a.sourceID < b.sourceID); + } + }; + +}; + +} + +#endif /* DBUSCOMMANDSENDER_H_ */ diff --git a/PluginCommandInterfaceDbus/include/CAmDbusMessageHandler.h b/PluginCommandInterfaceDbus/include/CAmDbusMessageHandler.h new file mode 100644 index 0000000..5431e2b --- /dev/null +++ b/PluginCommandInterfaceDbus/include/CAmDbusMessageHandler.h @@ -0,0 +1,127 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file DBusMessageHandler + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef _DBUSMESSAGEHANDLER_H_ +#define _DBUSMESSAGEHANDLER_H_ + +#include +#include +#include +#include +#include +#include "audiomanagertypes.h" + + +namespace am +{ + +/** + * handles DBus Messages, is used to extract & append parameters and send messages + */ +class CAmDbusMessageHandler +{ +public: + CAmDbusMessageHandler(); + ~CAmDbusMessageHandler(); + + /** + * sets the DBus Connection + * @param connection pointer to the DBus Connection + */ + void setDBusConnection(DBusConnection*& connection); + + /** + * is called to initiate the receiving of a message + * @param msg pointer to the message to be received + */ + void initReceive(DBusMessage* msg); + + /** + * is called to initiate the reply to a message + * @param msg pointer to the message the reply is for + */ + void initReply(DBusMessage* msg); + + /** + * inits a signal to be sent via dbus + * parameters can be added before sending the signal + * @param path the path + * @param signalName the signal name + */ + void initSignal(std::string path, std::string signalName); + + /** + * sends out the message + */ + void sendMessage(); + + /** + * the get functions return a value from the received dbus message + * @return + */ + dbus_uint16_t getUInt(); + dbus_int16_t getInt(); + dbus_bool_t getBool(); + char getByte(); + double getDouble(); + char* getString(); + void getProperty(dbus_int16_t& type, dbus_int16_t& value); + + /** + * the overloaded append function appends different datatypes to the dbusmessage + */ + void append(dbus_int16_t toAppend); + void append(dbus_uint16_t toAppend); + void append(char toAppend); + void append(bool toAppend); + void append(double toAppend); + void append(const am::am_SinkType_s& sinkType); + void append(const am::am_SourceType_s& sourceType); + void append(const am::am_MainSoundProperty_s mainSoundProperty); + void append(const am::am_Availability_s & availability); + void append(const am::am_SystemProperty_s & SystemProperty); + void append(const std::vector& listMainConnections); + void append(const std::vector& listMainSinks); + void append(const std::vector& listMainSources); + void append(const std::vector& listMainSoundProperties); + void append(const std::vector& listSourceClasses); + void append(const std::vector& listSinkClasses); + void append(const std::vector& listSystemProperties); + +private: + + DBusMessageIter mDBusMessageIter; + DBusError mDBusError; + dbus_uint32_t mSerial; + std::string mErrorName; + std::string mErrorMsg; + DBusMessage* mpDBusMessage; + DBusMessage* mpReveiveMessage; + DBusConnection* mpDBusConnection; +}; + +} + +#endif // _DBUSMESSAGEWRAPPER_H_ diff --git a/PluginCommandInterfaceDbus/include/CommandInterface.xml b/PluginCommandInterfaceDbus/include/CommandInterface.xml new file mode 100644 index 0000000..f6f07a0 --- /dev/null +++ b/PluginCommandInterfaceDbus/include/CommandInterface.xml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PluginCommandInterfaceDbus/include/CommandReceiverShadow.h b/PluginCommandInterfaceDbus/include/CommandReceiverShadow.h deleted file mode 100644 index d2c63cb..0000000 --- a/PluginCommandInterfaceDbus/include/CommandReceiverShadow.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file CommandReceiverShadow.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef COMMANDRECEIVERSHADOW_H_ -#define COMMANDRECEIVERSHADOW_H_ - -#include -#include -#include -#include -#include -#include "DBusMessageHandler.h" - -namespace am -{ - -class CommandReceiverShadow; - -typedef void (CommandReceiverShadow::*CallBackMethod)(DBusConnection *connection, DBusMessage *message); - -/** - * receives the DBus Callbacks, marhsalls and demarshalls the parameters and calls CommandReceive - */ -class CommandReceiverShadow -{ -public: - CommandReceiverShadow(); - virtual ~CommandReceiverShadow(); - void connect(DBusConnection *conn, DBusMessage *msg); - void disconnect(DBusConnection *conn, DBusMessage *msg); - void setVolume(DBusConnection *conn, DBusMessage *msg); - void volumeStep(DBusConnection *conn, DBusMessage *msg); - void setSinkMuteState(DBusConnection *conn, DBusMessage *msg); - void setMainSinkSoundProperty(DBusConnection *conn, DBusMessage *msg); - void setMainSourceSoundProperty(DBusConnection *conn, DBusMessage *msg); - void setSystemProperty(DBusConnection *conn, DBusMessage *msg); - void getListMainConnections(DBusConnection *conn, DBusMessage *msg); - void getListMainSinks(DBusConnection *conn, DBusMessage *msg); - void getListMainSources(DBusConnection *conn, DBusMessage *msg); - void getListMainSinkSoundProperties(DBusConnection *conn, DBusMessage *msg); - void getListMainSourceSoundProperties(DBusConnection *conn, DBusMessage *msg); - void getListSourceClasses(DBusConnection *conn, DBusMessage *msg); - void getListSinkClasses(DBusConnection *conn, DBusMessage *msg); - void getListSystemProperties(DBusConnection *conn, DBusMessage *msg); - void getTimingInformation(DBusConnection *conn, DBusMessage *msg); - - /** - * sets the pointer to the CommandReceiveInterface and registers Callback - * @param receiver - */ - void setCommandReceiver(CommandReceiveInterface*& receiver); -private: - CommandReceiveInterface* mCommandReceiveInterface; - DBusWrapper* mDBusWrapper; - typedef std::map functionMap_t; - functionMap_t mFunctionMap; - DBusMessageHandler mDBUSMessageHandler; - - /** - * receives a callback whenever the path of the plugin is called - */ - static DBusHandlerResult receiveCallback(DBusConnection *conn, DBusMessage *msg, void *user_data); - - /** - * dynamic delegate that handles the Callback of the static receiveCallback - * @param conn DBus connection - * @param msg DBus message - * @param user_data pointer to instance of CommandReceiverShadow - * @return - */ - DBusHandlerResult receiveCallbackDelegate(DBusConnection *conn, DBusMessage *msg); - - /** - * sends out introspectiondata read from an xml file. - * @param conn - * @param msg - */ - void sendIntrospection(DBusConnection* conn, DBusMessage* msg); - - /** - * creates the function map needed to combine DBus messages and function adresses - * @return the map - */ - functionMap_t createMap(); -}; - -} - -#endif /* COMMANDRECEIVERSHADOW_H_ */ diff --git a/PluginCommandInterfaceDbus/include/DBusCommandSender.h b/PluginCommandInterfaceDbus/include/DBusCommandSender.h deleted file mode 100644 index e64e6f6..0000000 --- a/PluginCommandInterfaceDbus/include/DBusCommandSender.h +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file CommandSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef DBUSCOMMANDSENDER_H_ -#define DBUSCOMMANDSENDER_H_ - -#ifdef UNIT_TEST -#include "../test/DbusCommandInterfaceBackdoor.h" -#endif - -#include -#include -#include -#include -#include "DBusMessageHandler.h" -#include "CommandReceiverShadow.h" - -namespace am -{ - -const char MY_NODE[] = "CommandInterface"; - -/** - * Dbus Implementation of CommandSendInterface - */ -class DbusCommandSender: public CommandSendInterface -{ -public: - DbusCommandSender(); - virtual ~DbusCommandSender(); - am_Error_e startupInterface(CommandReceiveInterface* commandreceiveinterface) ; - void setCommandReady(const uint16_t handle) ; - void setCommandRundown(const uint16_t handle) ; - void cbNewMainConnection(const am_MainConnectionType_s mainConnection) ; - void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) ; - void cbNewSink(const am_SinkType_s& sink) ; - void cbRemovedSink(const am_sinkID_t sinkID) ; - void cbNewSource(const am_SourceType_s& source) ; - void cbRemovedSource(const am_sourceID_t source) ; - void cbNumberOfSinkClassesChanged() ; - void cbNumberOfSourceClassesChanged() ; - void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) ; - void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) ; - void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) ; - void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) ; - void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) ; - void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) ; - void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) ; - void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty) ; - void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) ; - void getInterfaceVersion(std::string& version) const ; - -#ifdef UNIT_TEST - friend class DbusCommandInterfaceBackdoor; -#endif -private: - DBusMessageHandler mDBUSMessageHandler; - CommandReceiverShadow mCommandReceiverShadow; - DBusWrapper* mDBusWrapper; - CommandReceiveInterface* mCommandReceiveInterface; - bool mReady; ///< ! if false, calls shall be ignored. - - - /** - * list of sinks, needed to send out only deltas - */ - std::vector mlistSinks; - - /** - * list of sources, needed to send out only deltas - */ - std::vector mlistSources; - - /** - * used as comparison function for am_SinkType_s - */ - struct sortBySinkID - { - bool operator()(const am_SinkType_s & a, const am_SinkType_s & b) - { - return (a.sinkID < b.sinkID); - } - }; - - /** - * used as comparison function for am_SourceType_s - */ - struct sortBySourceID - { - bool operator()(const am_SourceType_s & a, const am_SourceType_s & b) - { - return (a.sourceID < b.sourceID); - } - }; - -}; - -} - -#endif /* DBUSCOMMANDSENDER_H_ */ diff --git a/PluginCommandInterfaceDbus/include/DBusMessageHandler.h b/PluginCommandInterfaceDbus/include/DBusMessageHandler.h deleted file mode 100644 index 71a4078..0000000 --- a/PluginCommandInterfaceDbus/include/DBusMessageHandler.h +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file DBusMessageHandler - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef _DBUSMESSAGEHANDLER_H_ -#define _DBUSMESSAGEHANDLER_H_ - -#include -#include -#include -#include -#include -#include - -namespace am -{ - -/** - * handles DBus Messages, is used to extract & append parameters and send messages - */ -class DBusMessageHandler -{ -public: - DBusMessageHandler(); - ~DBusMessageHandler(); - - /** - * sets the DBus Connection - * @param connection pointer to the DBus Connection - */ - void setDBusConnection(DBusConnection*& connection); - - /** - * is called to initiate the receiving of a message - * @param msg pointer to the message to be received - */ - void initReceive(DBusMessage* msg); - - /** - * is called to initiate the reply to a message - * @param msg pointer to the message the reply is for - */ - void initReply(DBusMessage* msg); - - /** - * inits a signal to be sent via dbus - * parameters can be added before sending the signal - * @param path the path - * @param signalName the signal name - */ - void initSignal(std::string path, std::string signalName); - - /** - * sends out the message - */ - void sendMessage(); - - /** - * the get functions return a value from the received dbus message - * @return - */ - dbus_uint16_t getUInt(); - dbus_int16_t getInt(); - dbus_bool_t getBool(); - char getByte(); - double getDouble(); - char* getString(); - void getProperty(dbus_int16_t& type, dbus_int16_t& value); - - /** - * the overloaded append function appends different datatypes to the dbusmessage - */ - void append(dbus_int16_t toAppend); - void append(dbus_uint16_t toAppend); - void append(char toAppend); - void append(bool toAppend); - void append(double toAppend); - void append(const am::am_SinkType_s& sinkType); - void append(const am::am_SourceType_s& sourceType); - void append(const am::am_MainSoundProperty_s mainSoundProperty); - void append(const am::am_Availability_s & availability); - void append(const am::am_SystemProperty_s & SystemProperty); - void append(const std::vector& listMainConnections); - void append(const std::vector& listMainSinks); - void append(const std::vector& listMainSources); - void append(const std::vector& listMainSoundProperties); - void append(const std::vector& listSourceClasses); - void append(const std::vector& listSinkClasses); - void append(const std::vector& listSystemProperties); - -private: - - DBusMessageIter mDBusMessageIter; - DBusError mDBusError; - dbus_uint32_t mSerial; - std::string mErrorName; - std::string mErrorMsg; - DBusMessage* mDbusMessage; - DBusMessage* mReveiveMessage; - DBusConnection* mDBusConnection; -}; - -} - -#endif // _DBUSMESSAGEWRAPPER_H_ diff --git a/PluginCommandInterfaceDbus/include/IAmCommandReceiverShadow.h b/PluginCommandInterfaceDbus/include/IAmCommandReceiverShadow.h new file mode 100644 index 0000000..dd5a23d --- /dev/null +++ b/PluginCommandInterfaceDbus/include/IAmCommandReceiverShadow.h @@ -0,0 +1,113 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CommandReceiverShadow.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef COMMANDRECEIVERSHADOW_H_ +#define COMMANDRECEIVERSHADOW_H_ + + + +#include +#include +#include "config.h" +#include "command/IAmCommandReceive.h" +#include "CAmDbusMessageHandler.h" +#include "shared/CAmDbusWrapper.h" + +namespace am +{ + +class IAmCommandReceiverShadow; + +typedef void (IAmCommandReceiverShadow::*CallBackMethod)(DBusConnection *connection, DBusMessage *message); + +/** + * receives the DBus Callbacks, marhsalls and demarshalls the parameters and calls CommandReceive + */ +class IAmCommandReceiverShadow +{ +public: + IAmCommandReceiverShadow(); + virtual ~IAmCommandReceiverShadow(); + void connect(DBusConnection *conn, DBusMessage *msg); + void disconnect(DBusConnection *conn, DBusMessage *msg); + void setVolume(DBusConnection *conn, DBusMessage *msg); + void volumeStep(DBusConnection *conn, DBusMessage *msg); + void setSinkMuteState(DBusConnection *conn, DBusMessage *msg); + void setMainSinkSoundProperty(DBusConnection *conn, DBusMessage *msg); + void setMainSourceSoundProperty(DBusConnection *conn, DBusMessage *msg); + void setSystemProperty(DBusConnection *conn, DBusMessage *msg); + void getListMainConnections(DBusConnection *conn, DBusMessage *msg); + void getListMainSinks(DBusConnection *conn, DBusMessage *msg); + void getListMainSources(DBusConnection *conn, DBusMessage *msg); + void getListMainSinkSoundProperties(DBusConnection *conn, DBusMessage *msg); + void getListMainSourceSoundProperties(DBusConnection *conn, DBusMessage *msg); + void getListSourceClasses(DBusConnection *conn, DBusMessage *msg); + void getListSinkClasses(DBusConnection *conn, DBusMessage *msg); + void getListSystemProperties(DBusConnection *conn, DBusMessage *msg); + void getTimingInformation(DBusConnection *conn, DBusMessage *msg); + + /** + * sets the pointer to the CommandReceiveInterface and registers Callback + * @param receiver + */ + void setCommandReceiver(IAmCommandReceive*& receiver); +private: + typedef std::map functionMap_t; + functionMap_t mFunctionMap; + CAmDbusMessageHandler mDBUSMessageHandler; + IAmCommandReceive* mpIAmCommandReceive; + CAmDbusWrapper* mpCAmDbusWrapper; + + /** + * receives a callback whenever the path of the plugin is called + */ + static DBusHandlerResult receiveCallback(DBusConnection *conn, DBusMessage *msg, void *user_data); + + /** + * dynamic delegate that handles the Callback of the static receiveCallback + * @param conn DBus connection + * @param msg DBus message + * @param user_data pointer to instance of CommandReceiverShadow + * @return + */ + DBusHandlerResult receiveCallbackDelegate(DBusConnection *conn, DBusMessage *msg); + + /** + * sends out introspectiondata read from an xml file. + * @param conn + * @param msg + */ + void sendIntrospection(DBusConnection* conn, DBusMessage* msg); + + /** + * creates the function map needed to combine DBus messages and function adresses + * @return the map + */ + functionMap_t createMap(); +}; + +} + +#endif /* COMMANDRECEIVERSHADOW_H_ */ diff --git a/PluginCommandInterfaceDbus/include/mainpage.h b/PluginCommandInterfaceDbus/include/mainpage.h deleted file mode 100644 index 8a2848c..0000000 --- a/PluginCommandInterfaceDbus/include/mainpage.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * \mainpage - * \image html "Bild1.png" - * Copyright Copyright (C) 2011, BMW AG - * - * \date 22.06.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 . - * 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. - * - * \section About About PluginInterfaceDBus - * This plugin for the Genivi AudioManager serves as interface for DBus. - * - * \section Info More information - * can be found at - * - */ - -#ifndef MAINPAGE_H_ -#define MAINPAGE_H_ - -#endif /* MAINPAGE_H_ */ diff --git a/PluginCommandInterfaceDbus/src/CAmCommandSenderDbus.cpp b/PluginCommandInterfaceDbus/src/CAmCommandSenderDbus.cpp new file mode 100644 index 0000000..cb5b838 --- /dev/null +++ b/PluginCommandInterfaceDbus/src/CAmCommandSenderDbus.cpp @@ -0,0 +1,331 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmCommandSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmCommandSenderDbus.h" +#include +#include +#include +#include +#include +#include "CAmDbusMessageHandler.h" +#include "shared/CAmDltWrapper.h" +#include "shared/CAmDbusWrapper.h" + + +DLT_DECLARE_CONTEXT(commandDbus) + +using namespace am; + +/** + * factory for plugin loading + */ +extern "C" IAmCommandSend* PluginCommandInterfaceDbusFactory() +{ + return (new CAmCommandSenderDbus()); +} + +/** + * destroy instance of commandSendInterface + */ +extern "C" void destroyRoutingPluginInterfaceDbus(IAmCommandSend* commandSendInterface) +{ + delete commandSendInterface; +} + +CAmCommandSenderDbus::CAmCommandSenderDbus() : + mCAmDbusMessageHandler(), // + mIAmCommandReceiverShadow(), // + mpCAmDbusWrapper(NULL), // + mpIAmCommandReceive(NULL), // + mReady(false) +{ + CAmDltWrapper::instance()->registerContext(commandDbus, "DBP", "DBus Plugin"); + log(&commandDbus, DLT_LOG_INFO, "DbusCommandSender constructor called"); +} + +CAmCommandSenderDbus::~CAmCommandSenderDbus() +{ + log(&commandDbus, DLT_LOG_INFO, "DbusCommandSender destructed"); + CAmDltWrapper::instance()->unregisterContext(commandDbus); +} + +am_Error_e CAmCommandSenderDbus::startupInterface(IAmCommandReceive* commandreceiveinterface) +{ + log(&commandDbus, DLT_LOG_INFO, "startupInterface called"); + + mpIAmCommandReceive = commandreceiveinterface; + mIAmCommandReceiverShadow.setCommandReceiver(mpIAmCommandReceive); + mpIAmCommandReceive->getDBusConnectionWrapper(mpCAmDbusWrapper); + assert(mpCAmDbusWrapper!=NULL); + DBusConnection * connection; + mpCAmDbusWrapper->getDBusConnection(connection); + assert(connection!=NULL); + mCAmDbusMessageHandler.setDBusConnection(connection); + return (E_OK); +} + +void CAmCommandSenderDbus::setCommandReady(const uint16_t handle) +{ + //todo:implement handle handling + log(&commandDbus, DLT_LOG_INFO, "cbCommunicationReady called"); + mReady = true; + mpIAmCommandReceive->confirmCommandReady(handle); +} + +void CAmCommandSenderDbus::setCommandRundown(const uint16_t handle) +{ + log(&commandDbus, DLT_LOG_INFO, "cbCommunicationRundown called"); + mReady = false; + mpIAmCommandReceive->confirmCommandRundown(handle); + /** + * todo: implement DbusCommandSender::cbCommunicationRundown() + */ +} + +void CAmCommandSenderDbus::cbNewMainConnection(const am_MainConnectionType_s mainConnection) +{ + (void)mainConnection; + //todo: change xml and interface to differetiate between new connection and removed one + log(&commandDbus, DLT_LOG_INFO, "cbNumberOfMainConnectionsChanged called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfMainConnectionsChanged")); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) +{ + (void)mainConnection; +//todo: change xml and interface to differetiate between new connection and removed one + log(&commandDbus, DLT_LOG_INFO, "cbNumberOfMainConnectionsChanged called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfMainConnectionsChanged")); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbNewSink(const am_SinkType_s& sink) +{ + log(&commandDbus, DLT_LOG_INFO, "cbNewSink called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), "SinkAdded"); + mCAmDbusMessageHandler.append(sink); + + log(&commandDbus, DLT_LOG_INFO, "send signal SinkAdded"); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbRemovedSink(const am_sinkID_t sinkID) +{ + //todo: check if this really works! + log(&commandDbus, DLT_LOG_INFO, "cbRemovedSink called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), "SinkRemoved"); + mCAmDbusMessageHandler.append(sinkID); + + log(&commandDbus, DLT_LOG_INFO, "send signal SinkAdded"); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbNewSource(const am_SourceType_s& source) +{ + log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSourcesChanged called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), "SourceAdded"); + mCAmDbusMessageHandler.append(source); + + log(&commandDbus, DLT_LOG_INFO, "send signal SourceAdded"); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void am::CAmCommandSenderDbus::cbRemovedSource(const am_sourceID_t source) +{ + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), "SourceRemoved"); + mCAmDbusMessageHandler.append(source); + + log(&commandDbus, DLT_LOG_INFO, "send signal SourceRemoved"); + + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbNumberOfSinkClassesChanged() +{ + log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSinkClassesChanged called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSinkClassesChanged")); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbNumberOfSourceClassesChanged() +{ + log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSourceClassesChanged called"); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSourceClassesChanged")); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) +{ + log(&commandDbus, DLT_LOG_INFO, "cbMainConnectionStateChanged called, connectionID=", connectionID, "connectionState=", connectionState); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("MainConnectionStateChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) connectionID); + mCAmDbusMessageHandler.append((dbus_int16_t) connectionState); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) +{ + log(&commandDbus, DLT_LOG_INFO, "cbMainSinkSoundPropertyChanged called, sinkID", sinkID, "SoundProperty.type", soundProperty.type, "SoundProperty.value", soundProperty.value); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSinkSoundPropertyChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sinkID); + mCAmDbusMessageHandler.append(soundProperty); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) +{ + log(&commandDbus, DLT_LOG_INFO, "cbMainSourceSoundPropertyChanged called, sourceID", sourceID, "SoundProperty.type", SoundProperty.type, "SoundProperty.value", SoundProperty.value); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSourceSoundPropertyChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sourceID); + mCAmDbusMessageHandler.append(SoundProperty); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + log(&commandDbus, DLT_LOG_INFO, "cbSinkAvailabilityChanged called, sinkID", sinkID, "availability.availability", availability.availability, "SoundProperty.reason", availability.availabilityReason); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkAvailabilityChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sinkID); + mCAmDbusMessageHandler.append(availability); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + log(&commandDbus, DLT_LOG_INFO, "cbSourceAvailabilityChanged called, sourceID", sourceID, "availability.availability", availability.availability, "SoundProperty.reason", availability.availabilityReason); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("SourceAvailabilityChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sourceID); + mCAmDbusMessageHandler.append(availability); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ + log(&commandDbus, DLT_LOG_INFO, "cbVolumeChanged called, sinkID", sinkID, "volume", volume); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("VolumeChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sinkID); + mCAmDbusMessageHandler.append((dbus_int16_t) volume); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + log(&commandDbus, DLT_LOG_INFO, "cbSinkMuteStateChanged called, sinkID", sinkID, "muteState", muteState); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkMuteStateChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) sinkID); + mCAmDbusMessageHandler.append((dbus_int16_t) muteState); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty) +{ + log(&commandDbus, DLT_LOG_INFO, "cbSystemPropertyChanged called, SystemProperty.type", SystemProperty.type, "SystemProperty.value", SystemProperty.value); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("SystemPropertyChanged")); + mCAmDbusMessageHandler.append(SystemProperty); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void am::CAmCommandSenderDbus::cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) +{ + log(&commandDbus, DLT_LOG_INFO, "cbTimingInformationChanged called, mainConnectionID=", mainConnectionID, "time=", time); + + if (mReady) + { + mCAmDbusMessageHandler.initSignal(std::string(MY_NODE), std::string("TimingInformationChanged")); + mCAmDbusMessageHandler.append((dbus_uint16_t) mainConnectionID); + mCAmDbusMessageHandler.append((dbus_int16_t) time); + mCAmDbusMessageHandler.sendMessage(); + } +} + +void CAmCommandSenderDbus::getInterfaceVersion(std::string & version) const +{ + version = CommandSendVersion; +} + diff --git a/PluginCommandInterfaceDbus/src/CAmDbusMessageHandler.cpp b/PluginCommandInterfaceDbus/src/CAmDbusMessageHandler.cpp new file mode 100644 index 0000000..6b2dc3f --- /dev/null +++ b/PluginCommandInterfaceDbus/src/CAmDbusMessageHandler.cpp @@ -0,0 +1,631 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file DBusMessageHandler.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmDbusMessageHandler.h" +#include "config.h" +#include +#include +#include +#include "CAmCommandSenderDbus.h" +#include "shared/CAmDltWrapper.h" + +DLT_IMPORT_CONTEXT(commandDbus) + +namespace am +{ + +CAmDbusMessageHandler::CAmDbusMessageHandler() : + mDBusMessageIter(), // + mDBusError(), // + mSerial(0), // + mErrorName(""), // + mErrorMsg(""), // + mpDBusMessage(NULL), // + mpReveiveMessage(NULL), // + mpDBusConnection(NULL) +{ + log(&commandDbus, DLT_LOG_INFO, "DBusMessageHandler constructed"); +} + +CAmDbusMessageHandler::~CAmDbusMessageHandler() +{ + log(&commandDbus, DLT_LOG_INFO, "DBUSMessageHandler destructed"); +} + +void CAmDbusMessageHandler::initReceive(DBusMessage* msg) +{ + assert(msg!=NULL); + mpReveiveMessage = msg; + if (!dbus_message_iter_init(msg, &mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_INFO, "DBusMessageHandler::initReceive DBus Message has no arguments!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBUS Message has no arguments!"; + } +} + +void CAmDbusMessageHandler::initReply(DBusMessage* msg) +{ + assert(msg!=NULL); + mpDBusMessage = dbus_message_new_method_return(msg); + if (mpDBusMessage == NULL) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::initReply Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } + dbus_message_iter_init_append(mpDBusMessage, &mDBusMessageIter); +} + +void CAmDbusMessageHandler::initSignal(std::string path, std::string signalName) +{ + assert(!path.empty()); + assert(!signalName.empty()); + std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path; + mpDBusMessage = dbus_message_new_signal(completePath.c_str(), DBUS_SERVICE_PREFIX, signalName.c_str()); + + if (mpDBusMessage == NULL) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::initSignal Cannot allocate DBus message!"); + } + dbus_message_iter_init_append(mpDBusMessage, &mDBusMessageIter); +} + +void CAmDbusMessageHandler::sendMessage() +{ + assert(mpDBusConnection!=NULL); + if (mpReveiveMessage != 0) + { + mSerial = dbus_message_get_serial(mpReveiveMessage); + } + else + { + mSerial = 1; + } + if (!mErrorName.empty()) + { + mpDBusMessage = dbus_message_new_error(mpReveiveMessage, mErrorName.c_str(), mErrorMsg.c_str()); + } + if (!dbus_connection_send(mpDBusConnection, mpDBusMessage, &mSerial)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::sendMessage cannot send message!"); + } + dbus_connection_flush(mpDBusConnection); + dbus_message_unref(mpDBusMessage); + mpDBusMessage = NULL; +} + +char* CAmDbusMessageHandler::getString() +{ + char* param = NULL; + + if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getString DBUS handler argument is no String!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no string"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); + dbus_message_iter_next(&mDBusMessageIter); + } + return (param); +} + +dbus_bool_t CAmDbusMessageHandler::getBool() +{ + dbus_bool_t boolparam = false; + + if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getBool DBUS handler argument is no bool!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no bool"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, &boolparam); + dbus_message_iter_next(&mDBusMessageIter); + } + return (boolparam); +} + +char CAmDbusMessageHandler::getByte() +{ + char param; + + if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getByte DBUS handler argument is no byte!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no byte"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); + dbus_message_iter_next(&mDBusMessageIter); + } + return (param); +} + +dbus_uint16_t CAmDbusMessageHandler::getUInt() +{ + dbus_uint16_t param; + +#ifdef GLIB_DBUS_TYPES_TOLERANT + if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) +#else + if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) +#endif + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getUInt DBUS handler argument is no uint16_t!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no uint16_t"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); + dbus_message_iter_next(&mDBusMessageIter); + } + return (param); +} + +dbus_int16_t CAmDbusMessageHandler::getInt() +{ + dbus_int16_t param; + +#ifdef GLIB_DBUS_TYPES_TOLERANT + if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) +#else + if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) +#endif + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getInt DBUS handler argument is no int16_t!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no int16_t"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); + dbus_message_iter_next(&mDBusMessageIter); + } + return (param); +} + +double CAmDbusMessageHandler::getDouble() +{ + double param; + if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no double"; + } + else + { + dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); + dbus_message_iter_next(&mDBusMessageIter); + } + return (param); +} + +void CAmDbusMessageHandler::getProperty(dbus_int16_t & type, dbus_int16_t & value) +{ + DBusMessageIter arrayIter; + if (DBUS_TYPE_STRUCT != dbus_message_iter_get_arg_type(&mDBusMessageIter)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getProperty DBUS handler argument is no array!"); + mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); + mErrorMsg = "DBus argument is no array"; + } + else + { + dbus_message_iter_recurse(&mDBusMessageIter, &arrayIter); + dbus_message_iter_get_basic(&arrayIter, &type); + dbus_message_iter_next(&arrayIter); + dbus_message_iter_get_basic(&arrayIter, &value); + dbus_message_iter_next(&mDBusMessageIter); + } +} + +void CAmDbusMessageHandler::append(bool toAppend) +{ + dbus_bool_t mybool = toAppend; + if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BOOLEAN, &mybool)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(double toAppend) +{ + if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_DOUBLE, &toAppend)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(char toAppend) +{ + if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BYTE, &toAppend)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(dbus_int16_t toAppend) +{ + if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_INT16, &toAppend)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(dbus_uint16_t toAppend) +{ + if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_UINT16, &toAppend)) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::setDBusConnection(DBusConnection *& connection) +{ + assert(connection!=NULL); + mpDBusConnection = connection; +} + +void CAmDbusMessageHandler::append(const am::am_SinkType_s& sinkType) +{ + DBusMessageIter structIter; + DBusMessageIter structAvailIter; + dbus_bool_t success = true; + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sinkType.name); + + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availability); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availabilityReason); + success = success && dbus_message_iter_close_container(&structIter, &structAvailIter); + + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.volume); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.muteState); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkClassID); + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const am::am_SourceType_s & sourceType) +{ + DBusMessageIter structIter; + DBusMessageIter structAvailIter; + dbus_bool_t success = true; + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sourceType.name); + + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availability); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availabilityReason); + success = success && dbus_message_iter_close_container(&structIter, &structAvailIter); + + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceClassID); + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const am::am_MainSoundProperty_s mainSoundProperty) +{ + DBusMessageIter structIter; + dbus_bool_t success = true; + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.type); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.value); + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const am::am_Availability_s & availability) +{ + DBusMessageIter structAvailIter; + dbus_bool_t success = true; + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availability); + success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availabilityReason); + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structAvailIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const am::am_SystemProperty_s & SystemProperty) +{ + DBusMessageIter structIter; + dbus_bool_t success = true; + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.type); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.value); + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector& listMainConnections) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + std::vector::const_iterator listIterator = listMainConnections.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qqqnn)", &arrayIter); + for (; listIterator < listMainConnections.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->mainConnectionID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->delay); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->connectionState); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listMainSinks) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + DBusMessageIter availIter; + std::vector::const_iterator listIterator = listMainSinks.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)nnq)", &arrayIter); + for (; listIterator < listMainSinks.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter); + success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability); + success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason); + success = success && dbus_message_iter_close_container(&structIter, &availIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->volume); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->muteState); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listMainSources) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + DBusMessageIter availIter; + std::vector::const_iterator listIterator = listMainSources.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)q)", &arrayIter); + for (; listIterator < listMainSources.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter); + success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability); + success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason); + success = success && dbus_message_iter_close_container(&structIter, &availIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listMainSoundProperties) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + std::vector::const_iterator listIterator = listMainSoundProperties.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter); + for (; listIterator < listMainSoundProperties.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listSourceClasses) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + DBusMessageIter propIter; + DBusMessageIter innerIter; + std::vector::const_iterator listIterator = listSourceClasses.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter); + for (; listIterator < listSourceClasses.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter); + + std::vector::const_iterator listInnerIterator = listIterator->listClassProperties.begin(); + for (; listInnerIterator < listIterator->listClassProperties.end(); ++listInnerIterator) + { + success = success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter); + success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty); + success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value); + success = success && dbus_message_iter_close_container(&innerIter, &propIter); + } + success = success && dbus_message_iter_close_container(&structIter, &innerIter); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listSinkClasses) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + DBusMessageIter propIter; + DBusMessageIter innerIter; + std::vector::const_iterator listIterator = listSinkClasses.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter); + for (; listIterator < listSinkClasses.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); + success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter); + + std::vector::const_iterator listInnerIterator = listIterator->listClassProperties.begin(); + for (; listInnerIterator < listIterator->listClassProperties.end(); ++listInnerIterator) + { + success = success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter); + success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty); + success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value); + success = success && dbus_message_iter_close_container(&innerIter, &propIter); + } + success = success && dbus_message_iter_close_container(&structIter, &innerIter); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} + +void CAmDbusMessageHandler::append(const std::vector & listSystemProperties) +{ + DBusMessageIter arrayIter; + DBusMessageIter structIter; + std::vector::const_iterator listIterator = listSystemProperties.begin(); + dbus_bool_t success = true; + + success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter); + for (; listIterator < listSystemProperties.end(); ++listIterator) + { + success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type); + success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value); + success = success && dbus_message_iter_close_container(&arrayIter, &structIter); + } + success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); + + if (!success) + { + log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); + mErrorName = std::string(DBUS_ERROR_NO_MEMORY); + mErrorMsg = "Cannot create reply!"; + } +} +} diff --git a/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp b/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp deleted file mode 100644 index 313818f..0000000 --- a/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file CommandReceiverShadow.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include -#include -#include -#include -#include "CommandReceiverShadow.h" -#include "DBusCommandSender.h" -#include "DLTWrapper.h" - -using namespace am; - -DLT_IMPORT_CONTEXT(commandDbus) - -/** - * static ObjectPathTable is needed for DBus Callback handling - */ -static DBusObjectPathVTable gObjectPathVTable; - -CommandReceiverShadow::CommandReceiverShadow() : - mCommandReceiveInterface(NULL), // - mDBusWrapper(NULL), // - mFunctionMap(createMap()), // - mDBUSMessageHandler() -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow constructed"); -} - -CommandReceiverShadow::~CommandReceiverShadow() -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow destructed"); -} - -void CommandReceiverShadow::connect(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::connect called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sourceID_t sourceID = (am_sourceID_t) mDBUSMessageHandler.getUInt(); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - am_mainConnectionID_t mainConnectionID = 0; - am_Error_e returnCode = mCommandReceiveInterface->connect(sourceID, sinkID, mainConnectionID); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append((dbus_uint16_t) mainConnectionID); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::disconnect(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::disconnect called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_mainConnectionID_t mainConnnectionID = (am_mainConnectionID_t) mDBUSMessageHandler.getUInt(); - am_Error_e returnCode = mCommandReceiveInterface->disconnect(mainConnnectionID); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::setVolume(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::setVolume called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - am_volume_t volume = (am_volume_t) mDBUSMessageHandler.getInt(); - am_Error_e returnCode = mCommandReceiveInterface->setVolume(sinkID, volume); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::volumeStep(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::volumeStep called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - int16_t volumeStep = (int16_t) mDBUSMessageHandler.getInt(); - am_Error_e returnCode = mCommandReceiveInterface->volumeStep(sinkID, volumeStep); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::setSinkMuteState(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::setSinkMuteState called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - am_MuteState_e muteState = (am_MuteState_e) mDBUSMessageHandler.getInt(); - am_Error_e returnCode = mCommandReceiveInterface->setSinkMuteState(sinkID, muteState); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::setMainSinkSoundProperty(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::setMainSinkSoundProperty called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - dbus_int16_t type = 0; - dbus_int16_t value = 0; - mDBUSMessageHandler.getProperty(type, value); - am_MainSoundProperty_s mainSoundProperty; - mainSoundProperty.type = (am_MainSoundPropertyType_e) type; - mainSoundProperty.value = (int32_t) value; - am_Error_e returnCode = mCommandReceiveInterface->setMainSinkSoundProperty(mainSoundProperty, sinkID); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::setMainSourceSoundProperty(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::setMainSourceSoundProperty called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sourceID_t sourceID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - dbus_int16_t type = 0; - dbus_int16_t value = 0; - mDBUSMessageHandler.getProperty(type, value); - am_MainSoundProperty_s mainSoundProperty; - mainSoundProperty.type = (am_MainSoundPropertyType_e) type; - mainSoundProperty.value = (int32_t) value; - am_Error_e returnCode = mCommandReceiveInterface->setMainSourceSoundProperty(mainSoundProperty, sourceID); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::setSystemProperty(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::setSystemProperty called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - dbus_int16_t type = 0; - dbus_int16_t value = 0; - mDBUSMessageHandler.getProperty(type, value); - am_SystemProperty_s systemProperty; - systemProperty.type = (am_SystemPropertyType_e) type; - systemProperty.value = (int32_t) value; - am_Error_e returnCode = mCommandReceiveInterface->setSystemProperty(systemProperty); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListMainConnections(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListMainConnections called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listMainConnections; - am_Error_e returnCode = mCommandReceiveInterface->getListMainConnections(listMainConnections); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listMainConnections); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListMainSinks(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListMainSinks called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listSinks; - am_Error_e returnCode = mCommandReceiveInterface->getListMainSinks(listSinks); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSinks); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListMainSources(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListMainSources called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listSources; - am_Error_e returnCode = mCommandReceiveInterface->getListMainSources(listSources); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSources); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListMainSinkSoundProperties(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListMainSinkSoundProperties called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); - std::vector listSinkSoundProperties; - am_Error_e returnCode = mCommandReceiveInterface->getListMainSinkSoundProperties(sinkID, listSinkSoundProperties); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSinkSoundProperties); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListMainSourceSoundProperties(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListMainSourceSoundProperties called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_sourceID_t sourceID = (am_sourceID_t) mDBUSMessageHandler.getUInt(); - std::vector listSinkSoundProperties; - am_Error_e returnCode = mCommandReceiveInterface->getListMainSourceSoundProperties(sourceID, listSinkSoundProperties); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSinkSoundProperties); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListSourceClasses(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListSourceClasses called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listSourceClasses; - am_Error_e returnCode = mCommandReceiveInterface->getListSourceClasses(listSourceClasses); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSourceClasses); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListSinkClasses(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListSinkClasses called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listSinkClasses; - am_Error_e returnCode = mCommandReceiveInterface->getListSinkClasses(listSinkClasses); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSinkClasses); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getListSystemProperties(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getListSystemProperties called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - std::vector listSystemProperties; - am_Error_e returnCode = mCommandReceiveInterface->getListSystemProperties(listSystemProperties); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append(listSystemProperties); - mDBUSMessageHandler.sendMessage(); -} - -void CommandReceiverShadow::getTimingInformation(DBusConnection *conn, DBusMessage *msg) -{ - log(&commandDbus,DLT_LOG_INFO,"CommandReceiverShadow::getTimingInformation called"); - - (void) conn; - assert(mCommandReceiveInterface!=NULL); - - mDBUSMessageHandler.initReceive(msg); - am_mainConnectionID_t mainConnectionID = (am_mainConnectionID_t) mDBUSMessageHandler.getUInt(); - am_timeSync_t delay = 0; - am_Error_e returnCode = mCommandReceiveInterface->getTimingInformation(mainConnectionID, delay); - mDBUSMessageHandler.initReply(msg); - mDBUSMessageHandler.append((dbus_int16_t) returnCode); - mDBUSMessageHandler.append((dbus_int16_t) delay); - mDBUSMessageHandler.sendMessage(); -} - -DBusHandlerResult CommandReceiverShadow::receiveCallback(DBusConnection *conn, DBusMessage *msg, void *user_data) -{ - assert(conn!=NULL); - assert(msg!=NULL); - assert(user_data!=NULL); - CommandReceiverShadow* reference = (CommandReceiverShadow*) user_data; - return (reference->receiveCallbackDelegate(conn, msg)); -} - -void CommandReceiverShadow::sendIntrospection(DBusConnection *conn, DBusMessage *msg) -{ - assert(conn!=NULL); - assert(msg!=NULL); - DBusMessage* reply; - DBusMessageIter args; - dbus_uint32_t serial = 0; - - // create a reply from the message - reply = dbus_message_new_method_return(msg); - std::ifstream in(INTROSPECTION_COMMAND_XML_FILE); - assert(in!=NULL); - std::string introspect((std::istreambuf_iterator(in)), std::istreambuf_iterator()); - 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(DLT_CONTEXT,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(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!")); - } - dbus_connection_flush(conn); - - // free the reply - dbus_message_unref(reply); -} - -DBusHandlerResult CommandReceiverShadow::receiveCallbackDelegate(DBusConnection *conn, DBusMessage *msg) -{ - //DLT_LOG(dMain, DLT_LOG_INFO, DLT_STRING("message received")); - - if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - { - sendIntrospection(conn, msg); - return (DBUS_HANDLER_RESULT_HANDLED); - } - - functionMap_t::iterator iter = mFunctionMap.begin(); - std::string k(dbus_message_get_member(msg)); - iter = mFunctionMap.find(k); - if (iter != mFunctionMap.end()) - { - std::string p(iter->first); - CallBackMethod cb = iter->second; - (this->*cb)(conn, msg); - return (DBUS_HANDLER_RESULT_HANDLED); - } - - return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - -void CommandReceiverShadow::setCommandReceiver(CommandReceiveInterface*& receiver) -{ - assert(receiver!=NULL); - mCommandReceiveInterface = receiver; - - gObjectPathVTable.message_function = CommandReceiverShadow::receiveCallback; - - DBusConnection* connection; - mCommandReceiveInterface->getDBusConnectionWrapper(mDBusWrapper); - assert(mDBusWrapper!=NULL); - - mDBusWrapper->getDBusConnection(connection); - assert(connection!=NULL); - mDBUSMessageHandler.setDBusConnection(connection); - - std::string path(MY_NODE); - mDBusWrapper->registerCallback(&gObjectPathVTable, path, this); -} - -CommandReceiverShadow::functionMap_t CommandReceiverShadow::createMap() -{ - functionMap_t m; - m["Connect"] = &CommandReceiverShadow::connect; - m["Disconnect"] = &CommandReceiverShadow::disconnect; - m["SetVolume"] = &CommandReceiverShadow::setVolume; - m["VolumeStep"] = &CommandReceiverShadow::volumeStep; - m["SetSinkMuteState"] = &CommandReceiverShadow::setSinkMuteState; - m["SetMainSinkSoundProperty"] = &CommandReceiverShadow::setMainSinkSoundProperty; - m["SetMainSourceSoundProperty"] = &CommandReceiverShadow::setMainSourceSoundProperty; - m["GetListMainConnections"] = &CommandReceiverShadow::getListMainConnections; - m["GetListMainSinks"] = &CommandReceiverShadow::getListMainSinks; - m["GetListMainSources"] = &CommandReceiverShadow::getListMainSources; - m["GetListMainSinkSoundProperties"] = &CommandReceiverShadow::getListMainSinkSoundProperties; - m["GetListMainSourceSoundProperties"] = &CommandReceiverShadow::getListMainSourceSoundProperties; - m["GetListSourceClasses"] = &CommandReceiverShadow::getListSourceClasses; - m["GetListSinkClasses"] = &CommandReceiverShadow::getListSinkClasses; - m["GetListSystemProperties"] = &CommandReceiverShadow::getListSystemProperties; - m["GetTimingInformation"] = &CommandReceiverShadow::getTimingInformation; - m["SetSystemProperty"] = &CommandReceiverShadow::setSystemProperty; - return (m); -} - diff --git a/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp b/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp deleted file mode 100644 index de577c9..0000000 --- a/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file CommandSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include -#include -#include "DBusCommandSender.h" -#include "DBusMessageHandler.h" -#include "DLTWrapper.h" -#include -#include -#include -#include -#include - -DLT_DECLARE_CONTEXT(commandDbus) - -using namespace am; - -/** - * factory for plugin loading - */ -extern "C" CommandSendInterface* PluginCommandInterfaceDbusFactory() -{ - return (new DbusCommandSender()); -} - -/** - * destroy instance of commandSendInterface - */ -extern "C" void destroyRoutingPluginInterfaceDbus(CommandSendInterface* commandSendInterface) -{ - delete commandSendInterface; -} - -DbusCommandSender::DbusCommandSender() : - mDBUSMessageHandler(), // - mCommandReceiverShadow(), // - mDBusWrapper(NULL), // - mCommandReceiveInterface(NULL), // - mReady(false) -{ - DLTWrapper::instance()->registerContext(commandDbus, "DBP", "DBus Plugin"); - log(&commandDbus, DLT_LOG_INFO, "DbusCommandSender constructor called"); -} - -DbusCommandSender::~DbusCommandSender() -{ - log(&commandDbus, DLT_LOG_INFO, "DbusCommandSender destructed"); - DLTWrapper::instance()->unregisterContext(commandDbus); -} - -am_Error_e DbusCommandSender::startupInterface(CommandReceiveInterface* commandreceiveinterface) -{ - log(&commandDbus, DLT_LOG_INFO, "startupInterface called"); - - mCommandReceiveInterface = commandreceiveinterface; - mCommandReceiverShadow.setCommandReceiver(mCommandReceiveInterface); - mCommandReceiveInterface->getDBusConnectionWrapper(mDBusWrapper); - assert(mDBusWrapper!=NULL); - DBusConnection * connection; - mDBusWrapper->getDBusConnection(connection); - assert(connection!=NULL); - mDBUSMessageHandler.setDBusConnection(connection); - return (E_OK); -} - -void DbusCommandSender::setCommandReady(const uint16_t handle) -{ - //todo:implement handle handling - log(&commandDbus, DLT_LOG_INFO, "cbCommunicationReady called"); - mReady = true; -} - -void DbusCommandSender::setCommandRundown(const uint16_t handle) -{ - log(&commandDbus, DLT_LOG_INFO, "cbCommunicationRundown called"); - mReady = false; - /** - * todo: implement DbusCommandSender::cbCommunicationRundown() - */ -} - -void DbusCommandSender::cbNewMainConnection(const am_MainConnectionType_s mainConnection) -{ - (void)mainConnection; - //todo: change xml and interface to differetiate between new connection and removed one - log(&commandDbus, DLT_LOG_INFO, "cbNumberOfMainConnectionsChanged called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfMainConnectionsChanged")); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) -{ -//todo: change xml and interface to differetiate between new connection and removed one - log(&commandDbus, DLT_LOG_INFO, "cbNumberOfMainConnectionsChanged called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfMainConnectionsChanged")); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbNewSink(const am_SinkType_s& sink) -{ - log(&commandDbus, DLT_LOG_INFO, "cbNewSink called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SinkAdded"); - mDBUSMessageHandler.append(sink); - - log(&commandDbus, DLT_LOG_INFO, "send signal SinkAdded"); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbRemovedSink(const am_sinkID_t sinkID) -{ - //todo: check if this really works! - log(&commandDbus, DLT_LOG_INFO, "cbRemovedSink called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SinkRemoved"); - mDBUSMessageHandler.append(sinkID); - - log(&commandDbus, DLT_LOG_INFO, "send signal SinkAdded"); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbNewSource(const am_SourceType_s& source) -{ - log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSourcesChanged called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SourceAdded"); - mDBUSMessageHandler.append(source); - - log(&commandDbus, DLT_LOG_INFO, "send signal SourceAdded"); - mDBUSMessageHandler.sendMessage(); - } -} - -void am::DbusCommandSender::cbRemovedSource(const am_sourceID_t source) -{ - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SourceRemoved"); - mDBUSMessageHandler.append(source); - - log(&commandDbus, DLT_LOG_INFO, "send signal SourceRemoved"); - - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbNumberOfSinkClassesChanged() -{ - log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSinkClassesChanged called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSinkClassesChanged")); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbNumberOfSourceClassesChanged() -{ - log(&commandDbus, DLT_LOG_INFO, "cbNumberOfSourceClassesChanged called"); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSourceClassesChanged")); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ - log(&commandDbus, DLT_LOG_INFO, "cbMainConnectionStateChanged called, connectionID=", connectionID, "connectionState=", connectionState); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainConnectionStateChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) connectionID); - mDBUSMessageHandler.append((dbus_int16_t) connectionState); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) -{ - log(&commandDbus, DLT_LOG_INFO, "cbMainSinkSoundPropertyChanged called, sinkID", sinkID, "SoundProperty.type", soundProperty.type, "SoundProperty.value", soundProperty.value); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSinkSoundPropertyChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sinkID); - mDBUSMessageHandler.append(soundProperty); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) -{ - log(&commandDbus, DLT_LOG_INFO, "cbMainSourceSoundPropertyChanged called, sourceID", sourceID, "SoundProperty.type", SoundProperty.type, "SoundProperty.value", SoundProperty.value); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSourceSoundPropertyChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sourceID); - mDBUSMessageHandler.append(SoundProperty); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - log(&commandDbus, DLT_LOG_INFO, "cbSinkAvailabilityChanged called, sinkID", sinkID, "availability.availability", availability.availability, "SoundProperty.reason", availability.availabilityReason); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkAvailabilityChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sinkID); - mDBUSMessageHandler.append(availability); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - log(&commandDbus, DLT_LOG_INFO, "cbSourceAvailabilityChanged called, sourceID", sourceID, "availability.availability", availability.availability, "SoundProperty.reason", availability.availabilityReason); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SourceAvailabilityChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sourceID); - mDBUSMessageHandler.append(availability); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ - log(&commandDbus, DLT_LOG_INFO, "cbVolumeChanged called, sinkID", sinkID, "volume", volume); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("VolumeChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sinkID); - mDBUSMessageHandler.append((dbus_int16_t) volume); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - log(&commandDbus, DLT_LOG_INFO, "cbSinkMuteStateChanged called, sinkID", sinkID, "muteState", muteState); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkMuteStateChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) sinkID); - mDBUSMessageHandler.append((dbus_int16_t) muteState); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty) -{ - log(&commandDbus, DLT_LOG_INFO, "cbSystemPropertyChanged called, SystemProperty.type", SystemProperty.type, "SystemProperty.value", SystemProperty.value); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SystemPropertyChanged")); - mDBUSMessageHandler.append(SystemProperty); - mDBUSMessageHandler.sendMessage(); - } -} - -void am::DbusCommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) -{ - log(&commandDbus, DLT_LOG_INFO, "cbTimingInformationChanged called, mainConnectionID=", mainConnectionID, "time=", time); - - if (mReady) - { - mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("TimingInformationChanged")); - mDBUSMessageHandler.append((dbus_uint16_t) mainConnectionID); - mDBUSMessageHandler.append((dbus_int16_t) time); - mDBUSMessageHandler.sendMessage(); - } -} - -void DbusCommandSender::getInterfaceVersion(std::string & version) const -{ - version = CommandSendVersion; -} - diff --git a/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp b/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp deleted file mode 100644 index 3dd9172..0000000 --- a/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file DBusMessageHandler.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#include -#include "DBusMessageHandler.h" -#include "DBusCommandSender.h" -#include "DLTWrapper.h" -#include -#include -#include - -DLT_IMPORT_CONTEXT(commandDbus) - -using namespace am; - -DBusMessageHandler::DBusMessageHandler() : - mDBusMessageIter(), // - mDBusError(), // - mSerial(0), // - mErrorName(""), // - mErrorMsg(""), // - mDbusMessage(NULL), // - mReveiveMessage(NULL), // - mDBusConnection(NULL) -{ - log(&commandDbus, DLT_LOG_INFO, "DBusMessageHandler constructed"); -} - -DBusMessageHandler::~DBusMessageHandler() -{ - log(&commandDbus, DLT_LOG_INFO, "DBUSMessageHandler destructed"); -} - -void DBusMessageHandler::initReceive(DBusMessage* msg) -{ - assert(msg!=NULL); - mReveiveMessage = msg; - if (!dbus_message_iter_init(msg, &mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_INFO, "DBusMessageHandler::initReceive DBus Message has no arguments!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBUS Message has no arguments!"; - } -} - -void DBusMessageHandler::initReply(DBusMessage* msg) -{ - assert(msg!=NULL); - mDbusMessage = dbus_message_new_method_return(msg); - if (mDbusMessage == NULL) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::initReply Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } - dbus_message_iter_init_append(mDbusMessage, &mDBusMessageIter); -} - -void DBusMessageHandler::initSignal(std::string path, std::string signalName) -{ - assert(!path.empty()); - assert(!signalName.empty()); - std::string completePath = std::string(DBUS_SERVICE_OBJECT_PATH) + "/" + path; - mDbusMessage = dbus_message_new_signal(completePath.c_str(), DBUS_SERVICE_PREFIX, signalName.c_str()); - - if (mDbusMessage == NULL) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::initSignal Cannot allocate DBus message!"); - } - dbus_message_iter_init_append(mDbusMessage, &mDBusMessageIter); -} - -void DBusMessageHandler::sendMessage() -{ - assert(mDBusConnection!=NULL); - if (mReveiveMessage != 0) - { - mSerial = dbus_message_get_serial(mReveiveMessage); - } - else - { - mSerial = 1; - } - if (!mErrorName.empty()) - { - mDbusMessage = dbus_message_new_error(mReveiveMessage, mErrorName.c_str(), mErrorMsg.c_str()); - } - if (!dbus_connection_send(mDBusConnection, mDbusMessage, &mSerial)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::sendMessage cannot send message!"); - } - dbus_connection_flush(mDBusConnection); - dbus_message_unref(mDbusMessage); - mDbusMessage = NULL; -} - -char* DBusMessageHandler::getString() -{ - char* param = NULL; - - if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getString DBUS handler argument is no String!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no string"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); - dbus_message_iter_next(&mDBusMessageIter); - } - return (param); -} - -dbus_bool_t DBusMessageHandler::getBool() -{ - dbus_bool_t boolparam = false; - - if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getBool DBUS handler argument is no bool!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no bool"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, &boolparam); - dbus_message_iter_next(&mDBusMessageIter); - } - return (boolparam); -} - -char DBusMessageHandler::getByte() -{ - char param; - - if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getByte DBUS handler argument is no byte!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no byte"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); - dbus_message_iter_next(&mDBusMessageIter); - } - return (param); -} - -dbus_uint16_t DBusMessageHandler::getUInt() -{ - dbus_uint16_t param; - -#ifdef GLIB_DBUS_TYPES_TOLERANT - if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) -#else - if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) -#endif - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getUInt DBUS handler argument is no uint16_t!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no uint16_t"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); - dbus_message_iter_next(&mDBusMessageIter); - } - return (param); -} - -dbus_int16_t DBusMessageHandler::getInt() -{ - dbus_int16_t param; - -#ifdef GLIB_DBUS_TYPES_TOLERANT - if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter) && DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) -#else - if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter)) -#endif - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getInt DBUS handler argument is no int16_t!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no int16_t"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); - dbus_message_iter_next(&mDBusMessageIter); - } - return (param); -} - -double DBusMessageHandler::getDouble() -{ - double param; - if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getDouble DBUS handler argument is no double!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no double"; - } - else - { - dbus_message_iter_get_basic(&mDBusMessageIter, ¶m); - dbus_message_iter_next(&mDBusMessageIter); - } - return (param); -} - -void DBusMessageHandler::getProperty(dbus_int16_t & type, dbus_int16_t & value) -{ - DBusMessageIter arrayIter; - if (DBUS_TYPE_STRUCT != dbus_message_iter_get_arg_type(&mDBusMessageIter)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::getProperty DBUS handler argument is no array!"); - mErrorName = std::string(DBUS_ERROR_INVALID_ARGS); - mErrorMsg = "DBus argument is no array"; - } - else - { - dbus_message_iter_recurse(&mDBusMessageIter, &arrayIter); - dbus_message_iter_get_basic(&arrayIter, &type); - dbus_message_iter_next(&arrayIter); - dbus_message_iter_get_basic(&arrayIter, &value); - dbus_message_iter_next(&mDBusMessageIter); - } -} - -void DBusMessageHandler::append(bool toAppend) -{ - dbus_bool_t mybool = toAppend; - if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BOOLEAN, &mybool)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(double toAppend) -{ - if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_DOUBLE, &toAppend)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(char toAppend) -{ - if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BYTE, &toAppend)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(dbus_int16_t toAppend) -{ - if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_INT16, &toAppend)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(dbus_uint16_t toAppend) -{ - if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_UINT16, &toAppend)) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::setDBusConnection(DBusConnection *& connection) -{ - assert(connection!=NULL); - mDBusConnection = connection; -} - -void DBusMessageHandler::append(const am::am_SinkType_s& sinkType) -{ - DBusMessageIter structIter; - DBusMessageIter structAvailIter; - dbus_bool_t success = true; - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sinkType.name); - - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availability); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availabilityReason); - success = success && dbus_message_iter_close_container(&structIter, &structAvailIter); - - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.volume); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.muteState); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkClassID); - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const am::am_SourceType_s & sourceType) -{ - DBusMessageIter structIter; - DBusMessageIter structAvailIter; - dbus_bool_t success = true; - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sourceType.name); - - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availability); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availabilityReason); - success = success && dbus_message_iter_close_container(&structIter, &structAvailIter); - - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceClassID); - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const am::am_MainSoundProperty_s mainSoundProperty) -{ - DBusMessageIter structIter; - dbus_bool_t success = true; - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.type); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.value); - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const am::am_Availability_s & availability) -{ - DBusMessageIter structAvailIter; - dbus_bool_t success = true; - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availability); - success = success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availabilityReason); - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structAvailIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const am::am_SystemProperty_s & SystemProperty) -{ - DBusMessageIter structIter; - dbus_bool_t success = true; - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.type); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.value); - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector& listMainConnections) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - std::vector::const_iterator listIterator = listMainConnections.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qqqnn)", &arrayIter); - for (; listIterator < listMainConnections.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->mainConnectionID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->delay); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->connectionState); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listMainSinks) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - DBusMessageIter availIter; - std::vector::const_iterator listIterator = listMainSinks.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)nnq)", &arrayIter); - for (; listIterator < listMainSinks.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter); - success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability); - success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason); - success = success && dbus_message_iter_close_container(&structIter, &availIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->volume); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->muteState); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listMainSources) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - DBusMessageIter availIter; - std::vector::const_iterator listIterator = listMainSources.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)q)", &arrayIter); - for (; listIterator < listMainSources.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter); - success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability); - success = success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason); - success = success && dbus_message_iter_close_container(&structIter, &availIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listMainSoundProperties) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - std::vector::const_iterator listIterator = listMainSoundProperties.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter); - for (; listIterator < listMainSoundProperties.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listSourceClasses) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - DBusMessageIter propIter; - DBusMessageIter innerIter; - std::vector::const_iterator listIterator = listSourceClasses.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter); - for (; listIterator < listSourceClasses.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter); - - std::vector::const_iterator listInnerIterator = listIterator->listClassProperties.begin(); - for (; listInnerIterator < listIterator->listClassProperties.end(); ++listInnerIterator) - { - success = success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter); - success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty); - success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value); - success = success && dbus_message_iter_close_container(&innerIter, &propIter); - } - success = success && dbus_message_iter_close_container(&structIter, &innerIter); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listSinkClasses) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - DBusMessageIter propIter; - DBusMessageIter innerIter; - std::vector::const_iterator listIterator = listSinkClasses.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter); - for (; listIterator < listSinkClasses.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name); - success = success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter); - - std::vector::const_iterator listInnerIterator = listIterator->listClassProperties.begin(); - for (; listInnerIterator < listIterator->listClassProperties.end(); ++listInnerIterator) - { - success = success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter); - success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty); - success = success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value); - success = success && dbus_message_iter_close_container(&innerIter, &propIter); - } - success = success && dbus_message_iter_close_container(&structIter, &innerIter); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - -void DBusMessageHandler::append(const std::vector & listSystemProperties) -{ - DBusMessageIter arrayIter; - DBusMessageIter structIter; - std::vector::const_iterator listIterator = listSystemProperties.begin(); - dbus_bool_t success = true; - - success = success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter); - for (; listIterator < listSystemProperties.end(); ++listIterator) - { - success = success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type); - success = success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value); - success = success && dbus_message_iter_close_container(&arrayIter, &structIter); - } - success = success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter); - - if (!success) - { - log(&commandDbus, DLT_LOG_ERROR, "DBusMessageHandler::append Cannot allocate DBus message!"); - mErrorName = std::string(DBUS_ERROR_NO_MEMORY); - mErrorMsg = "Cannot create reply!"; - } -} - diff --git a/PluginCommandInterfaceDbus/src/IAmCommandReceiverShadow.cpp b/PluginCommandInterfaceDbus/src/IAmCommandReceiverShadow.cpp new file mode 100644 index 0000000..f43c9e6 --- /dev/null +++ b/PluginCommandInterfaceDbus/src/IAmCommandReceiverShadow.cpp @@ -0,0 +1,447 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CommandReceiverShadow.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "IAmCommandReceiverShadow.h" +#include +#include +#include +#include +#include "audiomanagertypes.h" +#include "CAmCommandSenderDbus.h" +#include "shared/CAmDltWrapper.h" + +using namespace am; + +DLT_IMPORT_CONTEXT(commandDbus) + +/** + * static ObjectPathTable is needed for DBus Callback handling + */ +static DBusObjectPathVTable gObjectPathVTable; + +IAmCommandReceiverShadow::IAmCommandReceiverShadow() : + mFunctionMap(createMap()), // + mDBUSMessageHandler(), // + mpIAmCommandReceive(NULL), // + mpCAmDbusWrapper(NULL) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow constructed"); +} + +IAmCommandReceiverShadow::~IAmCommandReceiverShadow() +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow destructed"); +} + +void IAmCommandReceiverShadow::connect(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::connect called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sourceID_t sourceID = (am_sourceID_t) mDBUSMessageHandler.getUInt(); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + am_mainConnectionID_t mainConnectionID = 0; + am_Error_e returnCode = mpIAmCommandReceive->connect(sourceID, sinkID, mainConnectionID); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append((dbus_uint16_t) mainConnectionID); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::disconnect(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::disconnect called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_mainConnectionID_t mainConnnectionID = (am_mainConnectionID_t) mDBUSMessageHandler.getUInt(); + am_Error_e returnCode = mpIAmCommandReceive->disconnect(mainConnnectionID); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::setVolume(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::setVolume called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + am_volume_t volume = (am_volume_t) mDBUSMessageHandler.getInt(); + am_Error_e returnCode = mpIAmCommandReceive->setVolume(sinkID, volume); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::volumeStep(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::volumeStep called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + int16_t volumeStep = (int16_t) mDBUSMessageHandler.getInt(); + am_Error_e returnCode = mpIAmCommandReceive->volumeStep(sinkID, volumeStep); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::setSinkMuteState(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::setSinkMuteState called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + am_MuteState_e muteState = (am_MuteState_e) mDBUSMessageHandler.getInt(); + am_Error_e returnCode = mpIAmCommandReceive->setSinkMuteState(sinkID, muteState); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::setMainSinkSoundProperty(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::setMainSinkSoundProperty called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + dbus_int16_t type = 0; + dbus_int16_t value = 0; + mDBUSMessageHandler.getProperty(type, value); + am_MainSoundProperty_s mainSoundProperty; + mainSoundProperty.type = (am_MainSoundPropertyType_e) type; + mainSoundProperty.value = (int32_t) value; + am_Error_e returnCode = mpIAmCommandReceive->setMainSinkSoundProperty(mainSoundProperty, sinkID); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::setMainSourceSoundProperty(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::setMainSourceSoundProperty called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sourceID_t sourceID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + dbus_int16_t type = 0; + dbus_int16_t value = 0; + mDBUSMessageHandler.getProperty(type, value); + am_MainSoundProperty_s mainSoundProperty; + mainSoundProperty.type = (am_MainSoundPropertyType_e) type; + mainSoundProperty.value = (int32_t) value; + am_Error_e returnCode = mpIAmCommandReceive->setMainSourceSoundProperty(mainSoundProperty, sourceID); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::setSystemProperty(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::setSystemProperty called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + dbus_int16_t type = 0; + dbus_int16_t value = 0; + mDBUSMessageHandler.getProperty(type, value); + am_SystemProperty_s systemProperty; + systemProperty.type = (am_SystemPropertyType_e) type; + systemProperty.value = (int32_t) value; + am_Error_e returnCode = mpIAmCommandReceive->setSystemProperty(systemProperty); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListMainConnections(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListMainConnections called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listMainConnections; + am_Error_e returnCode = mpIAmCommandReceive->getListMainConnections(listMainConnections); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listMainConnections); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListMainSinks(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListMainSinks called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listSinks; + am_Error_e returnCode = mpIAmCommandReceive->getListMainSinks(listSinks); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSinks); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListMainSources(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListMainSources called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listSources; + am_Error_e returnCode = mpIAmCommandReceive->getListMainSources(listSources); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSources); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListMainSinkSoundProperties(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListMainSinkSoundProperties called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sinkID_t sinkID = (am_sinkID_t) mDBUSMessageHandler.getUInt(); + std::vector listSinkSoundProperties; + am_Error_e returnCode = mpIAmCommandReceive->getListMainSinkSoundProperties(sinkID, listSinkSoundProperties); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSinkSoundProperties); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListMainSourceSoundProperties(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListMainSourceSoundProperties called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_sourceID_t sourceID = (am_sourceID_t) mDBUSMessageHandler.getUInt(); + std::vector listSinkSoundProperties; + am_Error_e returnCode = mpIAmCommandReceive->getListMainSourceSoundProperties(sourceID, listSinkSoundProperties); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSinkSoundProperties); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListSourceClasses(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListSourceClasses called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listSourceClasses; + am_Error_e returnCode = mpIAmCommandReceive->getListSourceClasses(listSourceClasses); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSourceClasses); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListSinkClasses(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListSinkClasses called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listSinkClasses; + am_Error_e returnCode = mpIAmCommandReceive->getListSinkClasses(listSinkClasses); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSinkClasses); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getListSystemProperties(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getListSystemProperties called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + std::vector listSystemProperties; + am_Error_e returnCode = mpIAmCommandReceive->getListSystemProperties(listSystemProperties); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append(listSystemProperties); + mDBUSMessageHandler.sendMessage(); +} + +void IAmCommandReceiverShadow::getTimingInformation(DBusConnection *conn, DBusMessage *msg) +{ + log(&commandDbus, DLT_LOG_INFO, "CommandReceiverShadow::getTimingInformation called"); + + (void) conn; + assert(mpIAmCommandReceive!=NULL); + + mDBUSMessageHandler.initReceive(msg); + am_mainConnectionID_t mainConnectionID = (am_mainConnectionID_t) mDBUSMessageHandler.getUInt(); + am_timeSync_t delay = 0; + am_Error_e returnCode = mpIAmCommandReceive->getTimingInformation(mainConnectionID, delay); + mDBUSMessageHandler.initReply(msg); + mDBUSMessageHandler.append((dbus_int16_t) returnCode); + mDBUSMessageHandler.append((dbus_int16_t) delay); + mDBUSMessageHandler.sendMessage(); +} + +DBusHandlerResult IAmCommandReceiverShadow::receiveCallback(DBusConnection *conn, DBusMessage *msg, void *user_data) +{ + assert(conn!=NULL); + assert(msg!=NULL); + assert(user_data!=NULL); + IAmCommandReceiverShadow* reference = (IAmCommandReceiverShadow*) user_data; + return (reference->receiveCallbackDelegate(conn, msg)); +} + +void IAmCommandReceiverShadow::sendIntrospection(DBusConnection *conn, DBusMessage *msg) +{ + assert(conn!=NULL); + assert(msg!=NULL); + DBusMessage* reply; + DBusMessageIter args; + dbus_uint32_t serial = 0; + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + std::ifstream in("CommandInterface.xml", std::ifstream::in); + if (!in) + { + logError("IAmCommandReceiverShadow::sendIntrospection could not load xml file"); + throw std::runtime_error("IAmCommandReceiverShadow::sendIntrospection Could not load introspecton XML"); + } + std::string introspect((std::istreambuf_iterator(in)), std::istreambuf_iterator()); + 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(DLT_CONTEXT,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(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!")); + } + dbus_connection_flush(conn); + + // free the reply + dbus_message_unref(reply); +} + +DBusHandlerResult IAmCommandReceiverShadow::receiveCallbackDelegate(DBusConnection *conn, DBusMessage *msg) +{ + //DLT_LOG(dMain, DLT_LOG_INFO, DLT_STRING("message received")); + + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) + { + sendIntrospection(conn, msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + functionMap_t::iterator iter = mFunctionMap.begin(); + std::string k(dbus_message_get_member(msg)); + iter = mFunctionMap.find(k); + if (iter != mFunctionMap.end()) + { + std::string p(iter->first); + CallBackMethod cb = iter->second; + (this->*cb)(conn, msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + +void IAmCommandReceiverShadow::setCommandReceiver(IAmCommandReceive*& receiver) +{ + assert(receiver!=NULL); + mpIAmCommandReceive = receiver; + + gObjectPathVTable.message_function = IAmCommandReceiverShadow::receiveCallback; + + DBusConnection* connection; + mpIAmCommandReceive->getDBusConnectionWrapper(mpCAmDbusWrapper); + assert(mpCAmDbusWrapper!=NULL); + + mpCAmDbusWrapper->getDBusConnection(connection); + assert(connection!=NULL); + mDBUSMessageHandler.setDBusConnection(connection); + + std::string path(MY_NODE); + mpCAmDbusWrapper->registerCallback(&gObjectPathVTable, path, this); +} + +IAmCommandReceiverShadow::functionMap_t IAmCommandReceiverShadow::createMap() +{ + functionMap_t m; + m["Connect"] = &IAmCommandReceiverShadow::connect; + m["Disconnect"] = &IAmCommandReceiverShadow::disconnect; + m["SetVolume"] = &IAmCommandReceiverShadow::setVolume; + m["VolumeStep"] = &IAmCommandReceiverShadow::volumeStep; + m["SetSinkMuteState"] = &IAmCommandReceiverShadow::setSinkMuteState; + m["SetMainSinkSoundProperty"] = &IAmCommandReceiverShadow::setMainSinkSoundProperty; + m["SetMainSourceSoundProperty"] = &IAmCommandReceiverShadow::setMainSourceSoundProperty; + m["GetListMainConnections"] = &IAmCommandReceiverShadow::getListMainConnections; + m["GetListMainSinks"] = &IAmCommandReceiverShadow::getListMainSinks; + m["GetListMainSources"] = &IAmCommandReceiverShadow::getListMainSources; + m["GetListMainSinkSoundProperties"] = &IAmCommandReceiverShadow::getListMainSinkSoundProperties; + m["GetListMainSourceSoundProperties"] = &IAmCommandReceiverShadow::getListMainSourceSoundProperties; + m["GetListSourceClasses"] = &IAmCommandReceiverShadow::getListSourceClasses; + m["GetListSinkClasses"] = &IAmCommandReceiverShadow::getListSinkClasses; + m["GetListSystemProperties"] = &IAmCommandReceiverShadow::getListSystemProperties; + m["GetTimingInformation"] = &IAmCommandReceiverShadow::getTimingInformation; + m["SetSystemProperty"] = &IAmCommandReceiverShadow::setSystemProperty; + return (m); +} + diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.cpp b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.cpp new file mode 100644 index 0000000..c3f53e1 --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.cpp @@ -0,0 +1,71 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file DbusCommandInterfaceBackdoor.cpp +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#include "CAmCommandSenderDbusBackdoor.h" +#include "command/IAmCommandReceive.h" + + +using namespace am; + +CAmCommandSenderDbusBackdoor::CAmCommandSenderDbusBackdoor() +{ +} + +CAmCommandSenderDbusBackdoor::~CAmCommandSenderDbusBackdoor() +{ +} + +void CAmCommandSenderDbusBackdoor::setReceiveInterface(CAmCommandSenderDbus *sender, IAmCommandReceive* interface) +{ + sender->mpIAmCommandReceive=interface; +} + +void CAmCommandSenderDbusBackdoor::setDbusConnection(CAmCommandSenderDbus *sender, DBusConnection *conn) +{ + sender->mCAmDbusMessageHandler.setDBusConnection(conn); +} + +void CAmCommandSenderDbusBackdoor::setListSinks(CAmCommandSenderDbus *sender, std::vector newList) +{ + sender->mlistSinks=newList; +} + +void CAmCommandSenderDbusBackdoor::setListSources(CAmCommandSenderDbus *sender, std::vector newList) +{ + sender->mlistSources=newList; +} + + + + + + + + + + + + + diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.h b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.h new file mode 100644 index 0000000..bbbeda9 --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusBackdoor.h @@ -0,0 +1,52 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file DubsIAmCommandBackdoor +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#ifndef DBUSCOMMANDINTERFACEBACKDOOR_H_ +#define DBUSCOMMANDINTERFACEBACKDOOR_H_ + +#include "../include/CAmCommandSenderDbus.h" +#include +#include +#include "audiomanagertypes.h" +#include "command/IAmCommandReceive.h" + +namespace am { + +class CAmCommandSenderDbus; + +class CAmCommandSenderDbusBackdoor +{ +public: + CAmCommandSenderDbusBackdoor(); + virtual ~CAmCommandSenderDbusBackdoor(); + void setReceiveInterface(CAmCommandSenderDbus *sender, IAmCommandReceive* interface); + void setDbusConnection(CAmCommandSenderDbus *sender,DBusConnection *conn); + void setListSinks(CAmCommandSenderDbus *sender, std::vector newList); + void setListSources(CAmCommandSenderDbus *sender, std::vector newList); +}; + +} + +#endif /* DBUSCOMMANDINTERFACEBACKDOOR_H_ */ diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.cpp b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.cpp new file mode 100644 index 0000000..071af58 --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.cpp @@ -0,0 +1,806 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file dbuscommandinterfacesignalsTest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmCommandSenderDbusSignalTest.h" +#include +#include +#include +#include +#include +#include +#include +#include "CAmCommandSenderDbusBackdoor.h" +#include "MockIAmCommandReceive.h" +#include "../include/CAmCommandSenderDbus.h" +#include "../include/CAmDbusMessageHandler.h" +#include "../../AudioManagerDaemon/include/TAmPluginTemplate.h" +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +CAmCommandSenderDbusSignalTest::CAmCommandSenderDbusSignalTest() +{ + CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest"); + logInfo("dbusCommandInterfaceSignalTest started"); +} + +CAmCommandSenderDbusSignalTest::~CAmCommandSenderDbusSignalTest() +{ +} + +void* NumberOfMainConnectionsChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_MainConnectionType_s mainConnection; + sender->cbNewMainConnection(mainConnection); + return (NULL); +} + +void* cbSinkAdded(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + std::vector list; + am_SinkType_s mysink; + mysink.name = "MySink"; + mysink.sinkID = 23; + mysink.availability.availability = A_MAX; + mysink.availability.availabilityReason = AR_UNKNOWN; + mysink.muteState = MS_UNKNOWN; + mysink.sinkClassID = 3; + mysink.volume = 234; + sender->cbNewSink(mysink); + return (NULL); +} + +void* cbSourceAdded(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_SourceType_s mysource; + mysource.name = "MySink"; + mysource.sourceID = 42; + mysource.availability.availability = A_MAX; + mysource.availability.availabilityReason = AR_UNKNOWN; + mysource.sourceClassID = 15; + sender->cbNewSource(mysource); + return (NULL); +} + +void* cbSourceRemoved(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_SourceType_s mysource; + mysource.name = "MySink"; + mysource.sourceID = 42; + sender->cbRemovedSource(mysource.sourceID); + return (NULL); +} + +void* cbSinkRemoved(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_SinkType_s mysink; + mysink.name = "MySink"; + mysink.sinkID = 23; + sender->cbRemovedSink(mysink.sinkID); + return (NULL); +} + +void* NumberOfSinkClassesChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + sender->cbNumberOfSinkClassesChanged(); + return (NULL); +} + +void* NumberOfSourceClassesChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + sender->cbNumberOfSourceClassesChanged(); + return (NULL); +} + +void* MainConnectionStateChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_connectionID_t id = 4; + am_ConnectionState_e state = CS_CONNECTING; + sender->cbMainConnectionStateChanged(id, state); + return (NULL); +} + +void* MainSinkSoundPropertyChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_sinkID_t sinkID = 3; + am_MainSoundProperty_s soundProperty; + soundProperty.type = MSP_UNKNOWN; + soundProperty.value = 23; + sender->cbMainSinkSoundPropertyChanged(sinkID, soundProperty); + return (NULL); +} + +void* MainSourceSoundPropertyChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_sourceID_t sourceID = 35; + am_MainSoundProperty_s soundProperty; + soundProperty.type = MSP_UNKNOWN; + soundProperty.value = 233; + sender->cbMainSourceSoundPropertyChanged(sourceID, soundProperty); + return (NULL); +} + +void* cbSinkAvailabilityChangedLoop(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_Availability_s av; + av.availability = A_AVAILABLE; + av.availabilityReason = AR_UNKNOWN; + sender->cbSinkAvailabilityChanged(4, av); + return (NULL); +} + +void* VolumeChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_volume_t volume = 344; + sender->cbVolumeChanged(23, volume); + return (NULL); +} + +void* cbSourceAvailabilityChangedLoop(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_Availability_s av; + av.availability = A_AVAILABLE; + av.availabilityReason = AR_UNKNOWN; + sender->cbSourceAvailabilityChanged(2, av); + return (NULL); +} + +void* SinkMuteStateChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + sender->cbSinkMuteStateChanged(42, MS_MUTED); + return (NULL); +} + +void* SystemPropertyChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + am_SystemProperty_s property; + property.type = SYP_UNKNOWN; + property.value = 355; + sender->cbSystemPropertyChanged(property); + return (NULL); +} + +void* TimingInformationChanged(void* ppCommandSend) +{ + sleep(1); + IAmCommandSend* sender=static_cast(ppCommandSend); + sender->cbTimingInformationChanged(42, 233); + return (NULL); +} + +TEST_F(CAmCommandSenderDbusSignalTest,cbSourceAvailabilityChanged) +{ + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + CAmSocketHandler pSocketHandler; + CAmDbusWrapper pDBusWrapper(&pSocketHandler); + MockIAmCommandReceive pReceiveInterface; + + IAmCommandSend* (*createFunc)(); + void* tempLibHandle = NULL; + std::string libname("../plugins/command/libPluginCommandInterfaceDbus.so"); + createFunc = getCreateFunction(libname, tempLibHandle); + + if (!createFunc) + { + logError("CommandSendInterface Test Entry point of RoutingPlugin not found"); + exit(1); + } + + ppCommandSend = createFunc(); + + if (!ppCommandSend) + { + logError("CommandSendInterface Test RoutingPlugin initialization failed. Entry Function not callable"); + exit(1); + } + + // ok, here we give the DBusWrapper pointer to the Plugin and start the interface + EXPECT_CALL(pReceiveInterface,getDBusConnectionWrapper(_)).WillRepeatedly(DoAll(SetArgReferee<0>(&pDBusWrapper), Return(E_OK))); + EXPECT_CALL(pReceiveInterface, confirmCommandReady(10)); + + ppCommandSend->startupInterface(&pReceiveInterface); + ppCommandSend->setCommandReady(10); + + pthread_t pythonloop; + pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchsignal(*arg, **kwarg):\n" + " print ('Caught NumberOfMainConnectionsChanged') \n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSinkAdded(*arg, **karg):\n" + " print ('Caught signal (in SinkAdded handler) ') \n" + " print (arg[0])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + std::ifstream ifs("/tmp/result.txt"); + std::string line; + int lineCounter = 0, result = 0; + while (std::getline(ifs, line)) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(23), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.Int16(234), dbus.Int16(0), dbus.UInt16(3)), signature=None)"), 0); + } + ifs.close(); + + pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSinkRemoved(*arg, **karg):\n" + " print ('Caught signal (in SinkRemoved handler) ') \n" + " print (arg[0])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 23); + } + ifs.close(); + + pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSourceAdded(*arg, **karg):\n" + " print ('Caught signal (in SourceAdded handler) ') \n" + " print (arg[0])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(42), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.UInt16(15)), signature=None)"), 0); + } + ifs.close(); + + pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSourceRemoved(*arg, **karg):\n" + " print ('Caught signal (in SinkRemoved handler) ') \n" + " print (arg[0])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 42); + } + ifs.close(); + + pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n" + " print ('Caught catchNumberOfSinkClassesChanged') \n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n" + " print ('Caught CatchNumberOfSourceClassesChanged') \n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchMainConnectionStateChanged(*arg, **karg):\n" + " print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 4); + } + else if (lineCounter == 1) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, CS_CONNECTING); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchMainSinkSoundPropertyChanged(*arg, **karg):\n" + " print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 3); + } + else if (lineCounter == 1) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(23)), signature=None)"), 0); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchMainSourceSoundPropertyChanged(*arg, **karg):\n" + " print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 35); + } + else if (lineCounter == 1) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(233)), signature=None)"), 0); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSinkAvailabilityChanged(*arg, **karg):\n" + " print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 4); + } + else if (lineCounter == 1) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSourceAvailability(*arg, **karg):\n" + " print ('Caught signal (in catchSourceAvailability handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 2); + } + else if (lineCounter == 1) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(0)), signature=None)"), 0); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, VolumeChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchVolumeChanged(*arg, **karg):\n" + " print ('Caught signal (in catchVolumeChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 23); + } + else if (lineCounter == 1) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 344); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSinkMuteStateChanged(*arg, **karg):\n" + " print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 42); + } + else if (lineCounter == 1) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, MS_MUTED); + } + lineCounter++; + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchSystemPropertyChanged(*arg, **karg):\n" + " print ('Caught signal (in catchSystemPropertyChanged handler) ') \n" + " print (arg[0])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0); + } + ifs.close(); + + //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) + //so it is running in the main context and the signals are send from threads... + pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) ppCommandSend); + PyRun_SimpleStringFlags("import sys\n" + "import traceback\n" + "import gobject\n" + "import dbus\n" + "import dbus.mainloop.glib\n" + "loop = gobject.MainLoop()\n" + "def catchTimingInformationChanged(*arg, **karg):\n" + " print ('Caught signal (in catchTimingInformationChanged handler) ') \n" + " print (arg[0])\n" + " print (arg[1])\n" + " f = open('/tmp/result.txt','w')\n" + " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" + " f.close()\n" + " loop.quit()\n" + "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" + "bus = dbus.SessionBus()\n" + "bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" + "loop.run()\n", NULL); + pthread_join(pythonloop, NULL); + + ifs.open("/tmp/result.txt"); + lineCounter = 0; + result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 0) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 42); + } + else if (lineCounter == 1) + { + std::stringstream(line) >> result; + ASSERT_EQ(result, 233); + } + lineCounter++; + } + ifs.close(); + +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +void CAmCommandSenderDbusSignalTest::SetUp() +{ + Py_Initialize(); +} + +void CAmCommandSenderDbusSignalTest::TearDown() +{ + Py_Finalize(); +} + diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.h b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.h new file mode 100644 index 0000000..14ad9ef --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusSignalTest.h @@ -0,0 +1,51 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file dbuscommandinterfacesignalsTest.h +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + +#ifndef DBUSCOMMANINTERFACESIGNALSTEST_H_ +#define DBUSCOMMANINTERFACESIGNALSTEST_H_ + + +#include +#include + +#define UNIT_TEST 1 + +namespace am { + +class IAmCommandSend; + +class CAmCommandSenderDbusSignalTest: public ::testing::Test +{ +public: + IAmCommandSend *ppCommandSend; + CAmCommandSenderDbusSignalTest(); + virtual ~CAmCommandSenderDbusSignalTest(); + void SetUp(); + void TearDown(); +}; + +} + +#endif /* DBUSCOMMANINTERFACESIGNALSTEST_H_ */ diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.cpp b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.cpp new file mode 100644 index 0000000..e1d0197 --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.cpp @@ -0,0 +1,629 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file dbuscommandpluginInterfaceTest.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmCommandSenderDbusTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "TAmPluginTemplate.h" +#include "MockIAmCommandReceive.h" +#include "shared/CAmDltWrapper.h" +#include "shared/CAmSocketHandler.h" +#include "shared/CAmDbusWrapper.h" +#include "../include/CAmCommandSenderDbus.h" +#include "../include/CAmDbusMessageHandler.h" + +using namespace am; +using namespace testing; + +std::string DBUSCOMMAND = "dbus-send --session --print-reply --dest=org.genivi.audiomanager /org/genivi/audiomanager/CommandInterface org.genivi.audiomanager.CommandInterface."; + +void* run_the_loop(void* wrapper) +{ + CAmSocketHandler* wrap = (CAmSocketHandler*) wrapper; + wrap->start_listenting(); + return (NULL); +} + +CAmCommandSenderDbusTest::CAmCommandSenderDbusTest() +{ + CAmDltWrapper::instance()->registerApp("dbusTest", "dbusTest"); +} + +CAmCommandSenderDbusTest::~CAmCommandSenderDbusTest() +{ + +} + +void CAmCommandSenderDbusTest::SetUp() +{ + +} + +void CAmCommandSenderDbusTest::TearDown() +{ + +} + +ACTION(returnListConnections){ +std::vector list; +am::am_MainConnectionType_s listItem; +listItem.mainConnectionID=15; +listItem.sinkID=4; +listItem.sourceID=3; +listItem.connectionState=CS_UNKNOWN; +listItem.delay=34; +list.push_back(listItem); +arg0=list; +} + +ACTION(returnListSinks){ +std::vector list; +am::am_SinkType_s listItem; +listItem.availability.availability=A_UNAVAILABLE; +listItem.availability.availabilityReason=AR_GENIVI_NOMEDIA; +listItem.muteState=MS_UNMUTED; +listItem.name="mySink"; +listItem.sinkClassID=34; +listItem.sinkID=24; +listItem.volume=124; +list.push_back(listItem); +arg0=list; +} + +ACTION(returnListSources){ +std::vector list; +am::am_SourceType_s listItem; +listItem.availability.availability=A_MAX; +listItem.availability.availabilityReason=AR_GENIVI_SAMEMEDIA; +listItem.name="MySource"; +listItem.sourceClassID=12; +listItem.sourceID=224; +list.push_back(listItem); +listItem.name="NextSource"; +listItem.sourceID=22; +list.push_back(listItem); +arg0=list; +} + +ACTION(returnListMainSinkSoundProperties){ +std::vector list; +am::am_MainSoundProperty_s listItem; +listItem.type=MSP_MAX; +listItem.value=223; +list.push_back(listItem); +listItem.type=MSP_UNKNOWN; +listItem.value=2; +list.push_back(listItem); +arg1=list; +} + +ACTION(returnListSourceClasses){ +std::vector list; +am::am_SourceClass_s listItem; +am::am_ClassProperty_s property; +property.classProperty=CP_GENIVI_SINK_TYPE; +property.value=12; +listItem.name="FirstCLass"; +listItem.sourceClassID=23; +listItem.listClassProperties.push_back(property); +list.push_back(listItem); +listItem.name="SecondCLass"; +listItem.sourceClassID=2; +listItem.listClassProperties.push_back(property); +list.push_back(listItem); +arg0=list; +} + +ACTION(returnListSinkClasses){ +std::vector list; +am::am_SinkClass_s listItem; +am::am_ClassProperty_s property; +property.classProperty=CP_GENIVI_SOURCE_TYPE; +property.value=122; +listItem.name="FirstCLass"; +listItem.sinkClassID=2123; +listItem.listClassProperties.push_back(property); +list.push_back(listItem); +listItem.name="SecondCLass"; +listItem.sinkClassID=23; +listItem.listClassProperties.push_back(property); +list.push_back(listItem); +arg0=list; +} + +ACTION(returnListSystemProperties){ +std::vector list; +am::am_SystemProperty_s listItem; +listItem.type=SYP_UNKNOWN; +listItem.value=-2245; +list.push_back(listItem); +arg0=list; +} + +ACTION(returnTimingInfo){ +am::am_timeSync_t time=23; +arg1=time; +} + +TEST_F(CAmCommandSenderDbusTest, MessageTest) +{ + Py_Initialize(); + //unfortunatly we need to put all in one testcase because testing with the dbus loop caused problems... + CAmSocketHandler pSocketHandler; + CAmDbusWrapper pDBusWrapper(&pSocketHandler); + pthread_t ptestThread; + std::vector plistCommandPluginDirs; + plistCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); + + MockIAmCommandReceive pReceiveInterface; + + //this class just creates the thread that will handle the mainloop... + pthread_create(&ptestThread, NULL, run_the_loop, (void*) &pSocketHandler); + + IAmCommandSend* (*createFunc)(); + void* tempLibHandle = NULL; + std::string libname("../plugins/command/libPluginCommandInterfaceDbus.so"); + createFunc = getCreateFunction(libname, tempLibHandle); + + if (!createFunc) + { + logError("CommandSendInterface Test Entry point of RoutingPlugin not found"); + exit(1); + } + + ppCommandSend = createFunc(); + + if (!ppCommandSend) + { + logError("CommandSendInterface Test RoutingPlugin initialization failed. Entry Function not callable"); + exit(1); + } + +// ok, here we give the DBusWrapper pointer to the Plugin and start the interface + EXPECT_CALL(pReceiveInterface,getDBusConnectionWrapper(_)).WillRepeatedly(DoAll(SetArgReferee<0>(&pDBusWrapper), Return(E_OK))); + EXPECT_CALL(pReceiveInterface, confirmCommandReady(10)); + + ppCommandSend->startupInterface(&pReceiveInterface); + ppCommandSend->setCommandReady(10); + + EXPECT_CALL(pReceiveInterface,connect(2,3,_)).WillRepeatedly(DoAll(SetArgReferee<2>(35), Return(E_OK))); + system((DBUSCOMMAND + std::string("Connect uint16:2 uint16:3 > /tmp/result.txt ")).c_str()); + + //check the results + std::ifstream ifs("/tmp/result.txt"); + std::string line; + int lineCounter = 0, result = 0; + while (std::getline(ifs, line)) + { + if (lineCounter == 1) + { + std::stringstream(line.replace(line.begin(), line.begin() + 9, "")) >> result; + ASSERT_EQ(result, E_OK); + } + else if (lineCounter == 2) + { + std::stringstream(line.replace(line.begin(), line.begin() + 10, "")) >> result; + ASSERT_EQ(result, 35); + } + lineCounter++; + } + ifs.close(); + + std::cout << "[connect ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,disconnect(2)).WillOnce(Return(E_OK)); + system((DBUSCOMMAND + std::string("Disconnect uint16:2 > /tmp/result.txt ")).c_str()); + + //check the results + lineCounter = 0; + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + if (lineCounter == 1) + { + std::stringstream(line.replace(line.begin(), line.begin() + 9, "")) >> result; + ASSERT_EQ(result, E_OK); + } + lineCounter++; + } + ifs.close(); + + std::cout << "[disconnect]" << std::endl; + + EXPECT_CALL(pReceiveInterface,setVolume(22,12)).WillOnce(Return(E_OK)); + system((DBUSCOMMAND + std::string("SetVolume uint16:22 int16:12 > /tmp/result.txt ")).c_str()); + + //check the results + lineCounter = 0; + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + if (lineCounter == 1) + { + std::stringstream(line.replace(line.begin(), line.begin() + 9, "")) >> result; + ASSERT_EQ(result, E_OK); + } + lineCounter++; + } + ifs.close(); + + std::cout << "[setVolume ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,volumeStep(2,1)).WillOnce(Return(E_OK)); + system((DBUSCOMMAND + std::string("VolumeStep uint16:2 int16:1 > /tmp/result.txt ")).c_str()); + + //check the results + lineCounter = 0; + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + if (lineCounter == 1) + { + std::stringstream(line.replace(line.begin(), line.begin() + 9, "")) >> result; + ASSERT_EQ(result, E_OK); + } + lineCounter++; + } + ifs.close(); + + std::cout << "[volumeStep]" << std::endl; + + EXPECT_CALL(pReceiveInterface,setSinkMuteState(1,MS_UNKNOWN)).WillOnce(Return(E_OK)); + system((DBUSCOMMAND + std::string("SetSinkMuteState uint16:1 int16:0 > /tmp/result.txt ")).c_str()); + + //check the results + lineCounter = 0; + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + if (lineCounter == 1) + { + std::stringstream(line.replace(line.begin(), line.begin() + 9, "")) >> result; + ASSERT_EQ(result, E_OK); + } + lineCounter++; + } + ifs.close(); + + std::cout << "[sinkmutest]" << std::endl; + + EXPECT_CALL(pReceiveInterface,setMainSinkSoundProperty(AllOf(Field(&am_MainSoundProperty_s::value, 3), + Field(&am_MainSoundProperty_s::type,MSP_UNKNOWN)),1)).WillOnce(Return(E_ABORTED)); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='SetMainSinkSoundProperty',\n" + "signature='q(nn)',\n" + "args=[1,(0,3)],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + std::stringstream(line) >> result; + }ASSERT_EQ(result, E_ABORTED); + ifs.close(); + + std::cout << "[sinksound ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,setMainSourceSoundProperty(AllOf(Field(&am_MainSoundProperty_s::value, 3), + Field(&am_MainSoundProperty_s::type,MSP_UNKNOWN)),1)).WillOnce(Return(E_ABORTED)); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='SetMainSourceSoundProperty',\n" + "signature='q(nn)',\n" + "args=[1,(0,3)],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + std::stringstream(line) >> result; + }ASSERT_EQ(result, E_ABORTED); + ifs.close(); + + std::cout << "[sourcesnd ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,setSystemProperty(Field(&am_SystemProperty_s::value,2))).WillOnce(Return(E_DATABASE_ERROR)); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='SetSystemProperty',\n" + "signature='(nn)',\n" + "args=[(2,2)],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + std::stringstream(line) >> result; + }ASSERT_EQ(result, E_DATABASE_ERROR); + ifs.close(); + + std::cout << "[systemprop]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListMainConnections(_)).WillOnce(DoAll(returnListConnections(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListMainConnections',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(15), dbus.UInt16(3), dbus.UInt16(4), dbus.Int16(34), dbus.Int16(0)), signature=None)], signature=dbus.Signature('(qqqnn)')))"), 0); + } + ifs.close(); + + std::cout << "[listmainc ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListMainSinks(_)).WillOnce(DoAll(returnListSinks(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListMainSinks',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(24), dbus.String(u'mySink'), dbus.Struct((dbus.Int16(2), dbus.Int16(3)), signature=None), dbus.Int16(124), dbus.Int16(2), dbus.UInt16(34)), signature=None)], signature=dbus.Signature('(qs(nn)nnq)')))"), 0); + } + ifs.close(); + + std::cout << "[listsinks ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListMainSources(_)).WillOnce(DoAll(returnListSources(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListMainSources',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(224), dbus.String(u'MySource'), dbus.Struct((dbus.Int16(3), dbus.Int16(2)), signature=None), dbus.UInt16(12)), signature=None), dbus.Struct((dbus.UInt16(22), dbus.String(u'NextSource'), dbus.Struct((dbus.Int16(3), dbus.Int16(2)), signature=None), dbus.UInt16(12)), signature=None)], signature=dbus.Signature('(qs(nn)q)')))"), 0); + } + ifs.close(); + + std::cout << "[listsource]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListMainSinkSoundProperties(1,_)).WillOnce(DoAll(returnListMainSinkSoundProperties(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListMainSinkSoundProperties',\n" + "signature='q',\n" + "args=[1],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(4), dbus.Int16(223)), signature=None), dbus.Struct((dbus.Int16(0), dbus.Int16(2)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); + } + ifs.close(); + + std::cout << "[lMainSiPro]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListMainSourceSoundProperties(1,_)).WillOnce(DoAll(returnListMainSinkSoundProperties(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListMainSourceSoundProperties',\n" + "signature='q',\n" + "args=[1],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(4), dbus.Int16(223)), signature=None), dbus.Struct((dbus.Int16(0), dbus.Int16(2)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); + } + ifs.close(); + + std::cout << "[lMainSoPro]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListSourceClasses(_)).WillOnce(DoAll(returnListSourceClasses(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListSourceClasses',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(23), dbus.String(u'FirstCLass'), dbus.Array([dbus.Struct((dbus.Int16(2), dbus.Int16(12)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None), dbus.Struct((dbus.UInt16(2), dbus.String(u'SecondCLass'), dbus.Array([dbus.Struct((dbus.Int16(2), dbus.Int16(12)), signature=None), dbus.Struct((dbus.Int16(2), dbus.Int16(12)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None)], signature=dbus.Signature('(qsa(nn))')))"), 0); + } + ifs.close(); + + std::cout << "[lSourceCla]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListSinkClasses(_)).WillOnce(DoAll(returnListSinkClasses(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListSinkClasses',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(2123), dbus.String(u'FirstCLass'), dbus.Array([dbus.Struct((dbus.Int16(1), dbus.Int16(122)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None), dbus.Struct((dbus.UInt16(23), dbus.String(u'SecondCLass'), dbus.Array([dbus.Struct((dbus.Int16(1), dbus.Int16(122)), signature=None), dbus.Struct((dbus.Int16(1), dbus.Int16(122)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None)], signature=dbus.Signature('(qsa(nn))')))"), 0); + } + ifs.close(); + + std::cout << "[lSinkClass]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getListSystemProperties(_)).WillOnce(DoAll(returnListSystemProperties(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetListSystemProperties',\n" + "signature='',\n" + "args=[],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(0), dbus.Int16(-2245)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); + } + ifs.close(); + + std::cout << "[lSysProp ]" << std::endl; + + EXPECT_CALL(pReceiveInterface,getTimingInformation(2,_)).WillOnce(DoAll(returnTimingInfo(), Return(E_ABORTED))); + + PyRun_SimpleStringFlags("import dbus\n" + "f = open('/tmp/result.txt','w')\n" + "bus = dbus.SessionBus()\n" + "retVal=dbus.Bus().call_blocking(\n" + "bus_name='org.genivi.audiomanager',\n" + "object_path='/org/genivi/audiomanager/CommandInterface',\n" + "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" + "method='GetTimingInformation',\n" + "signature='q',\n" + "args=[2],) \n" + "f.write(str(retVal));\n" + "f.close()", NULL); + result = 0; + ifs.open("/tmp/result.txt"); + while (std::getline(ifs, line)) + { + //we could parse here, but this is the fastest way.... + ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Int16(23))"), 0); + } + ifs.close(); + + std::cout << "[timingInfo]" << std::endl; + Py_Finalize(); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.h b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.h new file mode 100644 index 0000000..a89affd --- /dev/null +++ b/PluginCommandInterfaceDbus/test/CAmCommandSenderDbusTest.h @@ -0,0 +1,61 @@ +/** +* Copyright (C) 2011, BMW AG +* +* GeniviAudioMananger AudioManagerDaemon +* +* \file dbuscommandpluginInterfaceTest.h +* +* \date 20-Oct-2011 3:42:04 PM +* \author Christian Mueller (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 Mueller 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 . +* 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. +* +* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN +*/ + + +#ifndef DBUSCOMMANDPLUGININTERFACETEST_H_ +#define DBUSCOMMANDPLUGININTERFACETEST_H_ + +#include +#include + +#define UNIT_TEST 1 + +namespace am { + +class CAmCommandSenderDbusBackdoor; +class IAmCommandSend; + +/* + * originally, I would want to have several tests, but there are problems implementing this with + * Dbus. + * I use python to send put the messages and to check the returns I get from the Plugin. + * + */ + + +class CAmCommandSenderDbusTest :public ::testing::Test +{ +public: + IAmCommandSend *ppCommandSend; + CAmCommandSenderDbusTest(); + ~CAmCommandSenderDbusTest(); + + void SetUp(); + void TearDown(); +}; + +} + +#endif /* DBUSCOMMANDPLUGININTERFACETEST_H_ */ diff --git a/PluginCommandInterfaceDbus/test/CMakeLists.txt b/PluginCommandInterfaceDbus/test/CMakeLists.txt index 8745af8..d1eabbf 100644 --- a/PluginCommandInterfaceDbus/test/CMakeLists.txt +++ b/PluginCommandInterfaceDbus/test/CMakeLists.txt @@ -23,7 +23,7 @@ cmake_minimum_required(VERSION 2.6) -PROJECT(controlInterfacetest) +PROJECT(CAmCommandSenderDbusTests) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") @@ -41,13 +41,13 @@ INCLUDE_DIRECTORIES( ${STD_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} ${DBUS_ARCH_INCLUDE_DIR} - ${DBUS_INCLUDES_FOLDER} + ${DBUS_include_FOLDER} ${CMAKE_SOURCE_DIR} ${DLT_INCLUDE_DIRS} ${DBUS_INCLUDE_DIR} - ${INCLUDES_FOLDER} + ${include_FOLDER} ${PYTHON_INCLUDE_DIRS} ${GTEST_INCLUDE_DIR} "../../AudioManagerDaemon/include" @@ -55,31 +55,28 @@ INCLUDE_DIRECTORIES( ) file(GLOB DBUS_PLUGIN_INTERFACE_SRCS_CXX - "../../AudioManagerDaemon/src/DBusWrapper.cpp" - "../../AudioManagerDaemon/src/CommandSender.cpp" - "../../AudioManagerDaemon/src/SocketHandler.cpp" - "../../AudioManagerDaemon/src/DLTWrapper.cpp" + "../../AudioManagerDaemon/src/CAmDbusWrapper.cpp" + "../../AudioManagerDaemon/src/CAmSocketHandler.cpp" + "../../AudioManagerDaemon/src/CAmDltWrapper.cpp" "../src/*.cpp" - "dbuscommandpluginInterfaceTest.cpp" - "DbusCommanInterfaceBackdoor.cpp" + "CAmCommandSenderDbusBackdoor.cpp" + "CAmCommandSenderDbusTest.cpp" + ) file(GLOB DBUS_SIGNAL_INTERFACE_SRCS_CXX - "../../AudioManagerDaemon/src/DBusWrapper.cpp" - "../../AudioManagerDaemon/src/CommandSender.cpp" - "../../AudioManagerDaemon/src/SocketHandler.cpp" - "../../AudioManagerDaemon/src/DLTWrapper.cpp" - "../../AudioManagerDaemon/src/DatabaseHandler.cpp" - "../../AudioManagerDaemon/src/ControlSender.cpp" - "../src/*.cpp" - "dbuscommaninterfacesignalsTest.cpp" - "DbusCommandInterfaceBackdoor.cpp" + "../../AudioManagerDaemon/src/CAmDbusWrapper.cpp" + "../../AudioManagerDaemon/src/CAmSocketHandler.cpp" + "../../AudioManagerDaemon/src/CAmDltWrapper.cpp" + "../src/*.cpp" + "CAmCommandSenderDbusBackdoor.cpp" + "CAmCommandSenderDbusSignalTest.cpp" ) -ADD_EXECUTABLE(dbusCommandMessages ${DBUS_PLUGIN_INTERFACE_SRCS_CXX}) +ADD_EXECUTABLE(AmCommandSenderDbusTest ${DBUS_PLUGIN_INTERFACE_SRCS_CXX}) -ADD_EXECUTABLE(dbusCommandSignals ${DBUS_SIGNAL_INTERFACE_SRCS_CXX}) +ADD_EXECUTABLE(AmCommandSenderDbusSignalTest ${DBUS_SIGNAL_INTERFACE_SRCS_CXX}) -TARGET_LINK_LIBRARIES(dbusCommandMessages +TARGET_LINK_LIBRARIES(AmCommandSenderDbusTest ${DLT_LIBRARIES} ${DBUS_LIBRARY} ${CMAKE_DL_LIBS} @@ -90,7 +87,7 @@ TARGET_LINK_LIBRARIES(dbusCommandMessages ) -TARGET_LINK_LIBRARIES(dbusCommandSignals +TARGET_LINK_LIBRARIES(AmCommandSenderDbusSignalTest ${DLT_LIBRARIES} ${DBUS_LIBRARY} ${CMAKE_DL_LIBS} @@ -100,13 +97,13 @@ TARGET_LINK_LIBRARIES(dbusCommandSignals gmock ) -INSTALL(TARGETS dbusCommandMessages +INSTALL(TARGETS AmCommandSenderDbusTest DESTINATION "~/AudioManagerTest/" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ COMPONENT tests ) -INSTALL(TARGETS dbusCommandSignals +INSTALL(TARGETS AmCommandSenderDbusSignalTest DESTINATION "~/AudioManagerTest/" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ COMPONENT tests diff --git a/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.cpp b/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.cpp deleted file mode 100644 index a61f693..0000000 --- a/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file DbusCommandInterfaceBackdoor.cpp -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#include "DbusCommandInterfaceBackdoor.h" - - -using namespace am; - -DbusCommandInterfaceBackdoor::DbusCommandInterfaceBackdoor() -{ -} - -DbusCommandInterfaceBackdoor::~DbusCommandInterfaceBackdoor() -{ -} - -void DbusCommandInterfaceBackdoor::setReceiveInterface(DbusCommandSender *sender, CommandReceiveInterface* interface) -{ - sender->mCommandReceiveInterface=interface; -} - -void DbusCommandInterfaceBackdoor::setDbusConnection(DbusCommandSender *sender, DBusConnection *conn) -{ - sender->mDBUSMessageHandler.setDBusConnection(conn); -} - -void DbusCommandInterfaceBackdoor::setListSinks(DbusCommandSender *sender, std::vector newList) -{ - sender->mlistSinks=newList; -} - -void DbusCommandInterfaceBackdoor::setListSources(DbusCommandSender *sender, std::vector newList) -{ - sender->mlistSources=newList; -} - - - - - - - - - - - - - diff --git a/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.h b/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.h deleted file mode 100644 index 1549e65..0000000 --- a/PluginCommandInterfaceDbus/test/DbusCommandInterfaceBackdoor.h +++ /dev/null @@ -1,51 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file DubsCommandInterfaceBackdoor.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#ifndef DBUSCOMMANDINTERFACEBACKDOOR_H_ -#define DBUSCOMMANDINTERFACEBACKDOOR_H_ - -#include -#include "../include/DBusCommandSender.h" -#include "../include/DBusMessageHandler.h" -#include "../include/CommandReceiverShadow.h" - -namespace am { - -class DbusCommandSender; - -class DbusCommandInterfaceBackdoor -{ -public: - DbusCommandInterfaceBackdoor(); - virtual ~DbusCommandInterfaceBackdoor(); - void setReceiveInterface(DbusCommandSender *sender, CommandReceiveInterface* interface); - void setDbusConnection(DbusCommandSender *sender,DBusConnection *conn); - void setListSinks(DbusCommandSender *sender, std::vector newList); - void setListSources(DbusCommandSender *sender, std::vector newList); -}; - -} - -#endif /* DBUSCOMMANDINTERFACEBACKDOOR_H_ */ diff --git a/PluginCommandInterfaceDbus/test/MockIAmCommandReceive.h b/PluginCommandInterfaceDbus/test/MockIAmCommandReceive.h new file mode 100644 index 0000000..bb9e53f --- /dev/null +++ b/PluginCommandInterfaceDbus/test/MockIAmCommandReceive.h @@ -0,0 +1,59 @@ +#ifndef MOCKCOMMANDRECEIVENTERFACE_H_ +#define MOCKCOMMANDRECEIVENTERFACE_H_ + +#include "command/IAmCommandReceive.h" +#include +#include + +namespace am { + +class MockIAmCommandReceive : public IAmCommandReceive { + public: + MOCK_METHOD3(connect, + am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); + MOCK_METHOD1(disconnect, + am_Error_e(const am_mainConnectionID_t mainConnectionID)); + MOCK_METHOD2(setVolume, + am_Error_e(const am_sinkID_t sinkID, const am_mainVolume_t volume)); + MOCK_METHOD2(volumeStep, + am_Error_e(const am_sinkID_t sinkID, const int16_t volumeStep)); + MOCK_METHOD2(setSinkMuteState, + am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD2(setMainSinkSoundProperty, + am_Error_e(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID)); + MOCK_METHOD2(setMainSourceSoundProperty, + am_Error_e(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID)); + MOCK_METHOD1(setSystemProperty, + am_Error_e(const am_SystemProperty_s& property)); + MOCK_CONST_METHOD1(getListMainConnections, + am_Error_e(std::vector& listConnections)); + MOCK_CONST_METHOD1(getListMainSinks, + am_Error_e(std::vector& listMainSinks)); + MOCK_CONST_METHOD1(getListMainSources, + am_Error_e(std::vector& listMainSources)); + MOCK_CONST_METHOD2(getListMainSinkSoundProperties, + am_Error_e(const am_sinkID_t sinkID, std::vector& listSoundProperties)); + MOCK_CONST_METHOD2(getListMainSourceSoundProperties, + am_Error_e(const am_sourceID_t sourceID, std::vector& listSourceProperties)); + MOCK_CONST_METHOD1(getListSourceClasses, + am_Error_e(std::vector& listSourceClasses)); + MOCK_CONST_METHOD1(getListSinkClasses, + am_Error_e(std::vector& listSinkClasses)); + MOCK_CONST_METHOD1(getListSystemProperties, + am_Error_e(std::vector& listSystemProperties)); + MOCK_CONST_METHOD2(getTimingInformation, + am_Error_e(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay)); + MOCK_CONST_METHOD1(getDBusConnectionWrapper, + am_Error_e(CAmDbusWrapper*& dbusConnectionWrapper)); + MOCK_CONST_METHOD1(getSocketHandler, + am_Error_e(CAmSocketHandler*& socketHandler)); + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(confirmCommandReady, + void(const uint16_t handle)); + MOCK_METHOD1(confirmCommandRundown, + void(const uint16_t handle)); +}; + +} // namespace am +#endif /* MOCKCOMMANDRECEIVENTERFACE_H_ */ diff --git a/PluginCommandInterfaceDbus/test/MockInterfaces.h b/PluginCommandInterfaceDbus/test/MockInterfaces.h deleted file mode 100644 index b4e7792..0000000 --- a/PluginCommandInterfaceDbus/test/MockInterfaces.h +++ /dev/null @@ -1,85 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file MochInterfaces.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#ifndef MOCKINTERFACES_H_ -#define MOCKINTERFACES_H_ - -namespace am { - -class MockCommandReceiveInterface : public CommandReceiveInterface { - public: - MOCK_METHOD3(connect, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); - MOCK_METHOD1(disconnect, - am_Error_e(const am_mainConnectionID_t mainConnectionID)); - MOCK_METHOD2(setVolume, - am_Error_e(const am_sinkID_t sinkID, const am_mainVolume_t volume)); - MOCK_METHOD2(volumeStep, - am_Error_e(const am_sinkID_t sinkID, const int16_t volumeStep)); - MOCK_METHOD2(setSinkMuteState, - am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD2(setMainSinkSoundProperty, - am_Error_e(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID)); - MOCK_METHOD2(setMainSourceSoundProperty, - am_Error_e(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID)); - MOCK_METHOD1(setSystemProperty, - am_Error_e(const am_SystemProperty_s& property)); - MOCK_CONST_METHOD1(getListMainConnections, - am_Error_e(std::vector& listConnections)); - MOCK_CONST_METHOD1(getListMainSinks, - am_Error_e(std::vector& listMainSinks)); - MOCK_CONST_METHOD1(getListMainSources, - am_Error_e(std::vector& listMainSources)); - MOCK_CONST_METHOD2(getListMainSinkSoundProperties, - am_Error_e(const am_sinkID_t sinkID, std::vector& listSoundProperties)); - MOCK_CONST_METHOD2(getListMainSourceSoundProperties, - am_Error_e(const am_sourceID_t sourceID, std::vector& listSourceProperties)); - MOCK_CONST_METHOD1(getListSourceClasses, - am_Error_e(std::vector& listSourceClasses)); - MOCK_CONST_METHOD1(getListSinkClasses, - am_Error_e(std::vector& listSinkClasses)); - MOCK_CONST_METHOD1(getListSystemProperties, - am_Error_e(std::vector& listSystemProperties)); - MOCK_CONST_METHOD2(getTimingInformation, - am_Error_e(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay)); - MOCK_CONST_METHOD1(getDBusConnectionWrapper, - am_Error_e(DBusWrapper*& dbusConnectionWrapper)); - MOCK_CONST_METHOD1(getSocketHandler, - am_Error_e(SocketHandler*& socketHandler)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD1(confirmCommandReady, - void(const uint16_t handle)); - MOCK_METHOD1(confirmCommandRundown, - void(const uint16_t handle)); - - -}; - -} // namespace am - - - -#endif /* MOCKINTERFACES_H_ */ diff --git a/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.cpp b/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.cpp deleted file mode 100644 index f4dab30..0000000 --- a/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.cpp +++ /dev/null @@ -1,608 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file dbuscommandpluginInterfaceTest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include -#include -#include "dbuscommandpluginInterfaceTest.h" -#include -#include -#include "../include/DBusCommandSender.h" -#include "../include/DBusMessageHandler.h" -#include "DbusCommandInterfaceBackdoor.h" -#include "MockInterfaces.h" -#include "DLTWrapper.h" -#include "SocketHandler.h" - -using namespace am; -using namespace testing; - -//DLT_DECLARE_CONTEXT(DLT_CONTEXT) - -std::string DBUSCOMMAND = "dbus-send --session --print-reply --dest=org.genivi.audiomanager /org/genivi/audiomanager/CommandInterface org.genivi.audiomanager.CommandInterface."; - -void* run_the_loop(void* wrapper) -{ - SocketHandler* wrap = (SocketHandler*) wrapper; - wrap->start_listenting(); - return (NULL); -} - -dbuscommandpluginInterfaceTest::dbuscommandpluginInterfaceTest() : - pDatabaseHandler(std::string(":memory:")), // - pControlSender("") // -{ - DLTWrapper::instance()->registerApp("dbusTest", "dbusTest"); -} - -dbuscommandpluginInterfaceTest::~dbuscommandpluginInterfaceTest() -{ - -} - -void dbuscommandpluginInterfaceTest::SetUp() -{ - -} - -void dbuscommandpluginInterfaceTest::TearDown() -{ - -} - -ACTION(returnListConnections){ -std::vector list; -am::am_MainConnectionType_s listItem; -listItem.mainConnectionID=15; -listItem.sinkID=4; -listItem.sourceID=3; -listItem.connectionState=CS_UNKNOWN; -listItem.delay=34; -list.push_back(listItem); -arg0=list; -} - -ACTION(returnListSinks){ -std::vector list; -am::am_SinkType_s listItem; -listItem.availability.availability=A_UNAVAILABLE; -listItem.availability.availabilityReason=AR_GENIVI_NOMEDIA; -listItem.muteState=MS_UNMUTED; -listItem.name="mySink"; -listItem.sinkClassID=34; -listItem.sinkID=24; -listItem.volume=124; -list.push_back(listItem); -arg0=list; -} - -ACTION(returnListSources){ -std::vector list; -am::am_SourceType_s listItem; -listItem.availability.availability=A_MAX; -listItem.availability.availabilityReason=AR_GENIVI_SAMEMEDIA; -listItem.name="MySource"; -listItem.sourceClassID=12; -listItem.sourceID=224; -list.push_back(listItem); -listItem.name="NextSource"; -listItem.sourceID=22; -list.push_back(listItem); -arg0=list; -} - -ACTION(returnListMainSinkSoundProperties){ -std::vector list; -am::am_MainSoundProperty_s listItem; -listItem.type=MSP_MAX; -listItem.value=223; -list.push_back(listItem); -listItem.type=MSP_UNKNOWN; -listItem.value=2; -list.push_back(listItem); -arg1=list; -} - -ACTION(returnListSourceClasses){ -std::vector list; -am::am_SourceClass_s listItem; -am::am_ClassProperty_s property; -property.classProperty=CP_GENIVI_SINK_TYPE; -property.value=12; -listItem.name="FirstCLass"; -listItem.sourceClassID=23; -listItem.listClassProperties.push_back(property); -list.push_back(listItem); -listItem.name="SecondCLass"; -listItem.sourceClassID=2; -listItem.listClassProperties.push_back(property); -list.push_back(listItem); -arg0=list; -} - -ACTION(returnListSinkClasses){ -std::vector list; -am::am_SinkClass_s listItem; -am::am_ClassProperty_s property; -property.classProperty=CP_GENIVI_SOURCE_TYPE; -property.value=122; -listItem.name="FirstCLass"; -listItem.sinkClassID=2123; -listItem.listClassProperties.push_back(property); -list.push_back(listItem); -listItem.name="SecondCLass"; -listItem.sinkClassID=23; -listItem.listClassProperties.push_back(property); -list.push_back(listItem); -arg0=list; -} - -ACTION(returnListSystemProperties){ -std::vector list; -am::am_SystemProperty_s listItem; -listItem.type=SYP_UNKNOWN; -listItem.value=-2245; -list.push_back(listItem); -arg0=list; -} - -ACTION(returnTimingInfo){ -am::am_timeSync_t time=23; -arg1=time; -} - -TEST_F(dbuscommandpluginInterfaceTest,Connect) -{ - Py_Initialize(); - //unfortunatly we need to put all in one testcase because testing with the dbus loop caused problems... - SocketHandler pSocketHandler; - DBusWrapper pDBusWrapper(&pSocketHandler); - pthread_t ptestThread; - std::vector plistCommandPluginDirs; - plistCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); - - CommandSender pCommandSender(plistCommandPluginDirs); - MockCommandReceiveInterface pReceiveInterface; - - //this class just creates the thread that will handle the mainloop... - pthread_create(&ptestThread, NULL, run_the_loop, (void*) &pSocketHandler); - CommandReceiver pCommandReceiver(&pDatabaseHandler, &pControlSender, &pSocketHandler, &pDBusWrapper); - -// ok, here we give the DBusWrapper pointer to the Plugin and start the interface - EXPECT_CALL(pReceiveInterface,getDBusConnectionWrapper(_)).WillRepeatedly(DoAll(SetArgReferee<0>(&pDBusWrapper), Return(E_OK))); - pCommandSender.startupInterfaces(&pCommandReceiver); - - EXPECT_CALL(pReceiveInterface,connect(2,3,_)).WillRepeatedly(DoAll(SetArgReferee<2>(35), Return(E_OK))); - system((DBUSCOMMAND + std::string("Connect uint16:2 uint16:3 > /tmp/result.txt ")).c_str()); - - //check the results - std::ifstream ifs("/tmp/result.txt"); - std::string line; - int lineCounter = 0, result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 1) - { - std::stringstream(line.substr(line.find_first_not_of(" int16 "))) >> result; - ASSERT_EQ(result, E_OK); - } - else if (lineCounter == 2) - { - std::stringstream(line.substr(line.find_first_not_of(" uint16 "))) >> result; - ASSERT_EQ(result, 35); - } - lineCounter++; - } - ifs.close(); - - std::cout << "[connect ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,disconnect(2)).WillOnce(Return(E_OK)); - system((DBUSCOMMAND + std::string("Disconnect uint16:2 > /tmp/result.txt ")).c_str()); - - //check the results - lineCounter = 0; - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - if (lineCounter == 1) - { - std::stringstream(line.substr(line.find_first_not_of(" int16 "))) >> result; - ASSERT_EQ(result, E_OK); - } - lineCounter++; - } - ifs.close(); - - std::cout << "[disconnect]" << std::endl; - - EXPECT_CALL(pReceiveInterface,setVolume(22,12)).WillOnce(Return(E_OK)); - system((DBUSCOMMAND + std::string("SetVolume uint16:22 int16:12 > /tmp/result.txt ")).c_str()); - - //check the results - lineCounter = 0; - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - if (lineCounter == 1) - { - std::stringstream(line.substr(line.find_first_not_of(" int16 "))) >> result; - ASSERT_EQ(result, E_OK); - } - lineCounter++; - } - ifs.close(); - - std::cout << "[setVolume ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,volumeStep(2,1)).WillOnce(Return(E_OK)); - system((DBUSCOMMAND + std::string("VolumeStep uint16:2 int16:1 > /tmp/result.txt ")).c_str()); - - //check the results - lineCounter = 0; - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - if (lineCounter == 1) - { - std::stringstream(line.substr(line.find_first_not_of(" int16 "))) >> result; - ASSERT_EQ(result, E_OK); - } - lineCounter++; - } - ifs.close(); - - std::cout << "[volumeStep]" << std::endl; - - EXPECT_CALL(pReceiveInterface,setSinkMuteState(1,MS_UNKNOWN)).WillOnce(Return(E_OK)); - system((DBUSCOMMAND + std::string("SetSinkMuteState uint16:1 int16:0 > /tmp/result.txt ")).c_str()); - - //check the results - lineCounter = 0; - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - if (lineCounter == 1) - { - std::stringstream(line.substr(line.find_first_not_of(" int16 "))) >> result; - ASSERT_EQ(result, E_OK); - } - lineCounter++; - } - ifs.close(); - - std::cout << "[sinkmutest]" << std::endl; - - EXPECT_CALL(pReceiveInterface,setMainSinkSoundProperty(AllOf(Field(&am_MainSoundProperty_s::value, 3), - Field(&am_MainSoundProperty_s::type,MSP_UNKNOWN)),1)).WillOnce(Return(E_ABORTED)); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='SetMainSinkSoundProperty',\n" - "signature='q(nn)',\n" - "args=[1,(0,3)],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - std::stringstream(line) >> result; - }ASSERT_EQ(result, E_ABORTED); - ifs.close(); - - std::cout << "[sinksound ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,setMainSourceSoundProperty(AllOf(Field(&am_MainSoundProperty_s::value, 3), - Field(&am_MainSoundProperty_s::type,MSP_UNKNOWN)),1)).WillOnce(Return(E_ABORTED)); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='SetMainSourceSoundProperty',\n" - "signature='q(nn)',\n" - "args=[1,(0,3)],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - std::stringstream(line) >> result; - }ASSERT_EQ(result, E_ABORTED); - ifs.close(); - - std::cout << "[sourcesnd ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,setSystemProperty(Field(&am_SystemProperty_s::value,2))).WillOnce(Return(E_DATABASE_ERROR)); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='SetSystemProperty',\n" - "signature='(nn)',\n" - "args=[(2,2)],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - std::stringstream(line) >> result; - }ASSERT_EQ(result, E_DATABASE_ERROR); - ifs.close(); - - std::cout << "[systemprop]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListMainConnections(_)).WillOnce(DoAll(returnListConnections(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListMainConnections',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(15), dbus.UInt16(3), dbus.UInt16(4), dbus.Int16(34), dbus.Int16(0)), signature=None)], signature=dbus.Signature('(qqqnn)')))"), 0); - } - ifs.close(); - - std::cout << "[listmainc ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListMainSinks(_)).WillOnce(DoAll(returnListSinks(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListMainSinks',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(24), dbus.String(u'mySink'), dbus.Struct((dbus.Int16(0), dbus.Int16(2)), signature=None), dbus.Int16(124), dbus.Int16(1), dbus.UInt16(34)), signature=None)], signature=dbus.Signature('(qs(nn)nnq)')))"), 0); - } - ifs.close(); - - std::cout << "[listsinks ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListMainSources(_)).WillOnce(DoAll(returnListSources(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListMainSources',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(224), dbus.String(u'MySource'), dbus.Struct((dbus.Int16(3), dbus.Int16(1)), signature=None), dbus.UInt16(12)), signature=None), dbus.Struct((dbus.UInt16(22), dbus.String(u'NextSource'), dbus.Struct((dbus.Int16(3), dbus.Int16(1)), signature=None), dbus.UInt16(12)), signature=None)], signature=dbus.Signature('(qs(nn)q)')))"), 0); - } - ifs.close(); - - std::cout << "[listsource]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListMainSinkSoundProperties(1,_)).WillOnce(DoAll(returnListMainSinkSoundProperties(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListMainSinkSoundProperties',\n" - "signature='q',\n" - "args=[1],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(2), dbus.Int16(223)), signature=None), dbus.Struct((dbus.Int16(0), dbus.Int16(2)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); - } - ifs.close(); - - std::cout << "[lMainSiPro]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListMainSourceSoundProperties(1,_)).WillOnce(DoAll(returnListMainSinkSoundProperties(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListMainSourceSoundProperties',\n" - "signature='q',\n" - "args=[1],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(2), dbus.Int16(223)), signature=None), dbus.Struct((dbus.Int16(0), dbus.Int16(2)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); - } - ifs.close(); - - std::cout << "[lMainSoPro]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListSourceClasses(_)).WillOnce(DoAll(returnListSourceClasses(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListSourceClasses',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(23), dbus.String(u'FirstCLass'), dbus.Array([dbus.Struct((dbus.Int16(1), dbus.Int16(12)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None), dbus.Struct((dbus.UInt16(2), dbus.String(u'SecondCLass'), dbus.Array([dbus.Struct((dbus.Int16(1), dbus.Int16(12)), signature=None), dbus.Struct((dbus.Int16(1), dbus.Int16(12)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None)], signature=dbus.Signature('(qsa(nn))')))"), 0); - } - ifs.close(); - - std::cout << "[lSourceCla]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListSinkClasses(_)).WillOnce(DoAll(returnListSinkClasses(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListSinkClasses',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.UInt16(2123), dbus.String(u'FirstCLass'), dbus.Array([dbus.Struct((dbus.Int16(0), dbus.Int16(122)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None), dbus.Struct((dbus.UInt16(23), dbus.String(u'SecondCLass'), dbus.Array([dbus.Struct((dbus.Int16(0), dbus.Int16(122)), signature=None), dbus.Struct((dbus.Int16(0), dbus.Int16(122)), signature=None)], signature=dbus.Signature('(nn)'))), signature=None)], signature=dbus.Signature('(qsa(nn))')))"), 0); - } - ifs.close(); - - std::cout << "[lSinkClass]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getListSystemProperties(_)).WillOnce(DoAll(returnListSystemProperties(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetListSystemProperties',\n" - "signature='',\n" - "args=[],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Array([dbus.Struct((dbus.Int16(0), dbus.Int16(-2245)), signature=None)], signature=dbus.Signature('(nn)')))"), 0); - } - ifs.close(); - - std::cout << "[lSysProp ]" << std::endl; - - EXPECT_CALL(pReceiveInterface,getTimingInformation(2,_)).WillOnce(DoAll(returnTimingInfo(), Return(E_ABORTED))); - - PyRun_SimpleStringFlags("import dbus\n" - "f = open('/tmp/result.txt','w')\n" - "bus = dbus.SessionBus()\n" - "retVal=dbus.Bus().call_blocking(\n" - "bus_name='org.genivi.audiomanager',\n" - "object_path='/org/genivi/audiomanager/CommandInterface',\n" - "dbus_interface='org.genivi.audiomanager.CommandInterface',\n" - "method='GetTimingInformation',\n" - "signature='q',\n" - "args=[2],) \n" - "f.write(str(retVal));\n" - "f.close()", NULL); - result = 0; - ifs.open("/tmp/result.txt"); - while (std::getline(ifs, line)) - { - //we could parse here, but this is the fastest way.... - ASSERT_EQ(line.compare("(dbus.Int16(9), dbus.Int16(23))"), 0); - } - ifs.close(); - - std::cout << "[timingInfo]" << std::endl; - Py_Finalize(); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.h b/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.h deleted file mode 100644 index d45a107..0000000 --- a/PluginCommandInterfaceDbus/test/dbuscommandpluginInterfaceTest.h +++ /dev/null @@ -1,72 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file dbuscommandpluginInterfaceTest.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - - -#ifndef DBUSCOMMANDPLUGININTERFACETEST_H_ -#define DBUSCOMMANDPLUGININTERFACETEST_H_ - -#include -#include -#include -#include -#include -#include -#include "CommandReceiver.h" -#include "CommandSender.h" -#include "MockInterfaces.h" -#include "DbusCommandInterfaceBackdoor.h" -#include "DatabaseHandler.h" -#include "ControlSender.h" - - -#define UNIT_TEST 1 - -namespace am { - -class DbusCommandInterfaceBackdoor; - -/* - * originally, I would want to have several tests, but there are problems implementing this with - * Dbus. - * I use python to send put the messages and to check the returns I get from the Plugin. - * - */ - - -class dbuscommandpluginInterfaceTest :public ::testing::Test -{ -public: - DatabaseHandler pDatabaseHandler; - ControlSender pControlSender; - dbuscommandpluginInterfaceTest(); - ~dbuscommandpluginInterfaceTest(); - - void SetUp(); - void TearDown(); -}; - -} - -#endif /* DBUSCOMMANDPLUGININTERFACETEST_H_ */ diff --git a/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.cpp b/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.cpp deleted file mode 100644 index 655a1f3..0000000 --- a/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.cpp +++ /dev/null @@ -1,906 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file dbuscommandinterfacesignalsTest.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "dbuscommaninterfacesignalsTest.h" -#include -#include -#include -#include "../include/DBusCommandSender.h" -#include "../include/DBusMessageHandler.h" -#include "DbusCommandInterfaceBackdoor.h" -#include "MockInterfaces.h" -#include "DLTWrapper.h" - -using namespace am; -using namespace testing; - - -dbuscommaninterfacesignalsTest::dbuscommaninterfacesignalsTest() -{ - DLTWrapper::instance()->registerApp("dbusTest","dbusTest"); - logInfo("dbusCommandInterfaceSignalTest started"); -} - -dbuscommaninterfacesignalsTest::~dbuscommaninterfacesignalsTest() -{ -} - -void* NumberOfMainConnectionsChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNumberOfMainConnectionsChanged(); - return (NULL); -} - -void* cbSinkAdded(void*) -{ - sleep(1); - std::vector list; - am_SinkType_s mysink; - mysink.name = "MySink"; - mysink.sinkID = 23; - mysink.availability.availability = A_MAX; - mysink.availability.availabilityReason = AR_UNKNOWN; - mysink.muteState = MS_UNKNOWN; - mysink.sinkClassID = 3; - mysink.volume = 234; - list.push_back(mysink); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK))); - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNewSink(mysink); - return (NULL); -} - -void* cbSourceAdded(void*) -{ - sleep(1); - std::vector list; - am_SourceType_s myource; - myource.name = "MySink"; - myource.sourceID = 42; - myource.availability.availability = A_MAX; - myource.availability.availabilityReason = AR_UNKNOWN; - myource.sourceClassID = 15; - list.push_back(myource); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK))); - sender.cbNumberOfSourcesChanged(); - return (NULL); -} - -void* cbSourceRemoved(void*) -{ - sleep(1); - std::vector list; - am_SourceType_s myource; - myource.name = "MySink"; - myource.sourceID = 42; - myource.availability.availability = A_MAX; - myource.availability.availabilityReason = AR_UNKNOWN; - myource.sourceClassID = 15; - list.push_back(myource); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - backdoor.setListSources(&sender, list); - DBusError error; - dbus_error_init(&error); - list.clear(); - EXPECT_CALL(receiver,getListMainSources(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK))); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNumberOfSourcesChanged(); - return (NULL); -} - -void* cbSinkRemoved(void*) -{ - sleep(1); - std::vector list; - am_SinkType_s mysink; - mysink.name = "MySink"; - mysink.sinkID = 23; - mysink.availability.availability = A_MAX; - mysink.availability.availabilityReason = AR_UNKNOWN; - mysink.muteState = MS_UNKNOWN; - mysink.sinkClassID = 3; - mysink.volume = 234; - list.push_back(mysink); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - backdoor.setListSinks(&sender, list); - DBusError error; - dbus_error_init(&error); - list.clear(); - EXPECT_CALL(receiver,getListMainSinks(_)).WillOnce(DoAll(SetArgReferee<0>(list), Return(E_OK))); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNumberOfSinksChanged(); - return (NULL); -} - -void* NumberOfSinkClassesChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNumberOfSinkClassesChanged(); - return (NULL); -} - -void* NumberOfSourceClassesChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbNumberOfSourceClassesChanged(); - return (NULL); -} - -void* MainConnectionStateChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_connectionID_t id = 4; - am_ConnectionState_e state = CS_CONNECTING; - sender.cbMainConnectionStateChanged(id, state); - return (NULL); -} - -void* MainSinkSoundPropertyChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_sinkID_t sinkID = 3; - am_MainSoundProperty_s soundProperty; - soundProperty.type = MSP_UNKNOWN; - soundProperty.value = 23; - sender.cbMainSinkSoundPropertyChanged(sinkID, soundProperty); - return (NULL); -} - -void* MainSourceSoundPropertyChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_sourceID_t sourceID = 35; - am_MainSoundProperty_s soundProperty; - soundProperty.type = MSP_UNKNOWN; - soundProperty.value = 233; - sender.cbMainSourceSoundPropertyChanged(sourceID, soundProperty); - return (NULL); -} - -void* cbSinkAvailabilityChangedLoop(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_Availability_s av; - av.availability = A_AVAILABLE; - av.availabilityReason = AR_UNKNOWN; - sender.cbSinkAvailabilityChanged(4, av); - return (NULL); -} - -void* VolumeChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_volume_t volume = 344; - sender.cbVolumeChanged(23, volume); - return (NULL); -} - -void* cbSourceAvailabilityChangedLoop(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_Availability_s av; - av.availability = A_AVAILABLE; - av.availabilityReason = AR_UNKNOWN; - sender.cbSourceAvailabilityChanged(2, av); - return (NULL); -} - -void* SinkMuteStateChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbSinkMuteStateChanged(42, MS_MUTED); - return (NULL); -} - -void* SystemPropertyChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - am_SystemProperty_s property; - property.type = SYP_UNKNOWN; - property.value = 355; - sender.cbSystemPropertyChanged(property); - return (NULL); -} - -void* TimingInformationChanged(void*) -{ - sleep(1); - DbusCommandSender sender; - MockCommandReceiveInterface receiver; - DbusCommandInterfaceBackdoor backdoor; - backdoor.setReceiveInterface(&sender, &receiver); - DBusError error; - dbus_error_init(&error); - DBusConnection* co = dbus_bus_get(DBUS_BUS_SESSION, &error); - backdoor.setDbusConnection(&sender, co); - sender.cbTimingInformationChanged(42, 233); - return (NULL); -} - -TEST_F(dbuscommaninterfacesignalsTest,cbSourceAvailabilityChanged) -{ - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_t pythonloop; - pthread_create(&pythonloop, NULL, NumberOfMainConnectionsChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchsignal(*arg, **kwarg):\n" - " print ('Caught NumberOfMainConnectionsChanged') \n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchsignal, signal_name='NumberOfMainConnectionsChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - pthread_create(&pythonloop, NULL, cbSinkAdded, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSinkAdded(*arg, **karg):\n" - " print ('Caught signal (in SinkAdded handler) ') \n" - " print (arg[0])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSinkAdded, signal_name='SinkAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - std::ifstream ifs("/tmp/result.txt"); - std::string line; - int lineCounter = 0, result = 0; - while (std::getline(ifs, line)) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(23), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.Int16(234), dbus.Int16(0), dbus.UInt16(3)), signature=None)"), 0); - } - ifs.close(); - - pthread_create(&pythonloop, NULL, cbSinkRemoved, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSinkRemoved(*arg, **karg):\n" - " print ('Caught signal (in SinkRemoved handler) ') \n" - " print (arg[0])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSinkRemoved, signal_name='SinkRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 23); - } - ifs.close(); - - pthread_create(&pythonloop, NULL, cbSourceAdded, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSourceAdded(*arg, **karg):\n" - " print ('Caught signal (in SourceAdded handler) ') \n" - " print (arg[0])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSourceAdded, signal_name='SourceAdded', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.UInt16(42), dbus.String(u'MySink'), dbus.Struct((dbus.Int16(3), dbus.Int16(0)), signature=None), dbus.UInt16(15)), signature=None)"), 0); - } - ifs.close(); - - pthread_create(&pythonloop, NULL, cbSourceRemoved, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSourceRemoved(*arg, **karg):\n" - " print ('Caught signal (in SinkRemoved handler) ') \n" - " print (arg[0])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSourceRemoved, signal_name='SourceRemoved', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 42); - } - ifs.close(); - - pthread_create(&pythonloop, NULL, NumberOfSinkClassesChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchNumberOfSinkClassesChanged(*arg, **kwarg):\n" - " print ('Caught catchNumberOfSinkClassesChanged') \n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchNumberOfSinkClassesChanged, signal_name='NumberOfSinkClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - pthread_create(&pythonloop, NULL, NumberOfSourceClassesChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def CatchNumberOfSourceClassesChanged(*arg, **kwarg):\n" - " print ('Caught CatchNumberOfSourceClassesChanged') \n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(CatchNumberOfSourceClassesChanged, signal_name='NumberOfSourceClassesChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, MainConnectionStateChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchMainConnectionStateChanged(*arg, **karg):\n" - " print ('Caught signal (in catchMainConnectionStateChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchMainConnectionStateChanged, signal_name='MainConnectionStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 4); - } - else if (lineCounter == 1) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, CS_CONNECTING); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, MainSinkSoundPropertyChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchMainSinkSoundPropertyChanged(*arg, **karg):\n" - " print ('Caught signal (in catchMainSinkSoundPropertyChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchMainSinkSoundPropertyChanged, signal_name='MainSinkSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 3); - } - else if (lineCounter == 1) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(23)), signature=None)"), 0); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, MainSourceSoundPropertyChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchMainSourceSoundPropertyChanged(*arg, **karg):\n" - " print ('Caught signal (in catchMainSourceSoundPropertyChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchMainSourceSoundPropertyChanged, signal_name='MainSourceSoundPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 35); - } - else if (lineCounter == 1) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(1), dbus.Int16(233)), signature=None)"), 0); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, cbSinkAvailabilityChangedLoop, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSinkAvailabilityChanged(*arg, **karg):\n" - " print ('Caught signal (in catchSinkAvailabilityChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSinkAvailabilityChanged, signal_name='SinkAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 4); - } - else if (lineCounter == 1) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, cbSourceAvailabilityChangedLoop, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSourceAvailability(*arg, **karg):\n" - " print ('Caught signal (in catchSourceAvailability handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSourceAvailability, signal_name='SourceAvailabilityChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 2); - } - else if (lineCounter == 1) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(3)), signature=None)"), 0); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, VolumeChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchVolumeChanged(*arg, **karg):\n" - " print ('Caught signal (in catchVolumeChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchVolumeChanged, signal_name='VolumeChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 23); - } - else if (lineCounter == 1) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 344); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, SinkMuteStateChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSinkMuteStateChanged(*arg, **karg):\n" - " print ('Caught signal (in catchSinkMuteStateChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSinkMuteStateChanged, signal_name='SinkMuteStateChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 42); - } - else if (lineCounter == 1) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, MS_MUTED); - } - lineCounter++; - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, SystemPropertyChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchSystemPropertyChanged(*arg, **karg):\n" - " print ('Caught signal (in catchSystemPropertyChanged handler) ') \n" - " print (arg[0])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchSystemPropertyChanged, signal_name='SystemPropertyChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - ASSERT_EQ(line.compare("dbus.Struct((dbus.Int16(0), dbus.Int16(355)), signature=None)"), 0); - } - ifs.close(); - - //ok, now we want to test the signals. It did not work out that the python receiver worked in an own thread (as originally intended) - //so it is running in the main context and the signals are send from threads... - pthread_create(&pythonloop, NULL, TimingInformationChanged, (void*) NULL); - PyRun_SimpleStringFlags("import sys\n" - "import traceback\n" - "import gobject\n" - "import dbus\n" - "import dbus.mainloop.glib\n" - "loop = gobject.MainLoop()\n" - "def catchTimingInformationChanged(*arg, **karg):\n" - " print ('Caught signal (in catchTimingInformationChanged handler) ') \n" - " print (arg[0])\n" - " print (arg[1])\n" - " f = open('/tmp/result.txt','w')\n" - " f.write(str(arg[0]) + '\\n' + str (arg[1]));\n" - " f.close()\n" - " loop.quit()\n" - "dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)\n" - "bus = dbus.SessionBus()\n" - "bus.add_signal_receiver(catchTimingInformationChanged, signal_name='TimingInformationChanged', dbus_interface = 'org.genivi.audiomanager', message_keyword='dbus_message')\n" - "loop.run()\n", NULL); - pthread_join(pythonloop, NULL); - - ifs.open("/tmp/result.txt"); - lineCounter = 0; - result = 0; - while (std::getline(ifs, line)) - { - if (lineCounter == 0) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 42); - } - else if (lineCounter == 1) - { - std::stringstream(line) >> result; - ASSERT_EQ(result, 233); - } - lineCounter++; - } - ifs.close(); - -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -void dbuscommaninterfacesignalsTest::SetUp() -{ - Py_Initialize(); -} - -void dbuscommaninterfacesignalsTest::TearDown() -{ - Py_Finalize(); -} - diff --git a/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.h b/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.h deleted file mode 100644 index 0f930d6..0000000 --- a/PluginCommandInterfaceDbus/test/dbuscommaninterfacesignalsTest.h +++ /dev/null @@ -1,53 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file dbuscommandinterfacesignalsTest.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN -*/ - -#ifndef DBUSCOMMANINTERFACESIGNALSTEST_H_ -#define DBUSCOMMANINTERFACESIGNALSTEST_H_ -#include -#include -#include -#include -#include -#include -#include "CommandReceiver.h" -#include "CommandSender.h" -#include "MockInterfaces.h" - -#define UNIT_TEST 1 - -namespace am { - -class dbuscommaninterfacesignalsTest: public ::testing::Test -{ -public: - dbuscommaninterfacesignalsTest(); - virtual ~dbuscommaninterfacesignalsTest(); - void SetUp(); - void TearDown(); -}; - -} - -#endif /* DBUSCOMMANINTERFACESIGNALSTEST_H_ */ diff --git a/PluginControlInterface/CMakeLists.txt b/PluginControlInterface/CMakeLists.txt index 5946df7..7701364 100644 --- a/PluginControlInterface/CMakeLists.txt +++ b/PluginControlInterface/CMakeLists.txt @@ -4,9 +4,9 @@ PROJECT(PluginControlInterface) set(LIBRARY_OUTPUT_PATH ${PLUGINS_OUTPUT_PATH}/control) set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/ControlPlugin) -set(INCLUDES_FOLDER "include") +set(include_FOLDER "include") -FILE(READ "${AUDIO_INCLUDES_FOLDER}/control/ControlSendInterface.h" VERSION_BUFFER LIMIT 6000) +FILE(READ "${AUDIO_include_FOLDER}/control/IAmControlSend.h" VERSION_BUFFER LIMIT 6000) STRING(REGEX MATCH "ControlSendVersion*.[^0-9]*[0-9].[0-9]*[0-9]" LIB_INTERFACE_VERSION_STRING ${VERSION_BUFFER}) STRING(REGEX REPLACE "ControlSendVersion*.." "" LIB_INTERFACE_VERSION ${LIB_INTERFACE_VERSION_STRING}) MESSAGE(STATUS "Building against control interface version ${LIB_INTERFACE_VERSION}") @@ -15,8 +15,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${STD_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} + ${include_FOLDER} ) # all source files go here diff --git a/PluginControlInterface/include/CAmControlSenderBase.h b/PluginControlInterface/include/CAmControlSenderBase.h new file mode 100644 index 0000000..3d06356 --- /dev/null +++ b/PluginControlInterface/include/CAmControlSenderBase.h @@ -0,0 +1,165 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmControlSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef CONTROLSENDER_H_ +#define CONTROLSENDER_H_ + +#include "control/IAmControlSend.h" +#include + +using namespace am; + +class CAmControlSenderBase: public IAmControlSend +{ +public: + CAmControlSenderBase(); + virtual ~CAmControlSenderBase(); + am_Error_e startupController(IAmControlReceive* controlreceiveinterface); + void setControllerReady(); + void setControllerRundown(); + am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID); + am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID); + am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); + am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); + am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property); + am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume); + am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment); + am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState); + am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID); + am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID); + void hookSystemDomainRegistrationComplete(const am_domainID_t domainID); + am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID); + am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID); + am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID); + am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID); + am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); + am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID); + am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); + am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID); + void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); + void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); + void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); + void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability); + void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability); + void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state); + void hookSystemReceiveEarlyData(const std::vector& data); + void hookSystemSpeedChange(const am_speed_t speed); + void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); + void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID); + void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID); + void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error); + void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); + void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error); + void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error); + void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error); + void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); + void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); + void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); + am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats); + void getInterfaceVersion(std::string& version) const; + void confirmCommandReady(); + void confirmRoutingReady(); + void confirmCommandRundown(); + void confirmRoutingRundown(); + +private: + IAmControlReceive * mControlReceiveInterface; + struct handleStatus + { + bool status; + am_Handle_s handle; + }; + + struct mainConnectionSet + { + am_mainConnectionID_t connectionID; + std::vector listHandleStaus; + }; + + struct mainVolumeSet + { + am_sinkID_t sinkID; + am_Handle_s handle; + am_mainVolume_t mainVolume; + }; + + struct mainSinkSoundPropertySet + { + am_sinkID_t sinkID; + am_Handle_s handle; + am_MainSoundProperty_s mainSoundProperty; + }; + + class findHandle + { + handleStatus mHandle; + public: + explicit findHandle(handleStatus handle) : + mHandle(handle) + { + } + bool operator()(const handleStatus& handle) const + { + return (handle.handle.handle == mHandle.handle.handle); + } + }; + + struct checkHandle + { + + handleStatus mHandleStatus; + explicit checkHandle(const handleStatus& value) : + mHandleStatus(value) + { + } + + bool operator()(const handleStatus &value) + { + return !value.status; + } + }; + + struct checkMainConnectionID + { + am_MainConnection_s mMainConnection; + explicit checkMainConnectionID(const am_MainConnection_s& mainConnection) : + mMainConnection(mainConnection) + { + } + bool operator()(const am_MainConnection_s& mainConnection) + { + if (mMainConnection.mainConnectionID == mainConnection.mainConnectionID) + return true; + return false; + } + }; + + std::vector mListOpenConnections; + std::vector mListOpenDisconnections; + std::vector mListOpenVolumeChanges; + std::vector mListMainSoundPropertyChanges; +}; + +#endif /* CONTROLSENDER_H_ */ diff --git a/PluginControlInterface/include/ControlSender.h b/PluginControlInterface/include/ControlSender.h deleted file mode 100644 index e96f445..0000000 --- a/PluginControlInterface/include/ControlSender.h +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file ControlSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef CONTROLSENDER_H_ -#define CONTROLSENDER_H_ - -#include -#include - -using namespace am; - -class ControlSenderPlugin: public ControlSendInterface -{ -public: - ControlSenderPlugin(); - virtual ~ControlSenderPlugin(); - am_Error_e startupController(ControlReceiveInterface* controlreceiveinterface); - void setControllerReady(); - void setControllerRundown(); - am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID); - am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID); - am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); - am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); - am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property); - am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume); - am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment); - am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState); - am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID); - am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID); - void hookSystemDomainRegistrationComplete(const am_domainID_t domainID); - am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID); - am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID); - am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); - am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID); - am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); - am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID); - void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); - void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); - void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); - void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability); - void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability); - void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state); - void hookSystemReceiveEarlyData(const std::vector& data); - void hookSystemSpeedChange(const am_speed_t speed); - void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); - void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID); - void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID); - void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error); - void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error); - void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); - am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats); - void getInterfaceVersion(std::string& version) const; - void confirmCommandReady(); - void confirmRoutingReady(); - void confirmCommandRundown(); - void confirmRoutingRundown(); - -private: - ControlReceiveInterface * mControlReceiveInterface; - struct handleStatus - { - bool status; - am_Handle_s handle; - }; - - struct mainConnectionSet - { - am_mainConnectionID_t connectionID; - std::vector listHandleStaus; - }; - - struct mainVolumeSet - { - am_sinkID_t sinkID; - am_Handle_s handle; - am_mainVolume_t mainVolume; - }; - - struct mainSinkSoundPropertySet - { - am_sinkID_t sinkID; - am_Handle_s handle; - am_MainSoundProperty_s mainSoundProperty; - }; - - class findHandle - { - handleStatus mHandle; - public: - explicit findHandle(handleStatus handle) : - mHandle(handle) - { - } - bool operator()(const handleStatus& handle) const - { - return (handle.handle.handle == mHandle.handle.handle); - } - }; - - struct checkHandle - { - - handleStatus mHandleStatus; - explicit checkHandle(const handleStatus& value) : - mHandleStatus(value) - { - } - - bool operator()(const handleStatus &value) - { - return !value.status; - } - }; - - struct checkMainConnectionID - { - am_MainConnection_s mMainConnection; - explicit checkMainConnectionID(const am_MainConnection_s& mainConnection) : - mMainConnection(mainConnection) - { - } - bool operator()(const am_MainConnection_s& mainConnection) - { - if (mMainConnection.mainConnectionID == mainConnection.mainConnectionID) - return true; - return false; - } - }; - - std::vector mListOpenConnections; - std::vector mListOpenDisconnections; - std::vector mListOpenVolumeChanges; - std::vector mListMainSoundPropertyChanges; -}; - -#endif /* CONTROLSENDER_H_ */ diff --git a/PluginControlInterface/src/CAmControlSenderBase.cpp b/PluginControlInterface/src/CAmControlSenderBase.cpp new file mode 100644 index 0000000..9538ca3 --- /dev/null +++ b/PluginControlInterface/src/CAmControlSenderBase.cpp @@ -0,0 +1,477 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmControlSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmControlSenderBase.h" +#include +#include +#include "shared/CAmDltWrapper.h" +#include "control/IAmControlReceive.h" + +using namespace am; + +extern "C" IAmControlSend* PluginControlInterfaceFactory() +{ + return (new CAmControlSenderBase()); +} + +extern "C" void destroyControlPluginInterface(IAmControlSend* controlSendInterface) +{ + delete controlSendInterface; +} + +CAmControlSenderBase::CAmControlSenderBase() : + mControlReceiveInterface(NULL), // + mListOpenConnections(), // + mListOpenDisconnections(), // + mListOpenVolumeChanges() +{ +} + +CAmControlSenderBase::~CAmControlSenderBase() +{ +} + +am_Error_e CAmControlSenderBase::startupController(IAmControlReceive *controlreceiveinterface) +{ + assert(controlreceiveinterface); + mControlReceiveInterface = controlreceiveinterface; + //here is a good place to insert SystemProperties into the database... + //and might be a good place to insert the Source and Sink CLasses as well + return E_NOT_USED; +} + +void CAmControlSenderBase::setControllerReady() +{ + //here is a good place to insert Source and SinkClasses into the database... + mControlReceiveInterface->setRoutingReady(); + mControlReceiveInterface->setCommandReady(); +} + +am_Error_e CAmControlSenderBase::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) +{ + std::vector listRoutes; + std::vector listConnectionIDs; + am_Handle_s handle; + mControlReceiveInterface->getRoute(true, sourceID, sinkID, listRoutes); + if (listRoutes.empty()) + return E_NOT_POSSIBLE; + + std::vector listHandleStaus; + std::vector::iterator it(listRoutes[0].route.begin()); + for (; it != listRoutes[0].route.end(); ++it) + { + am_connectionID_t connectionID; + mControlReceiveInterface->connect(handle, connectionID, it->connectionFormat, it->sourceID, it->sinkID); + handleStatus status; + status.handle = handle; + status.status = false; + listHandleStaus.push_back(status); + listConnectionIDs.push_back(connectionID); + } + am_MainConnection_s mainConnectionData; + mainConnectionData.mainConnectionID = 0; + mainConnectionData.connectionState = CS_CONNECTING; + mainConnectionData.delay = 0; + mainConnectionData.listConnectionID = listConnectionIDs; + mControlReceiveInterface->enterMainConnectionDB(mainConnectionData, mainConnectionID); + mainConnectionSet set; + set.connectionID = mainConnectionID; + set.listHandleStaus = listHandleStaus; + mListOpenConnections.push_back(set); + return E_OK; +} + +am_Error_e CAmControlSenderBase::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) +{ + //first check if there is a connectionID like that + am_MainConnection_s mainConnection; + am_Error_e error; + if ((error = mControlReceiveInterface->getMainConnectionInfoDB(connectionID, mainConnection)) != E_OK) + { + return error; + } + + std::vector::iterator it(mainConnection.listConnectionID.begin()); + std::vector listHandleStaus; + for (; it != mainConnection.listConnectionID.end(); ++it) + { + handleStatus status; + status.status = false; + mControlReceiveInterface->disconnect(status.handle, *it); + listHandleStaus.push_back(status); + } + mainConnectionSet set; + set.connectionID = connectionID; + set.listHandleStaus = listHandleStaus; + mListOpenConnections.push_back(set); + return E_OK; +} + +am_Error_e CAmControlSenderBase::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) +{ + if (sinkID == 0) + return E_NON_EXISTENT; + + mainSinkSoundPropertySet set; + set.sinkID = sinkID; + set.mainSoundProperty = soundProperty; + am_SoundProperty_s sp; + //I know this is bad - just for the reference, ok? + sp.type = static_cast(soundProperty.type); + sp.value = soundProperty.value; + am_Error_e error; + if ((error = mControlReceiveInterface->setSinkSoundProperty(set.handle, sinkID, sp)) != E_OK) + { + return error; + } + mListMainSoundPropertyChanges.push_back(set); + return E_OK; +} + +am_Error_e CAmControlSenderBase::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) +{ + (void) sourceID; + (void) soundProperty; + return E_NOT_USED; +} + +am_Error_e CAmControlSenderBase::hookUserSetSystemProperty(const am_SystemProperty_s & property) +{ + (void) property; + return E_NOT_USED; +} + +am_Error_e CAmControlSenderBase::hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) +{ + assert(SinkID!=0); + mainVolumeSet set; + set.sinkID = SinkID; + set.mainVolume = newVolume; + am_Error_e error; + if ((error = mControlReceiveInterface->setSinkVolume(set.handle, SinkID, newVolume, RAMP_GENIVI_DIRECT, 20)) != E_OK) + { + return error; + } + mListOpenVolumeChanges.push_back(set); + return E_OK; +} + +am_Error_e CAmControlSenderBase::hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) +{ + assert(SinkID!=0); + mainVolumeSet set; + set.sinkID = SinkID; + am_Error_e error; + am_Sink_s sink; + mControlReceiveInterface->getSinkInfoDB(SinkID, sink); + set.mainVolume = sink.volume + increment; + if ((error = mControlReceiveInterface->setSinkVolume(set.handle, SinkID, set.mainVolume, RAMP_GENIVI_DIRECT, 20)) != E_OK) + { + return error; + } + mListOpenVolumeChanges.push_back(set); + return E_OK; +} + +am_Error_e CAmControlSenderBase::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + (void) sinkID; + (void) muteState; + return E_NOT_USED; +} + +am_Error_e CAmControlSenderBase::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->enterDomainDB(domainData, domainID); +} + +am_Error_e CAmControlSenderBase::hookSystemDeregisterDomain(const am_domainID_t domainID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->removeDomainDB(domainID); +} + +void CAmControlSenderBase::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) +{ + (void) domainID; +} + +am_Error_e CAmControlSenderBase::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->enterSinkDB(sinkData, sinkID); +} + +am_Error_e CAmControlSenderBase::hookSystemDeregisterSink(const am_sinkID_t sinkID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->removeSinkDB(sinkID); +} + +am_Error_e CAmControlSenderBase::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->enterSourceDB(sourceData, sourceID); +} + +am_Error_e CAmControlSenderBase::hookSystemDeregisterSource(const am_sourceID_t sourceID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->removeSourceDB(sourceID); +} + +am_Error_e CAmControlSenderBase::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->enterGatewayDB(gatewayData, gatewayID); +} + +am_Error_e CAmControlSenderBase::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->removeGatewayDB(gatewayID); +} + +am_Error_e CAmControlSenderBase::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->enterCrossfaderDB(crossfaderData, crossfaderID); +} + +am_Error_e CAmControlSenderBase::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) +{ + //this application does not do anything with it -> but some product might want to take influence here + return mControlReceiveInterface->removeCrossfaderDB(crossfaderID); +} + +void CAmControlSenderBase::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + (void) handle; + (void) sinkID; + (void) volume; +} + +void CAmControlSenderBase::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + (void) handle; + (void) sourceID; + (void) volume; +} + +void CAmControlSenderBase::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + (void) sourceID; + (void) interruptState; +} + +void CAmControlSenderBase::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + (void) sinkID; + (void) availability; +} + +void CAmControlSenderBase::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + (void) sourceID; + (void) availability; +} + +void CAmControlSenderBase::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) +{ + (void) domainID; + (void) state; +} + +void CAmControlSenderBase::hookSystemReceiveEarlyData(const std::vector & data) +{ + (void) data; +} + +void CAmControlSenderBase::hookSystemSpeedChange(const am_speed_t speed) +{ + (void) speed; +} + +void CAmControlSenderBase::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) +{ + (void) mainConnectionID; + (void) time; +} + +void CAmControlSenderBase::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) +{ + (void) errorID; + //\todo:error checking + std::vector::iterator it(mListOpenConnections.begin()); + for (; it != mListOpenConnections.end(); ++it) + { + std::vector::iterator hit; + handleStatus status; + status.status = true; + status.handle = handle; + hit = std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), findHandle(status)); + if (hit == it->listHandleStaus.end()) + continue; + hit->status = true; + if (it->listHandleStaus.end() == std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), checkHandle(status))) + { + mControlReceiveInterface->changeMainConnectionStateDB(it->connectionID, CS_CONNECTED); + mListOpenConnections.erase(it); + break; + } + } +} + +void CAmControlSenderBase::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) +{ + (void) errorID; + //\todo:error checking + std::vector::iterator it(mListOpenDisconnections.begin()); + for (; it != mListOpenDisconnections.end(); ++it) + { + std::vector::iterator hit; + handleStatus status; + status.status = true; + status.handle = handle; + hit = std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), findHandle(status)); + if (hit == it->listHandleStaus.end()) + continue; + hit->status = true; + if (it->listHandleStaus.end() == std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), checkHandle(status))) + { + mControlReceiveInterface->removeMainConnectionDB(it->connectionID); + mListOpenDisconnections.erase(it); + break; + } + } +} + +void CAmControlSenderBase::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) +{ + (void) handle; + (void) hostsink; + (void) error; +} + +void CAmControlSenderBase::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + (void) error; + (void) volume; + //\todo:error checking + std::vector::iterator it(mListOpenVolumeChanges.begin()); + for (; it != mListOpenVolumeChanges.end(); ++it) + { + if (handle.handle == it->handle.handle) + { + mControlReceiveInterface->changeSinkMainVolumeDB(it->mainVolume, it->sinkID); + } + } +} + +void CAmControlSenderBase::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) +{ + (void) error; + (void) voulme; + (void) handle; +} + +void CAmControlSenderBase::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + (void) error; + (void) handle; +} + +void CAmControlSenderBase::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + (void) error; + (void) handle; +} + +void CAmControlSenderBase::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + (void) error; + //\todo:error checking + std::vector::iterator it(mListMainSoundPropertyChanges.begin()); + for (; it != mListMainSoundPropertyChanges.end(); ++it) + { + if (handle.handle == it->handle.handle) + { + mControlReceiveInterface->changeMainSinkSoundPropertyDB(it->mainSoundProperty, it->sinkID); + } + } +} + +void CAmControlSenderBase::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + (void) error; + (void) handle; +} + +void CAmControlSenderBase::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + (void) error; + (void) handle; +} + +void CAmControlSenderBase::setControllerRundown() +{ +} + +am_Error_e CAmControlSenderBase::getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector & listPrioConnectionFormats) +{ + (void) sourceID; + (void) sinkID; + (void) listRoute; + //ok, this is cheap. In a real product you have your preferences, right? + listPrioConnectionFormats = listPossibleConnectionFormats; + return (E_OK); +} + +void CAmControlSenderBase::getInterfaceVersion(std::string & version) const +{ + version = ControlSendVersion; +} + +void CAmControlSenderBase::confirmCommandReady() +{ + logInfo("ControlSenderPlugin got Routing Ready confirmed"); +} + +void CAmControlSenderBase::confirmRoutingReady() +{ + logInfo("ControlSenderPlugin got Command Ready confirmed"); +} + +void CAmControlSenderBase::confirmCommandRundown() +{ + logInfo("ControlSenderPlugin got Routing Rundown confirmed"); +} + +void CAmControlSenderBase::confirmRoutingRundown() +{ + logInfo("ControlSenderPlugin got Command Rundown confirmed"); +} + diff --git a/PluginControlInterface/src/ControlSender.cpp b/PluginControlInterface/src/ControlSender.cpp deleted file mode 100644 index 567f8c6..0000000 --- a/PluginControlInterface/src/ControlSender.cpp +++ /dev/null @@ -1,477 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file ControlSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "ControlSender.h" -#include "control/ControlReceiveInterface.h" -#include -#include -#include "DLTWrapper.h" - -using namespace am; - -extern "C" ControlSendInterface* PluginControlInterfaceFactory() -{ - return (new ControlSenderPlugin()); -} - -extern "C" void destroyControlPluginInterface(ControlSendInterface* controlSendInterface) -{ - delete controlSendInterface; -} - -ControlSenderPlugin::ControlSenderPlugin() : - mControlReceiveInterface(NULL), // - mListOpenConnections(), // - mListOpenDisconnections(), // - mListOpenVolumeChanges() -{ -} - -ControlSenderPlugin::~ControlSenderPlugin() -{ -} - -am_Error_e ControlSenderPlugin::startupController(ControlReceiveInterface *controlreceiveinterface) -{ - assert(controlreceiveinterface); - mControlReceiveInterface = controlreceiveinterface; - //here is a good place to insert SystemProperties into the database... - //and might be a good place to insert the Source and Sink CLasses as well - return E_NOT_USED; -} - -void ControlSenderPlugin::setControllerReady() -{ - //here is a good place to insert Source and SinkClasses into the database... - mControlReceiveInterface->setRoutingReady(); - mControlReceiveInterface->setCommandReady(); -} - -am_Error_e ControlSenderPlugin::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) -{ - std::vector listRoutes; - std::vector listConnectionIDs; - am_Handle_s handle; - mControlReceiveInterface->getRoute(true, sourceID, sinkID, listRoutes); - if (listRoutes.empty()) - return E_NOT_POSSIBLE; - - std::vector listHandleStaus; - std::vector::iterator it(listRoutes[0].route.begin()); - for (; it != listRoutes[0].route.end(); ++it) - { - am_connectionID_t connectionID; - mControlReceiveInterface->connect(handle, connectionID, it->connectionFormat, it->sourceID, it->sinkID); - handleStatus status; - status.handle = handle; - status.status = false; - listHandleStaus.push_back(status); - listConnectionIDs.push_back(connectionID); - } - am_MainConnection_s mainConnectionData; - mainConnectionData.mainConnectionID = 0; - mainConnectionData.connectionState = CS_CONNECTING; - mainConnectionData.delay = 0; - mainConnectionData.listConnectionID = listConnectionIDs; - mControlReceiveInterface->enterMainConnectionDB(mainConnectionData, mainConnectionID); - mainConnectionSet set; - set.connectionID = mainConnectionID; - set.listHandleStaus = listHandleStaus; - mListOpenConnections.push_back(set); - return E_OK; -} - -am_Error_e ControlSenderPlugin::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) -{ - //first check if there is a connectionID like that - am_MainConnection_s mainConnection; - am_Error_e error; - if ((error = mControlReceiveInterface->getMainConnectionInfoDB(connectionID, mainConnection)) != E_OK) - { - return error; - } - - std::vector::iterator it(mainConnection.listConnectionID.begin()); - std::vector listHandleStaus; - for (; it != mainConnection.listConnectionID.end(); ++it) - { - handleStatus status; - status.status = false; - mControlReceiveInterface->disconnect(status.handle, *it); - listHandleStaus.push_back(status); - } - mainConnectionSet set; - set.connectionID = connectionID; - set.listHandleStaus = listHandleStaus; - mListOpenConnections.push_back(set); - return E_OK; -} - -am_Error_e ControlSenderPlugin::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) -{ - if (sinkID == 0) - return E_NON_EXISTENT; - - mainSinkSoundPropertySet set; - set.sinkID = sinkID; - set.mainSoundProperty = soundProperty; - am_SoundProperty_s sp; - //I know this is bad - just for the reference, ok? - sp.type = static_cast(soundProperty.type); - sp.value = soundProperty.value; - am_Error_e error; - if ((error = mControlReceiveInterface->setSinkSoundProperty(set.handle, sinkID, sp)) != E_OK) - { - return error; - } - mListMainSoundPropertyChanges.push_back(set); - return E_OK; -} - -am_Error_e ControlSenderPlugin::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) -{ - (void) sourceID; - (void) soundProperty; - return E_NOT_USED; -} - -am_Error_e ControlSenderPlugin::hookUserSetSystemProperty(const am_SystemProperty_s & property) -{ - (void) property; - return E_NOT_USED; -} - -am_Error_e ControlSenderPlugin::hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) -{ - assert(SinkID!=0); - mainVolumeSet set; - set.sinkID = SinkID; - set.mainVolume = newVolume; - am_Error_e error; - if ((error = mControlReceiveInterface->setSinkVolume(set.handle, SinkID, newVolume, RAMP_GENIVI_DIRECT, 20)) != E_OK) - { - return error; - } - mListOpenVolumeChanges.push_back(set); - return E_OK; -} - -am_Error_e ControlSenderPlugin::hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) -{ - assert(SinkID!=0); - mainVolumeSet set; - set.sinkID = SinkID; - am_Error_e error; - am_Sink_s sink; - mControlReceiveInterface->getSinkInfoDB(SinkID, sink); - set.mainVolume = sink.volume + increment; - if ((error = mControlReceiveInterface->setSinkVolume(set.handle, SinkID, set.mainVolume, RAMP_GENIVI_DIRECT, 20)) != E_OK) - { - return error; - } - mListOpenVolumeChanges.push_back(set); - return E_OK; -} - -am_Error_e ControlSenderPlugin::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - (void) sinkID; - (void) muteState; - return E_NOT_USED; -} - -am_Error_e ControlSenderPlugin::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->enterDomainDB(domainData, domainID); -} - -am_Error_e ControlSenderPlugin::hookSystemDeregisterDomain(const am_domainID_t domainID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->removeDomainDB(domainID); -} - -void ControlSenderPlugin::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) -{ - (void) domainID; -} - -am_Error_e ControlSenderPlugin::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->enterSinkDB(sinkData, sinkID); -} - -am_Error_e ControlSenderPlugin::hookSystemDeregisterSink(const am_sinkID_t sinkID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->removeSinkDB(sinkID); -} - -am_Error_e ControlSenderPlugin::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->enterSourceDB(sourceData, sourceID); -} - -am_Error_e ControlSenderPlugin::hookSystemDeregisterSource(const am_sourceID_t sourceID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->removeSourceDB(sourceID); -} - -am_Error_e ControlSenderPlugin::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->enterGatewayDB(gatewayData, gatewayID); -} - -am_Error_e ControlSenderPlugin::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->removeGatewayDB(gatewayID); -} - -am_Error_e ControlSenderPlugin::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->enterCrossfaderDB(crossfaderData, crossfaderID); -} - -am_Error_e ControlSenderPlugin::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) -{ - //this application does not do anything with it -> but some product might want to take influence here - return mControlReceiveInterface->removeCrossfaderDB(crossfaderID); -} - -void ControlSenderPlugin::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - (void) handle; - (void) sinkID; - (void) volume; -} - -void ControlSenderPlugin::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - (void) handle; - (void) sourceID; - (void) volume; -} - -void ControlSenderPlugin::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - (void) sourceID; - (void) interruptState; -} - -void ControlSenderPlugin::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - (void) sinkID; - (void) availability; -} - -void ControlSenderPlugin::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - (void) sourceID; - (void) availability; -} - -void ControlSenderPlugin::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) -{ - (void) domainID; - (void) state; -} - -void ControlSenderPlugin::hookSystemReceiveEarlyData(const std::vector & data) -{ - (void) data; -} - -void ControlSenderPlugin::hookSystemSpeedChange(const am_speed_t speed) -{ - (void) speed; -} - -void ControlSenderPlugin::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) -{ - (void) mainConnectionID; - (void) time; -} - -void ControlSenderPlugin::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) -{ - (void) errorID; - //\todo:error checking - std::vector::iterator it(mListOpenConnections.begin()); - for (; it != mListOpenConnections.end(); ++it) - { - std::vector::iterator hit; - handleStatus status; - status.status = true; - status.handle = handle; - hit = std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), findHandle(status)); - if (hit == it->listHandleStaus.end()) - continue; - hit->status = true; - if (it->listHandleStaus.end() == std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), checkHandle(status))) - { - mControlReceiveInterface->changeMainConnectionStateDB(it->connectionID, CS_CONNECTED); - mListOpenConnections.erase(it); - break; - } - } -} - -void ControlSenderPlugin::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) -{ - (void) errorID; - //\todo:error checking - std::vector::iterator it(mListOpenDisconnections.begin()); - for (; it != mListOpenDisconnections.end(); ++it) - { - std::vector::iterator hit; - handleStatus status; - status.status = true; - status.handle = handle; - hit = std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), findHandle(status)); - if (hit == it->listHandleStaus.end()) - continue; - hit->status = true; - if (it->listHandleStaus.end() == std::find_if(it->listHandleStaus.begin(), it->listHandleStaus.end(), checkHandle(status))) - { - mControlReceiveInterface->removeMainConnectionDB(it->connectionID); - mListOpenDisconnections.erase(it); - break; - } - } -} - -void ControlSenderPlugin::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) -{ - (void) handle; - (void) hostsink; - (void) error; -} - -void ControlSenderPlugin::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - (void) error; - (void) volume; - //\todo:error checking - std::vector::iterator it(mListOpenVolumeChanges.begin()); - for (; it != mListOpenVolumeChanges.end(); ++it) - { - if (handle.handle == it->handle.handle) - { - mControlReceiveInterface->changeSinkMainVolumeDB(it->mainVolume, it->sinkID); - } - } -} - -void ControlSenderPlugin::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) -{ - (void) error; - (void) voulme; - (void) handle; -} - -void ControlSenderPlugin::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - (void) error; - (void) handle; -} - -void ControlSenderPlugin::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - (void) error; - (void) handle; -} - -void ControlSenderPlugin::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - (void) error; - //\todo:error checking - std::vector::iterator it(mListMainSoundPropertyChanges.begin()); - for (; it != mListMainSoundPropertyChanges.end(); ++it) - { - if (handle.handle == it->handle.handle) - { - mControlReceiveInterface->changeMainSinkSoundPropertyDB(it->mainSoundProperty, it->sinkID); - } - } -} - -void ControlSenderPlugin::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - (void) error; - (void) handle; -} - -void ControlSenderPlugin::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - (void) error; - (void) handle; -} - -void ControlSenderPlugin::setControllerRundown() -{ -} - -am_Error_e ControlSenderPlugin::getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector & listPrioConnectionFormats) -{ - (void) sourceID; - (void) sinkID; - (void) listRoute; - //ok, this is cheap. In a real product you have your preferences, right? - listPrioConnectionFormats = listPossibleConnectionFormats; - return (E_OK); -} - -void ControlSenderPlugin::getInterfaceVersion(std::string & version) const -{ - version = ControlSendVersion; -} - -void ControlSenderPlugin::confirmCommandReady() -{ - logInfo("ControlSenderPlugin got Routing Ready confirmed"); -} - -void ControlSenderPlugin::confirmRoutingReady() -{ - logInfo("ControlSenderPlugin got Command Ready confirmed"); -} - -void ControlSenderPlugin::confirmCommandRundown() -{ - logInfo("ControlSenderPlugin got Routing Rundown confirmed"); -} - -void ControlSenderPlugin::confirmRoutingRundown() -{ - logInfo("ControlSenderPlugin got Command Rundown confirmed"); -} - diff --git a/PluginRoutingInterfaceAsync/CMakeLists.txt b/PluginRoutingInterfaceAsync/CMakeLists.txt index 598b4fe..35f9e7e 100644 --- a/PluginRoutingInterfaceAsync/CMakeLists.txt +++ b/PluginRoutingInterfaceAsync/CMakeLists.txt @@ -26,9 +26,9 @@ PROJECT(PluginRoutingInterfaceAsync) set(LIBRARY_OUTPUT_PATH ${PLUGINS_OUTPUT_PATH}/routing) set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/RoutingAsync) -set(INCLUDES_FOLDER "include") +set(include_FOLDER "include") -FILE(READ "${AUDIO_INCLUDES_FOLDER}/routing/RoutingSendInterface.h" VERSION_BUFFER LIMIT 6000) +FILE(READ "${AUDIO_include_FOLDER}/routing/IAmRoutingSend.h" VERSION_BUFFER LIMIT 6000) STRING(REGEX MATCH "RoutingSendVersion*.[^0-9]*[0-9].[0-9]*[0-9]" LIB_INTERFACE_VERSION_STRING ${VERSION_BUFFER}) STRING(REGEX REPLACE "RoutingSendVersion*.." "" LIB_INTERFACE_VERSION ${LIB_INTERFACE_VERSION_STRING}) MESSAGE(STATUS "Building against routing interface version ${LIB_INTERFACE_VERSION}") @@ -39,8 +39,8 @@ FIND_PACKAGE(DBUS REQUIRED) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} + ${include_FOLDER} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR} ) diff --git a/PluginRoutingInterfaceAsync/include/CAmRoutingSenderAsync.h b/PluginRoutingInterfaceAsync/include/CAmRoutingSenderAsync.h new file mode 100644 index 0000000..377b7c5 --- /dev/null +++ b/PluginRoutingInterfaceAsync/include/CAmRoutingSenderAsync.h @@ -0,0 +1,396 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmRoutingSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef ROUTINGSENDER_H_ +#define ROUTINGSENDER_H_ + +#include "routing/IAmRoutingSend.h" +#include "IAmRoutingReceiverShadow.h" +#include +#include + +namespace am +{ + +class CAmWorkerThreadPool; + +/** + * Base class for workers implements everything that is needed to implement a workerthread + * inherit from this class when adding new workers + */ +class CAmWorker +{ +public: + CAmWorker(CAmWorkerThreadPool* pool); + virtual ~CAmWorker() + {}; + /** + * needs to be overwritten, this function is called when the worker should start to work + */ + void virtual start2work()=0; + + /** + * needs to be overwritten, this function is called when the worker thread is canceled. Should be used for + * clean up and sending important messages + */ + void virtual cancelWork()=0; + /** + * waits for a semaphore with a timeout. This leaves the Threadpool the chance to interrupt the processing + * You should call whenever waiting on some event, even with time=0 in order to make sure that cancel events are + * received + * @param time time until timeout in timespec format + * @return true if thread is canceled. Then just return start2work function so that the thread is given back to the pool + */ + bool timedWait(timespec time); + + /** + * the semaphore for cancellation is set by the thread automatically... + * @param cancel + */ + void setCancelSempaphore(sem_t* cancel); + CAmWorkerThreadPool* pPool; +private: + sem_t* mCancelSem; // mListWorkers; //& listSoundProperties) ; + am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) ; + am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) ; + am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) ; + am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) ; + am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) ; + am_Error_e returnBusName(std::string& BusName) const ; + void getInterfaceVersion(std::string& version) const ; + + /** + * threadafe insert of route and connectionID + * @param connectionID + * @param route + */ + void insertConnectionSafe(am_connectionID_t connectionID, am_RoutingElement_s route); + + /** + * threadsafe removal of a connection + * @param + */ + void removeConnectionSafe(am_connectionID_t); + + /** + * threadsafe remove of a handle + * @param handle + */ + void removeHandleSafe(uint16_t handle); + + /** + * threadsafe update of Sinkvolume + * @param sinkID + * @param volume + */ + void updateSinkVolumeSafe(am_sinkID_t sinkID, am_volume_t volume); + + /** + * threadsafe update of SourceVolume + * @param sourceID + * @param volume + */ + void updateSourceVolumeSafe(am_sourceID_t sourceID, am_volume_t volume); + + /** + * threadsafe update of sourceState + * @param sourceID + * @param state + */ + void updateSourceStateSafe(am_sourceID_t sourceID, am_SourceState_e state); + + /** + * threadsafe update of sinkSoundProperty + * @param sinkID + * @param soundProperty + */ + void updateSinkSoundPropertySafe(am_sinkID_t sinkID, am_SoundProperty_s soundProperty); + + /** + * threadsafe update of sourceSoundProperty + * @param sourceID + * @param soundProperty + */ + void updateSourceSoundPropertySafe(am_sourceID_t sourceID, am_SoundProperty_s soundProperty); + + /** + * threadsafe update of domainstate + * @param domainID + * @param domainState + */ + void updateDomainstateSafe(am_domainID_t domainID, am_DomainState_e domainState); + + void updateDomainListSafe(std::vector listDomains); + + void updateSourceListSafe(std::vector listSource); + + void updateSinkListSafe(std::vector listSinks); + +private: + /** + * Extra thread that handles dbus stimulation for interrupt tests + * This is a very very very basic implementation of the dbus interface + * there is not failure handling, nothing. + * it is used just for testing, not intended to be used otherwise... + * @param data + */ + std::vector createDomainTable(); + std::vector createSinkTable(); + std::vector createSourceTable(); + std::vector createGatewayTable(); + IAmRoutingReceiverShadow* mShadow; + IAmRoutingReceive* mReceiveInterface; + CAmSocketHandler *mSocketHandler; + std::vector mDomains; + std::vector mSinks; + std::vector mSources; + std::vector mGateways; + std::map mMapHandleWorker; + std::map mMapConnectionIDRoute; + CAmWorkerThreadPool mPool; + pthread_t mInterruptThread; + static pthread_mutex_t mMapConnectionMutex; + static pthread_mutex_t mMapHandleWorkerMutex; + static pthread_mutex_t mSinksMutex; + static pthread_mutex_t mSourcesMutex; + static pthread_mutex_t mDomainsMutex; +}; + +/** + * worker to for connection + */ +class asycConnectWorker: public CAmWorker +{ +public: + asycConnectWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_Handle_s mHandle; + am_connectionID_t mConnectionID; + am_sourceID_t mSourceID; + am_sinkID_t mSinkID; + am_ConnectionFormat_e mConnectionFormat; +}; + +/** + * worker for disconnecting + */ +class asycDisConnectWorker: public CAmWorker +{ +public: + asycDisConnectWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_Handle_s mHandle; + am_connectionID_t mConnectionID; + am_ConnectionFormat_e mConnectionFormat; +}; + +/** + * worker to for connection + */ + +#include +#include +#include + +class asyncSetSinkVolumeWorker: public CAmWorker +{ +public: + asyncSetSinkVolumeWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_volume_t mCurrentVolume; + am_Handle_s mHandle; + am_sinkID_t mSinkID; + am_volume_t mVolume; + am_RampType_e mRamp; + am_time_t mTime; +}; + +class asyncSetSourceVolumeWorker: public CAmWorker +{ +public: + asyncSetSourceVolumeWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sourceID_t SourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_volume_t mCurrentVolume; + am_Handle_s mHandle; + am_sourceID_t mSourceID; + am_volume_t mVolume; + am_RampType_e mRamp; + am_time_t mTime; +}; + +class asyncSetSourceStateWorker: public CAmWorker +{ +public: + asyncSetSourceStateWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_Handle_s mHandle; + am_sourceID_t mSourceID; + am_SourceState_e mSourcestate; +}; + +class asyncSetSinkSoundPropertyWorker: public CAmWorker +{ +public: + asyncSetSinkSoundPropertyWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sinkID_t sinkID); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_Handle_s mHandle; + am_sinkID_t mSinkID; + am_SoundProperty_s mSoundProperty; +}; + +class asyncSetSourceSoundPropertyWorker: public CAmWorker +{ +public: + asyncSetSourceSoundPropertyWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sourceID_t sourceID); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_Handle_s mHandle; + am_sourceID_t mSourceID; + am_SoundProperty_s mSoundProperty; +}; + +class asyncDomainStateChangeWorker: public CAmWorker +{ +public: + asyncDomainStateChangeWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const am_domainID_t domainID, const am_DomainState_e domainState); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + am_domainID_t mDomainID; + am_DomainState_e mDomainState; +}; + +class syncRegisterWorker: public CAmWorker +{ +public: + syncRegisterWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const std::vector domains, const std::vector sinks, const std::vector sources, const uint16_t handle); + void start2work(); + void cancelWork(); +private: + CAmRoutingSenderAsync * mAsyncSender; + IAmRoutingReceiverShadow *mShadow; + std::vector mListDomains; + std::vector mListSinks; + std::vector mListSources; + uint16_t mHandle; +}; + +} + +#endif /* ROUTINGSENDER_H_ */ diff --git a/PluginRoutingInterfaceAsync/include/IAmRoutingReceiverShadow.h b/PluginRoutingInterfaceAsync/include/IAmRoutingReceiverShadow.h new file mode 100644 index 0000000..af4685c --- /dev/null +++ b/PluginRoutingInterfaceAsync/include/IAmRoutingReceiverShadow.h @@ -0,0 +1,79 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file testRoutingItnerfaceAsync.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef ROUTINGRECEIVERASYNCSHADOW_H_ +#define ROUTINGRECEIVERASYNCSHADOW_H_ + +#include "routing/IAmRoutingReceive.h" +#include +#include +#include "shared/CAmSerializer.h" +#include "shared/CAmSocketHandler.h" + +namespace am +{ + +/** + * Threadsafe shadow of the RoutingReceiverInterface + * Register and deregister Functions are sychronous so they do not show up here... + */ +class IAmRoutingReceiverShadow +{ +public: + IAmRoutingReceiverShadow(IAmRoutingReceive* iReceiveInterface,CAmSocketHandler* iSocketHandler); + virtual ~IAmRoutingReceiverShadow(); + void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); + void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); + void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); + void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); + void ackSetSourceState(const am_Handle_s handle, const am_Error_e error); + void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); + void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); + void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error); + void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); + void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); + void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); + void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); + void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability); + void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState); + void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay); + am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID) ; + am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ; + am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) ; + am_Error_e deregisterSink(const am_sinkID_t sinkID) ; + am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ; + am_Error_e deregisterSource(const am_sourceID_t sourceID) ; + am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ; + void confirmRoutingReady(uint16_t starupHandle); + void confirmRoutingRundown(uint16_t rundownHandle); + +private: + + CAmSocketHandler *mSocketHandler; + IAmRoutingReceive *mRoutingReceiveInterface; + CAmSerializer mSerializer; +}; + +} /* namespace am */ +#endif /* ROUTINGRECEIVERASYNCSHADOW_H_ */ diff --git a/PluginRoutingInterfaceAsync/include/RoutingReceiverAsyncShadow.h b/PluginRoutingInterfaceAsync/include/RoutingReceiverAsyncShadow.h deleted file mode 100644 index bf5a5ed..0000000 --- a/PluginRoutingInterfaceAsync/include/RoutingReceiverAsyncShadow.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file testRoutingItnerfaceAsync.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef ROUTINGRECEIVERASYNCSHADOW_H_ -#define ROUTINGRECEIVERASYNCSHADOW_H_ - -#include -#include -#include -#include -#include "CAmSerializer.h" - -namespace am -{ - -/** - * Threadsafe shadow of the RoutingReceiverInterface - * Register and deregister Functions are sychronous so they do not show up here... - */ -class RoutingReceiverAsyncShadow -{ -public: - RoutingReceiverAsyncShadow(RoutingReceiveInterface* iReceiveInterface,SocketHandler* iSocketHandler); - virtual ~RoutingReceiverAsyncShadow(); - void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); - void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error); - void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void ackSetSourceState(const am_Handle_s handle, const am_Error_e error); - void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); - void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); - void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error); - void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); - void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); - void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); - void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); - void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability); - void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState); - void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay); - am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID) ; - am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ; - am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) ; - am_Error_e deregisterSink(const am_sinkID_t sinkID) ; - am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ; - am_Error_e deregisterSource(const am_sourceID_t sourceID) ; - am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ; - void confirmRoutingReady(uint16_t starupHandle); - -private: - - SocketHandler *mSocketHandler; - RoutingReceiveInterface *mRoutingReceiveInterface; - CAmSerializer mSerializer; -}; - -} /* namespace am */ -#endif /* ROUTINGRECEIVERASYNCSHADOW_H_ */ diff --git a/PluginRoutingInterfaceAsync/include/RoutingSenderAsyn.h b/PluginRoutingInterfaceAsync/include/RoutingSenderAsyn.h deleted file mode 100644 index 96e1b5c..0000000 --- a/PluginRoutingInterfaceAsync/include/RoutingSenderAsyn.h +++ /dev/null @@ -1,398 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file RoutingSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef ROUTINGSENDER_H_ -#define ROUTINGSENDER_H_ - -#include -#include "RoutingReceiverAsyncShadow.h" -#include -#include - -namespace am -{ - -class WorkerThreadPool; - -/** - * Base class for workers implements everything that is needed to implement a workerthread - * inherit from this class when adding new workers - */ -class Worker -{ -public: - Worker(WorkerThreadPool* pool); - virtual ~Worker() - { - } - ; - /** - * needs to be overwritten, this function is called when the worker should start to work - */ - void virtual start2work()=0; - - /** - * needs to be overwritten, this function is called when the worker thread is canceled. Should be used for - * clean up and sending important messages - */ - void virtual cancelWork()=0; - /** - * waits for a semaphore with a timeout. This leaves the Threadpool the chance to interrupt the processing - * You should call whenever waiting on some event, even with time=0 in order to make sure that cancel events are - * received - * @param time time until timeout in timespec format - * @return true if thread is canceled. Then just return start2work function so that the thread is given back to the pool - */ - bool timedWait(timespec time); - - /** - * the semaphore for cancellation is set by the thread automatically... - * @param cancel - */ - void setCancelSempaphore(sem_t* cancel); - WorkerThreadPool* pPool; -private: - sem_t* mCancelSem; // mListWorkers; //& listSoundProperties) ; - am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) ; - am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) ; - am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) ; - am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) ; - am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) ; - am_Error_e returnBusName(std::string& BusName) const ; - void getInterfaceVersion(std::string& version) const ; - - /** - * threadafe insert of route and connectionID - * @param connectionID - * @param route - */ - void insertConnectionSafe(am_connectionID_t connectionID, am_RoutingElement_s route); - - /** - * threadsafe removal of a connection - * @param - */ - void removeConnectionSafe(am_connectionID_t); - - /** - * threadsafe remove of a handle - * @param handle - */ - void removeHandleSafe(uint16_t handle); - - /** - * threadsafe update of Sinkvolume - * @param sinkID - * @param volume - */ - void updateSinkVolumeSafe(am_sinkID_t sinkID, am_volume_t volume); - - /** - * threadsafe update of SourceVolume - * @param sourceID - * @param volume - */ - void updateSourceVolumeSafe(am_sourceID_t sourceID, am_volume_t volume); - - /** - * threadsafe update of sourceState - * @param sourceID - * @param state - */ - void updateSourceStateSafe(am_sourceID_t sourceID, am_SourceState_e state); - - /** - * threadsafe update of sinkSoundProperty - * @param sinkID - * @param soundProperty - */ - void updateSinkSoundPropertySafe(am_sinkID_t sinkID, am_SoundProperty_s soundProperty); - - /** - * threadsafe update of sourceSoundProperty - * @param sourceID - * @param soundProperty - */ - void updateSourceSoundPropertySafe(am_sourceID_t sourceID, am_SoundProperty_s soundProperty); - - /** - * threadsafe update of domainstate - * @param domainID - * @param domainState - */ - void updateDomainstateSafe(am_domainID_t domainID, am_DomainState_e domainState); - - void updateDomainListSafe(std::vector listDomains); - - void updateSourceListSafe(std::vector listSource); - - void updateSinkListSafe(std::vector listSinks); - -private: - /** - * Extra thread that handles dbus stimulation for interrupt tests - * This is a very very very basic implementation of the dbus interface - * there is not failure handling, nothing. - * it is used just for testing, not intended to be used otherwise... - * @param data - */ - std::vector createDomainTable(); - std::vector createSinkTable(); - std::vector createSourceTable(); - std::vector createGatewayTable(); - RoutingReceiverAsyncShadow* mShadow; - RoutingReceiveInterface* mReceiveInterface; - SocketHandler *mSocketHandler; - std::vector mDomains; - std::vector mSinks; - std::vector mSources; - std::vector mGateways; - std::map mMapHandleWorker; - std::map mMapConnectionIDRoute; - WorkerThreadPool mPool; - pthread_t mInterruptThread; - static pthread_mutex_t mMapConnectionMutex; - static pthread_mutex_t mMapHandleWorkerMutex; - static pthread_mutex_t mSinksMutex; - static pthread_mutex_t mSourcesMutex; - static pthread_mutex_t mDomainsMutex; -}; - -/** - * worker to for connection - */ -class asycConnectWorker: public Worker -{ -public: - asycConnectWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_Handle_s mHandle; - am_connectionID_t mConnectionID; - am_sourceID_t mSourceID; - am_sinkID_t mSinkID; - am_ConnectionFormat_e mConnectionFormat; -}; - -/** - * worker for disconnecting - */ -class asycDisConnectWorker: public Worker -{ -public: - asycDisConnectWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_Handle_s mHandle; - am_connectionID_t mConnectionID; - am_ConnectionFormat_e mConnectionFormat; -}; - -/** - * worker to for connection - */ - -#include -#include -#include - -class asyncSetSinkVolumeWorker: public Worker -{ -public: - asyncSetSinkVolumeWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_volume_t mCurrentVolume; - am_Handle_s mHandle; - am_sinkID_t mSinkID; - am_volume_t mVolume; - am_RampType_e mRamp; - am_time_t mTime; -}; - -class asyncSetSourceVolumeWorker: public Worker -{ -public: - asyncSetSourceVolumeWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sourceID_t SourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_volume_t mCurrentVolume; - am_Handle_s mHandle; - am_sourceID_t mSourceID; - am_volume_t mVolume; - am_RampType_e mRamp; - am_time_t mTime; -}; - -class asyncSetSourceStateWorker: public Worker -{ -public: - asyncSetSourceStateWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_Handle_s mHandle; - am_sourceID_t mSourceID; - am_SourceState_e mSourcestate; -}; - -class asyncSetSinkSoundPropertyWorker: public Worker -{ -public: - asyncSetSinkSoundPropertyWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sinkID_t sinkID); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_Handle_s mHandle; - am_sinkID_t mSinkID; - am_SoundProperty_s mSoundProperty; -}; - -class asyncSetSourceSoundPropertyWorker: public Worker -{ -public: - asyncSetSourceSoundPropertyWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sourceID_t sourceID); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_Handle_s mHandle; - am_sourceID_t mSourceID; - am_SoundProperty_s mSoundProperty; -}; - -class asyncDomainStateChangeWorker: public Worker -{ -public: - asyncDomainStateChangeWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_domainID_t domainID, const am_DomainState_e domainState); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - am_domainID_t mDomainID; - am_DomainState_e mDomainState; -}; - -class syncRegisterWorker: public Worker -{ -public: - syncRegisterWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const std::vector domains, const std::vector sinks, const std::vector sources, const uint16_t handle); - void start2work(); - void cancelWork(); -private: - AsyncRoutingSender * mAsyncSender; - RoutingReceiverAsyncShadow *mShadow; - std::vector mListDomains; - std::vector mListSinks; - std::vector mListSources; - uint16_t mHandle; -}; - -} - -#endif /* ROUTINGSENDER_H_ */ diff --git a/PluginRoutingInterfaceAsync/src/CAmRoutingSenderAsync.cpp b/PluginRoutingInterfaceAsync/src/CAmRoutingSenderAsync.cpp new file mode 100644 index 0000000..31e5948 --- /dev/null +++ b/PluginRoutingInterfaceAsync/src/CAmRoutingSenderAsync.cpp @@ -0,0 +1,1294 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmRoutingSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmRoutingSenderAsync.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" + +using namespace am; + +DLT_DECLARE_CONTEXT(PluginRoutingAsync) + +extern "C" IAmRoutingSend* PluginRoutingInterfaceAsyncFactory() +{ + return (new CAmRoutingSenderAsync()); +} + +extern "C" void destroyRoutingPluginInterfaceAsync(IAmRoutingSend* routingSendInterface) +{ + delete routingSendInterface; +} + +pthread_mutex_t CAmRoutingSenderAsync::mMapConnectionMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t CAmRoutingSenderAsync::mMapHandleWorkerMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t CAmRoutingSenderAsync::mSinksMutex= PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t CAmRoutingSenderAsync::mSourcesMutex= PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t CAmRoutingSenderAsync::mDomainsMutex= PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t CAmWorkerThreadPool::mBlockingMutex = PTHREAD_MUTEX_INITIALIZER; + +void *CAmWorkerThreadPool::CAmWorkerThread(void* data) +{ + threadInfo_s *myInfo=(threadInfo_s*)data; + while (1) + { + sem_wait(&myInfo->block); + pthread_mutex_lock(&mBlockingMutex); + CAmWorker* actWorker=myInfo->worker; + pthread_mutex_unlock(&mBlockingMutex); + actWorker->setCancelSempaphore(&myInfo->cancel); + actWorker->start2work(); + actWorker->pPool->finishedWork(myInfo->threadID); + } + return NULL; +} + +CAmWorkerThreadPool::CAmWorkerThreadPool(int numThreads): +mNumThreads(numThreads) +{ + int workerID=0; + mListWorkers.resize(mNumThreads); + for (int i=0;i::iterator it=mListWorkers.begin(); + for(;it!=mListWorkers.end();++it) + { + if(!it->busy) + { + it->worker=worker; + it->busy=true; + pthread_mutex_unlock(&mBlockingMutex); + sem_post(&it->block); + return ((int)it->workerID); + } + } + pthread_mutex_unlock(&mBlockingMutex); + return (-1); +} + +bool CAmWorkerThreadPool::cancelWork(int workerID) +{ + std::vector::iterator it=mListWorkers.begin(); + for(;it!=mListWorkers.end();++it) + { + if(it->workerID==workerID && it->busy) + { + sem_post(&it->cancel); + return (true); + } + } + return (false); +} + +void CAmWorkerThreadPool::finishedWork(pthread_t threadID) +{ + pthread_mutex_lock(&mBlockingMutex); + std::vector::iterator it=mListWorkers.begin(); + for(;it!=mListWorkers.end();++it) + { + if(it->threadID==threadID) + { + it->busy=false; + delete it->worker; + break; + } + } + pthread_mutex_unlock(&mBlockingMutex); +} + +CAmWorkerThreadPool::~CAmWorkerThreadPool() +{ + for (int i=0;icancelWork(); + return (true); +} + +CAmRoutingSenderAsync::CAmRoutingSenderAsync(): +mReceiveInterface(0), mDomains(createDomainTable()), mSinks(createSinkTable()), mSources ( createSourceTable ( ) ), mGateways ( createGatewayTable ( ) ), mMapHandleWorker ( ) , mMapConnectionIDRoute ( ) , mPool (10) +{ +} + +CAmRoutingSenderAsync::~CAmRoutingSenderAsync() +{ + delete mShadow; +} + +am_Error_e CAmRoutingSenderAsync::startupInterface(IAmRoutingReceive *routingreceiveinterface) +{ + //first, create the Shadow: + assert(routingreceiveinterface!=0); + mReceiveInterface = routingreceiveinterface; + CAmSocketHandler* handler; + routingreceiveinterface->getSocketHandler(handler); + mShadow = new IAmRoutingReceiverShadow(routingreceiveinterface, handler); + return E_OK; +} + +void CAmRoutingSenderAsync::setRoutingReady(const uint16_t handle) +{ + syncRegisterWorker *worker = new syncRegisterWorker(this, &mPool, mShadow, mDomains, mSinks, mSources, handle); + + if ((mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncConnect not enough threads!"); + delete worker; + } + + //gateways +// std::vector::iterator gatewayIter=mGateways.begin(); +// for(;gatewayIter!=mGateways.end();++gatewayIter) +// { +// am_gatewayID_t gatewayID; +// gatewayIter->domainSinkID=mDomains[0].domainID; +// gatewayIter->domainSourceID=mDomains[1].domainID; +// gatewayIter->controlDomainID=mDomains[0].domainID; +// if((eCode=mReceiveInterface->registerGateway(*gatewayIter,gatewayID))!=E_OK) +// { +// logError("AsyncRoutingSender::routingInterfacesReady error on registering gateway, failed with",eCode)); +// } +// gatewayIter->gatewayID=gatewayID; +// } + + //create thread for interrupts, but only if we are testing - otherwise we get 100% cpu load: + //todo: find a solution for the 100% dbus load to uncomment this and make interrupt tests work + //pthread_create(&mInterruptThread,NULL,&AsyncRoutingSender::InterruptEvents,&mShadow); +} + +void CAmRoutingSenderAsync::setRoutingRundown(const uint16_t handle) +{ + assert(mReceiveInterface!=0); + mShadow->confirmRoutingRundown(handle); +} + +am_Error_e CAmRoutingSenderAsync::asyncAbort(const am_Handle_s handle) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + + //first check if we know the handle + pthread_mutex_lock(&mMapHandleWorkerMutex); + std::map::iterator iter = mMapHandleWorker.begin(); + if (mMapHandleWorker.find(handle.handle) == mMapHandleWorker.end()) + { + pthread_mutex_unlock(&mMapHandleWorkerMutex); + return (E_NON_EXISTENT); + } + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + //ok, cancel the action: + if (mPool.cancelWork(iter->second)) + return (E_OK); + return (E_UNKNOWN); +} + +am_Error_e CAmRoutingSenderAsync::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_CONNECT); + assert(connectionID!=0); + assert(sinkID!=0); + assert(sourceID!=0); + + //check if we can take the job + am_Sink_s sink; + am_Source_s source; + int16_t work = -1; + + //find the sink + std::vector::iterator sinkIter = mSinks.begin(); + for (; sinkIter != mSinks.end(); ++sinkIter) + { + if (sinkIter->sinkID == sinkID) + { + sink = *sinkIter; + break; + } + } + if (sinkIter == mSinks.end()) + return (E_NON_EXISTENT); //not found! + + //find the source + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + source = *sourceIter; + break; + } + } + if (sourceIter == mSources.end()) + return (E_NON_EXISTENT); //not found! + + //check the format + if (std::find(source.listConnectionFormats.begin(), source.listConnectionFormats.end(), connectionFormat) == source.listConnectionFormats.end()) + return (E_WRONG_FORMAT); + if (std::find(sink.listConnectionFormats.begin(), sink.listConnectionFormats.end(), connectionFormat) == sink.listConnectionFormats.end()) + return (E_WRONG_FORMAT); + + //the operation is ok, lets create a worker, assign it to a task in the task pool + asycConnectWorker *worker = new asycConnectWorker(this, &mPool, mShadow, handle, connectionID, sourceID, sinkID, connectionFormat); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncConnect not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_DISCONNECT); + assert(connectionID!=0); + + //check if we can take the job + int16_t work = -1; + + pthread_mutex_lock(&mMapConnectionMutex); + if (mMapConnectionIDRoute.find(connectionID) == mMapConnectionIDRoute.end()) + { + pthread_mutex_unlock(&mMapConnectionMutex); + return (E_NON_EXISTENT); + } + pthread_mutex_unlock(&mMapConnectionMutex); + + //the operation is ok, lets create a worker, assign it to a task in the task pool + asycDisConnectWorker *worker = new asycDisConnectWorker(this, &mPool, mShadow, handle, connectionID); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncDisconnect not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_SETSINKVOLUME); + assert(sinkID!=0); + + //check if we can take the job + am_Sink_s sink; + int16_t work = -1; + + //find the sink + pthread_mutex_lock(&mSinksMutex); + std::vector::iterator sinkIter = mSinks.begin(); + for (; sinkIter != mSinks.end(); ++sinkIter) + { + if (sinkIter->sinkID == sinkID) + { + sink = *sinkIter; + break; + } + } + pthread_mutex_unlock(&mSinksMutex); + if (sinkIter == mSinks.end()) + return (E_NON_EXISTENT); //not found! + + asyncSetSinkVolumeWorker *worker = new asyncSetSinkVolumeWorker(this, &mPool, mShadow, sinkIter->volume, handle, sinkID, volume, ramp, time); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncSetSinkVolume not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_SETSOURCEVOLUME); + assert(sourceID!=0); + + //check if we can take the job + am_Source_s source; + int16_t work = -1; + + //find the sink + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + source = *sourceIter; + break; + } + } + pthread_mutex_unlock(&mSourcesMutex); + if (sourceIter == mSources.end()) + return (E_NON_EXISTENT); //not found! + + asyncSetSourceVolumeWorker *worker = new asyncSetSourceVolumeWorker(this, &mPool, mShadow, sourceIter->volume, handle, sourceID, volume, ramp, time); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncSetSourceVolume not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_SETSOURCESTATE); + assert(sourceID!=0); + + //check if we can take the job + am_Source_s source; + int16_t work = -1; + + //find the source + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + source = *sourceIter; + break; + } + } + pthread_mutex_unlock(&mSourcesMutex); + if (sourceIter == mSources.end()) + return (E_NON_EXISTENT); //not found! + + asyncSetSourceStateWorker *worker = new asyncSetSourceStateWorker(this, &mPool, mShadow, handle, sourceID, state); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncSetSourceState not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_SETSINKSOUNDPROPERTY); + assert(sinkID!=0); + + //check if we can take the job + am_Sink_s sink; + int16_t work = -1; + + //find the sink + pthread_mutex_lock(&mSinksMutex); + std::vector::iterator sinkIter = mSinks.begin(); + for (; sinkIter != mSinks.end(); ++sinkIter) + { + if (sinkIter->sinkID == sinkID) + { + sink = *sinkIter; + break; + } + } + pthread_mutex_unlock(&mSinksMutex); + if (sinkIter == mSinks.end()) + return (E_NON_EXISTENT); //not found! + + asyncSetSinkSoundPropertyWorker *worker = new asyncSetSinkSoundPropertyWorker(this, &mPool, mShadow, handle, soundProperty, sinkID); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncSetSinkSoundProperty not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) +{ + //todo: implement crossfader + (void) handle; + (void) crossfaderID; + (void) hotSink; + (void) rampType; + (void) time; + return E_NOT_USED; +} + +am_Error_e CAmRoutingSenderAsync::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + assert(mReceiveInterface!=0); + assert(domainID!=0); + + //check if we can take the job + am_Domain_s domain; + int16_t work = -1; + + //find the sink + pthread_mutex_lock(&mDomainsMutex); + std::vector::iterator domainIter = mDomains.begin(); + for (; domainIter != mDomains.end(); ++domainIter) + { + if (domainIter->domainID == domainID) + { + domain = *domainIter; + break; + } + } + pthread_mutex_unlock(&mDomainsMutex); + if (domainIter == mDomains.end()) + return (E_NON_EXISTENT); //not found! + + asyncDomainStateChangeWorker *worker = new asyncDomainStateChangeWorker(this, &mPool, mShadow, domainID, domainState); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::setDomainState not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + return (E_OK); + +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) +{ + assert(mReceiveInterface!=0); + assert(handle.handle!=0); + assert(handle.handleType==H_SETSOURCESOUNDPROPERTY); + assert(sourceID!=0); + + //check if we can take the job + am_Source_s source; + int16_t work = -1; + + //find the source + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + source = *sourceIter; + break; + } + } + pthread_mutex_unlock(&mSourcesMutex); + if (sourceIter == mSources.end()) + return (E_NON_EXISTENT); //not found! + + asyncSetSourceSoundPropertyWorker *worker = new asyncSetSourceSoundPropertyWorker(this, &mPool, mShadow, handle, soundProperty, sourceID); + if ((work = mPool.startWork(worker)) == -1) + { + logError("AsyncRoutingSender::asyncSetSourceState not enough threads!"); + delete worker; + return (E_NOT_POSSIBLE); + } + + //save the handle related to the workerID + pthread_mutex_lock(&mMapHandleWorkerMutex); + mMapHandleWorker.insert(std::make_pair(handle.handle, work)); + pthread_mutex_unlock(&mMapHandleWorkerMutex); + + return (E_OK); +} + +am_Error_e CAmRoutingSenderAsync::returnBusName(std::string & BusName) const +{ + BusName = "RoutingAsync"; + return (E_OK); +} + +std::vector CAmRoutingSenderAsync::createDomainTable() +{ + //just write two domains into the table and return it + std::vector table; + am_Domain_s item; + item.busname = "RoutingAsync"; + item.domainID = 0; + item.early = false; + item.name = "AsyncDomain1"; + item.nodename = "AsyncNode1"; + item.state = DS_CONTROLLED; + table.push_back(item); + item.busname = "RoutingAsync"; + item.domainID = 0; + item.early = false; + item.name = "AsyncDomain2"; + item.nodename = "AsyncNode2"; + item.state = DS_CONTROLLED; + table.push_back(item); + return (table); +} + +std::vector CAmRoutingSenderAsync::createSinkTable() +{ + //create a bunch full of sinks + std::vector table; + am_Sink_s item; + am_SoundProperty_s sp; + sp.type = SP_EXAMPLE_BASS; + sp.value = 0; + + std::vector listMainSoundProperties; + am_MainSoundProperty_s msp; + msp.type = MSP_EXAMPLE_BASS; + msp.value = 5; + listMainSoundProperties.push_back(msp); + msp.type = MSP_EXAMPLE_MID; + listMainSoundProperties.push_back(msp); + msp.type = MSP_EXAMPLE_TREBLE; + listMainSoundProperties.push_back(msp); + for (int16_t i = 0; i <= 10; i++) + { + std::stringstream temp; + temp << i; + item.domainID = 0; //we cannot know this when the table is created ! + item.name = "mySink" + temp.str(); + item.sinkID = i; //take fixed ids to make thins easy + item.sinkClassID = 1; + item.volume = 0; + item.available.availability = A_AVAILABLE; + item.available.availabilityReason = AR_UNKNOWN; + item.listSoundProperties.push_back(sp); + item.listMainSoundProperties = listMainSoundProperties; + item.visible = true; + item.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + item.muteState = MS_MUTED; + item.mainVolume = 0; + table.push_back(item); + } + return (table); +} + +std::vector CAmRoutingSenderAsync::createSourceTable() +{ + //create a bunch full of sources + std::vector table; + am_Source_s item; + for (int16_t i = 0; i <= 10; i++) + { + std::stringstream temp; + temp << i; + item.domainID = 0; //we cannot know this when the table is created ! + item.name = "mySource" + temp.str(); + item.sourceState = SS_OFF; + item.sourceID = i; //take fixed ids to make thins easy + item.sourceClassID = 1; + item.volume = 0; + item.visible = true; + item.available.availability = A_AVAILABLE; + item.available.availabilityReason = AR_UNKNOWN; + item.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + table.push_back(item); + } + return (table); +} + +void CAmRoutingSenderAsync::insertConnectionSafe(am_connectionID_t connectionID, am_RoutingElement_s route) +{ + pthread_mutex_lock(&mMapConnectionMutex); + mMapConnectionIDRoute.insert(std::make_pair(connectionID, route)); + pthread_mutex_unlock(&mMapConnectionMutex); +} + +void CAmRoutingSenderAsync::removeHandleSafe(uint16_t handle) +{ + pthread_mutex_lock(&mMapHandleWorkerMutex); + if (!mMapHandleWorker.erase(handle)) + { + logError("AsyncRoutingSender::removeHandle could not remove handle"); + } + pthread_mutex_unlock(&mMapHandleWorkerMutex); +} + +void CAmRoutingSenderAsync::removeConnectionSafe(am_connectionID_t connectionID) +{ + pthread_mutex_lock(&mMapConnectionMutex); + if (!mMapConnectionIDRoute.erase(connectionID)) + { + logError("AsyncRoutingSender::removeConnectionSafe could not remove connection"); + } + pthread_mutex_unlock(&mMapConnectionMutex); +} + +void CAmRoutingSenderAsync::updateSinkVolumeSafe(am_sinkID_t sinkID, am_volume_t volume) +{ + pthread_mutex_lock(&mSinksMutex); + std::vector::iterator sinkIter = mSinks.begin(); + for (; sinkIter != mSinks.end(); ++sinkIter) + { + if (sinkIter->sinkID == sinkID) + { + sinkIter->volume = volume; + break; + } + } + pthread_mutex_unlock(&mSinksMutex); +} + +void am::CAmRoutingSenderAsync::updateSourceVolumeSafe(am_sourceID_t sourceID, am_volume_t volume) +{ + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + sourceIter->volume = volume; + break; + } + } + pthread_mutex_unlock(&mSourcesMutex); +} + +void am::CAmRoutingSenderAsync::updateSourceStateSafe(am_sourceID_t sourceID, am_SourceState_e state) +{ + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + sourceIter->sourceState = state; + break; + } + } + pthread_mutex_unlock(&mSourcesMutex); +} + +void am::CAmRoutingSenderAsync::updateSinkSoundPropertySafe(am_sinkID_t sinkID, am_SoundProperty_s soundProperty) +{ + pthread_mutex_lock(&mSinksMutex); + std::vector::iterator sinkIter = mSinks.begin(); + for (; sinkIter != mSinks.end(); ++sinkIter) + { + if (sinkIter->sinkID == sinkID) + { + std::vector::iterator spIterator = sinkIter->listSoundProperties.begin(); + for (; spIterator != sinkIter->listSoundProperties.end(); ++spIterator) + { + if (spIterator->type == soundProperty.type) + { + spIterator->value = soundProperty.value; + break; + } + } + } + } + pthread_mutex_unlock(&mSinksMutex); +} + +void am::CAmRoutingSenderAsync::updateSourceSoundPropertySafe(am_sourceID_t sourceID, am_SoundProperty_s soundProperty) +{ + pthread_mutex_lock(&mSourcesMutex); + std::vector::iterator sourceIter = mSources.begin(); + for (; sourceIter != mSources.end(); ++sourceIter) + { + if (sourceIter->sourceID == sourceID) + { + std::vector::iterator spIterator = sourceIter->listSoundProperties.begin(); + for (; spIterator != sourceIter->listSoundProperties.end(); ++spIterator) + { + if (spIterator->type == soundProperty.type) + { + spIterator->value = soundProperty.value; + break; + } + } + } + } + pthread_mutex_unlock(&mSourcesMutex); +} + +void am::CAmRoutingSenderAsync::updateDomainstateSafe(am_domainID_t domainID, am_DomainState_e domainState) +{ + pthread_mutex_lock(&mDomainsMutex); + std::vector::iterator domainIter = mDomains.begin(); + for (; domainIter != mDomains.end(); ++domainIter) + { + if (domainIter->domainID == domainID) + { + domainIter->state = domainState; + break; + } + } + pthread_mutex_unlock(&mDomainsMutex); +} + +void am::CAmRoutingSenderAsync::updateDomainListSafe(std::vector listDomains) +{ + pthread_mutex_lock(&mDomainsMutex); + mDomains = listDomains; + pthread_mutex_unlock(&mDomainsMutex); +} + +void am::CAmRoutingSenderAsync::updateSourceListSafe(std::vector listSource) +{ + pthread_mutex_lock(&mSourcesMutex); + mSources = listSource; + pthread_mutex_unlock(&mSourcesMutex); +} + +void am::CAmRoutingSenderAsync::updateSinkListSafe(std::vector listSinks) +{ + pthread_mutex_lock(&mSinksMutex); + mSinks = listSinks; + pthread_mutex_unlock(&mSinksMutex); +} + +void CAmRoutingSenderAsync::getInterfaceVersion(std::string & version) const +{ + version = RoutingSendVersion; +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) +{ + //todo: implement + (void) handle; + (void) sourceID; + (void) listSoundProperties; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderAsync::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) +{ + //todo: implement + (void) handle; + (void) sinkID; + (void) listSoundProperties; + return (E_NOT_USED); +} + +std::vector CAmRoutingSenderAsync::createGatewayTable() +{ + std::vector table; + am_Gateway_s item; + item.name = "myGateway"; + item.sinkID = 2; + item.sourceID = 2; + table.push_back(item); + return (table); +} + +asycConnectWorker::asycConnectWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mHandle(handle), // + mConnectionID(connectionID), // + mSourceID(sourceID), // + mSinkID(sinkID), // + mConnectionFormat(connectionFormat) +{ +} + +void asycConnectWorker::start2work() +{ + logInfo("Start connecting"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + am_RoutingElement_s route; + route.sinkID = mSinkID; + route.sourceID = mSourceID; + route.connectionFormat = mConnectionFormat; + + //enter new connectionID into the list + mAsyncSender->insertConnectionSafe(mConnectionID, route); + + //send the ack + mShadow->ackConnect(mHandle, mConnectionID, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asycConnectWorker::cancelWork() +{ + mAsyncSender->removeHandleSafe(mHandle.handle); + mShadow->ackConnect(mHandle, mConnectionID, E_ABORTED); +} + +asycDisConnectWorker::asycDisConnectWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_Handle_s handle, const am_connectionID_t connectionID) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mHandle(handle), // + mConnectionID(connectionID) +{ +} + +void asycDisConnectWorker::start2work() +{ + logInfo("Start disconnecting"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + am_RoutingElement_s route; + + //enter new connectionID into the list + mAsyncSender->insertConnectionSafe(mConnectionID, route); + + //send the ack + mShadow->ackDisconnect(mHandle, mConnectionID, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); + +} + +void asycDisConnectWorker::cancelWork() +{ + mAsyncSender->removeHandleSafe(mHandle.handle); + mShadow->ackDisconnect(mHandle, mConnectionID, E_ABORTED); +} + +asyncSetSinkVolumeWorker::asyncSetSinkVolumeWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mCurrentVolume(currentVolume), // + mHandle(handle), // + mSinkID(sinkID), // + mVolume(volume), // + mRamp(ramp), // + mTime(time) +{ +} + +void asyncSetSinkVolumeWorker::start2work() +{ + //todo: this implementation does not respect time and ramp.... + logInfo("Start setting sink volume"); + timespec t; + t.tv_nsec = 10000000; + t.tv_sec = 0; + + while (mCurrentVolume != mVolume) + { + if (mCurrentVolume < mVolume) + mCurrentVolume++; + else + mCurrentVolume--; + mShadow->ackSinkVolumeTick(mHandle, mSinkID, mCurrentVolume); + if (timedWait(t)) + return; + } + + //enter new connectionID into the list + mAsyncSender->updateSinkVolumeSafe(mSinkID, mCurrentVolume); + + //send the ack + mShadow->ackSetSinkVolumeChange(mHandle, mCurrentVolume, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asyncSetSinkVolumeWorker::cancelWork() +{ + mAsyncSender->updateSinkVolumeSafe(mSinkID, mCurrentVolume); + mAsyncSender->removeHandleSafe(mHandle.handle); + mShadow->ackSetSinkVolumeChange(mHandle, mCurrentVolume, E_ABORTED); +} + +asyncSetSourceVolumeWorker::asyncSetSourceVolumeWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sourceID_t SourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mCurrentVolume(currentVolume), // + mHandle(handle), // + mSourceID(SourceID), // + mVolume(volume), // + mRamp(ramp), // + mTime(time) +{ +} + +void asyncSetSourceVolumeWorker::start2work() +{ + //todo: this implementation does not respect time and ramp.... + logInfo("Start setting source volume"); + timespec t; + t.tv_nsec = 10000000; + t.tv_sec = 0; + + while (mCurrentVolume != mVolume) + { + if (mCurrentVolume < mVolume) + mCurrentVolume++; + else + mCurrentVolume--; + mShadow->ackSourceVolumeTick(mHandle, mSourceID, mCurrentVolume); + if (timedWait(t)) + return; + } + + //enter new connectionID into the list + mAsyncSender->updateSourceVolumeSafe(mSourceID, mCurrentVolume); + + //send the ack + mShadow->ackSetSourceVolumeChange(mHandle, mCurrentVolume, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asyncSetSourceVolumeWorker::cancelWork() +{ + mAsyncSender->updateSourceVolumeSafe(mSourceID, mCurrentVolume); + mAsyncSender->removeHandleSafe(mHandle.handle); + mShadow->ackSetSourceVolumeChange(mHandle, mCurrentVolume, E_ABORTED); +} + +asyncSetSourceStateWorker::asyncSetSourceStateWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mHandle(handle), // + mSourceID(sourceID), // + mSourcestate(state) +{ +} + +void asyncSetSourceStateWorker::start2work() +{ + logInfo("Start setting source state"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + + //enter new connectionID into the list + mAsyncSender->updateSourceStateSafe(mSourceID, mSourcestate); + + //send the ack + mShadow->ackSetSourceState(mHandle, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asyncSetSourceStateWorker::cancelWork() +{ + //send the ack + mShadow->ackSetSourceState(mHandle, E_ABORTED); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +asyncSetSinkSoundPropertyWorker::asyncSetSinkSoundPropertyWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sinkID_t sinkID) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mHandle(handle), // + mSinkID(sinkID), // + mSoundProperty(soundProperty) +{ +} + +void asyncSetSinkSoundPropertyWorker::start2work() +{ + logInfo("Start setting sink sound property"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + + //enter new connectionID into the list + mAsyncSender->updateSinkSoundPropertySafe(mSinkID, mSoundProperty); + + //send the ack + mShadow->ackSetSinkSoundProperty(mHandle, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asyncSetSinkSoundPropertyWorker::cancelWork() +{ + //send the ack + mShadow->ackSetSinkSoundProperty(mHandle, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +asyncSetSourceSoundPropertyWorker::asyncSetSourceSoundPropertyWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sourceID_t sourceID) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mHandle(handle), // + mSourceID(sourceID), // + mSoundProperty(soundProperty) +{ +} + +void asyncSetSourceSoundPropertyWorker::start2work() +{ + logInfo("Start setting source sound property"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + + //enter new connectionID into the list + mAsyncSender->updateSourceSoundPropertySafe(mSourceID, mSoundProperty); + + //send the ack + mShadow->ackSetSourceSoundProperty(mHandle, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +void asyncSetSourceSoundPropertyWorker::cancelWork() +{ + //send the ack + mShadow->ackSetSourceSoundProperty(mHandle, E_OK); + + //destroy the handle + mAsyncSender->removeHandleSafe(mHandle.handle); +} + +asyncDomainStateChangeWorker::asyncDomainStateChangeWorker(CAmRoutingSenderAsync *asyncSender, CAmWorkerThreadPool *pool, IAmRoutingReceiverShadow *shadow, const am_domainID_t domainID, const am_DomainState_e domainState) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mDomainID(domainID), // + mDomainState(domainState) +{ +} + +void asyncDomainStateChangeWorker::start2work() +{ + //todo: sendchanged data must be in here ! + logInfo("Start setting source sound property"); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 1; + + //do something for one second + if (timedWait(t)) + return; + + //enter new connectionID into the list + mAsyncSender->updateDomainstateSafe(mDomainID, mDomainState); + mShadow->hookDomainStateChange(mDomainID, mDomainState); + //send the new status + +} + +void am::asyncDomainStateChangeWorker::cancelWork() +{ + //send the new status + mShadow->hookDomainStateChange(mDomainID, mDomainState); +} + +syncRegisterWorker::syncRegisterWorker(CAmRoutingSenderAsync * asyncSender, CAmWorkerThreadPool* pool, IAmRoutingReceiverShadow* shadow, const std::vector domains, const std::vector sinks, const std::vector sources, const uint16_t handle) : + CAmWorker(pool), // + mAsyncSender(asyncSender), // + mShadow(shadow), // + mListDomains(domains), // + mListSinks(sinks), // + mListSources(sources), mHandle(handle) +{ +} + +void syncRegisterWorker::start2work() +{ + //todo: sendchanged data must be in here ! + logInfo("Start to register stuff"); + + am_Error_e eCode; + + std::vector::iterator domainIter = mListDomains.begin(); + for (; domainIter != mListDomains.end(); ++domainIter) + { + am_domainID_t domainID; + if ((eCode = mShadow->registerDomain(*domainIter, domainID)) != E_OK) + { + logError("syncRegisterWorker::start2work error on registering domain, failed with", eCode); + } + domainIter->domainID = domainID; + } + + mAsyncSender->updateDomainListSafe(mListDomains); + + //then sources + std::vector::iterator sourceIter = mListSources.begin(); + for (; sourceIter != mListSources.end(); ++sourceIter) + { + am_sourceID_t sourceID; + //set the correct domainID + sourceIter->domainID = mListDomains[0].domainID; + if ((eCode = mShadow->registerSource(*sourceIter, sourceID)) != E_OK) + { + logError("syncRegisterWorker::start2work error on registering source, failed with", eCode); + } + } + + mAsyncSender->updateSourceListSafe(mListSources); + + //sinks + std::vector::iterator sinkIter = mListSinks.begin(); + for (; sinkIter != mListSinks.end(); ++sinkIter) + { + am_sinkID_t sinkID; + //set the correct domainID + sinkIter->domainID = mListDomains[0].domainID; + if ((eCode = mShadow->registerSink(*sinkIter, sinkID)) != E_OK) + { + logError("syncRegisterWorker::start2work error on registering sink, failed with", eCode); + } + } + + mAsyncSender->updateSinkListSafe(mListSinks); + mShadow->confirmRoutingReady(mHandle); +} + +void syncRegisterWorker::cancelWork() +{ +} + diff --git a/PluginRoutingInterfaceAsync/src/IAmRoutingReceiverShadow.cpp b/PluginRoutingInterfaceAsync/src/IAmRoutingReceiverShadow.cpp new file mode 100644 index 0000000..b8733db --- /dev/null +++ b/PluginRoutingInterfaceAsync/src/IAmRoutingReceiverShadow.cpp @@ -0,0 +1,195 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file RoutingReceiverAsyncShadow.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "IAmRoutingReceiverShadow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "shared/CAmDltWrapper.h" + +using namespace am; + +IAmRoutingReceiverShadow::IAmRoutingReceiverShadow(IAmRoutingReceive* iReceiveInterface, CAmSocketHandler* iSocketHandler) : + mSocketHandler(iSocketHandler), // + mRoutingReceiveInterface(iReceiveInterface), // + mSerializer(iSocketHandler) +{ + +} + +IAmRoutingReceiverShadow::~IAmRoutingReceiverShadow() +{ +} + +void IAmRoutingReceiverShadow::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackConnect, handle, connectionID, error); +} + +void IAmRoutingReceiverShadow::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackDisconnect, handle, connectionID, error); +} + +void IAmRoutingReceiverShadow::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSetSinkVolumeChange, handle, volume, error); +} + +void IAmRoutingReceiverShadow::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSetSourceVolumeChange, handle, volume, error); +} + +void IAmRoutingReceiverShadow::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSetSourceState, handle, error); +} + +void IAmRoutingReceiverShadow::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSetSinkSoundProperty, handle, error); +} + +void IAmRoutingReceiverShadow::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSetSourceSoundProperty, handle, error); +} + +void IAmRoutingReceiverShadow::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackCrossFading, handle, hotSink, error); +} + +void IAmRoutingReceiverShadow::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSourceVolumeTick, handle, sourceID, volume); +} + +void IAmRoutingReceiverShadow::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::ackSinkVolumeTick, handle, sinkID, volume); +} + +void IAmRoutingReceiverShadow::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::hookInterruptStatusChange, sourceID, interruptState); +} + +void IAmRoutingReceiverShadow::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::hookSinkAvailablityStatusChange, sinkID, availability); +} + +void IAmRoutingReceiverShadow::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::hookSourceAvailablityStatusChange, sourceID, availability); +} + +void IAmRoutingReceiverShadow::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::hookDomainStateChange, domainID, domainState); +} + +void IAmRoutingReceiverShadow::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) +{ + mSerializer.asyncCall(mRoutingReceiveInterface, &IAmRoutingReceive::hookTimingInformationChanged, connectionID, delay); +} + +am_Error_e IAmRoutingReceiverShadow::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + am_Error_e error (E_UNKNOWN); + am_Domain_s domainDataCopy(domainData); + mSerializer.syncCall(mRoutingReceiveInterface, &IAmRoutingReceive::registerDomain, error, domainDataCopy, domainID); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + am_Error_e error (E_UNKNOWN); + am_Gateway_s gatewayDataCopy(gatewayData); + mSerializer.syncCall(mRoutingReceiveInterface,&IAmRoutingReceive::registerGateway, error, gatewayDataCopy, gatewayID); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + am_Error_e error (E_UNKNOWN); + am_Sink_s sinkDataCopy(sinkData); + mSerializer.syncCall(mRoutingReceiveInterface,&IAmRoutingReceive::registerSink, error, sinkDataCopy, sinkID); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::deregisterSink(const am_sinkID_t sinkID) +{ + am_Error_e error; + am_sinkID_t s(sinkID); //no const values allowed in syncCalls due to reference ! + mSerializer.syncCall(mRoutingReceiveInterface, &IAmRoutingReceive::deregisterSink, error, s); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + am_Error_e error (E_UNKNOWN); + am_Source_s sourceDataCopy(sourceData); + mSerializer.syncCall(mRoutingReceiveInterface,&IAmRoutingReceive::registerSource, error, sourceDataCopy, sourceID); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::deregisterSource(const am_sourceID_t sourceID) +{ + am_Error_e error; + am_sourceID_t s(sourceID); //no const values allowed in syncCalls due to reference ! + mSerializer.syncCall(mRoutingReceiveInterface, &IAmRoutingReceive::deregisterSource, error, s); + return (error); +} + +am_Error_e am::IAmRoutingReceiverShadow::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + am_Error_e error (E_UNKNOWN); + am_Crossfader_s crossfaderDataCopy(crossfaderData); + mSerializer.syncCall(mRoutingReceiveInterface,&IAmRoutingReceive::registerCrossfader, error, crossfaderDataCopy, crossfaderID); + return (error); +} + +void am::IAmRoutingReceiverShadow::confirmRoutingReady(uint16_t starupHandle) +{ + mSerializer.asyncCall(mRoutingReceiveInterface,&IAmRoutingReceive::confirmRoutingReady,starupHandle); +} + +void am::IAmRoutingReceiverShadow::confirmRoutingRundown(uint16_t rundownHandle) +{ + mSerializer.asyncCall(mRoutingReceiveInterface,&IAmRoutingReceive::confirmRoutingRundown,rundownHandle); +} + + + + + diff --git a/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp b/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp deleted file mode 100644 index 5c93f60..0000000 --- a/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file RoutingReceiverAsyncShadow.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "RoutingReceiverAsyncShadow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "DLTWrapper.h" - -using namespace am; - -RoutingReceiverAsyncShadow::RoutingReceiverAsyncShadow(RoutingReceiveInterface* iReceiveInterface, SocketHandler* iSocketHandler) : - mSocketHandler(iSocketHandler), // - mRoutingReceiveInterface(iReceiveInterface), // - mSerializer(iSocketHandler) -{ - -} - -RoutingReceiverAsyncShadow::~RoutingReceiverAsyncShadow() -{ -} - -void RoutingReceiverAsyncShadow::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackConnect, handle, connectionID, error); -} - -void RoutingReceiverAsyncShadow::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackDisconnect, handle, connectionID, error); -} - -void RoutingReceiverAsyncShadow::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSetSinkVolumeChange, handle, volume, error); -} - -void RoutingReceiverAsyncShadow::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSetSourceVolumeChange, handle, volume, error); -} - -void RoutingReceiverAsyncShadow::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSetSourceState, handle, error); -} - -void RoutingReceiverAsyncShadow::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSetSinkSoundProperty, handle, error); -} - -void RoutingReceiverAsyncShadow::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSetSourceSoundProperty, handle, error); -} - -void RoutingReceiverAsyncShadow::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackCrossFading, handle, hotSink, error); -} - -void RoutingReceiverAsyncShadow::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSourceVolumeTick, handle, sourceID, volume); -} - -void RoutingReceiverAsyncShadow::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::ackSinkVolumeTick, handle, sinkID, volume); -} - -void RoutingReceiverAsyncShadow::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::hookInterruptStatusChange, sourceID, interruptState); -} - -void RoutingReceiverAsyncShadow::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::hookSinkAvailablityStatusChange, sinkID, availability); -} - -void RoutingReceiverAsyncShadow::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::hookSourceAvailablityStatusChange, sourceID, availability); -} - -void RoutingReceiverAsyncShadow::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::hookDomainStateChange, domainID, domainState); -} - -void RoutingReceiverAsyncShadow::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - mSerializer.asyncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::hookTimingInformationChanged, connectionID, delay); -} - -am_Error_e RoutingReceiverAsyncShadow::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - am_Error_e error (E_UNKNOWN); - am_Domain_s domainDataCopy(domainData); - mSerializer.syncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::registerDomain, error, domainDataCopy, domainID); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - am_Error_e error (E_UNKNOWN); - am_Gateway_s gatewayDataCopy(gatewayData); - mSerializer.syncCall(mRoutingReceiveInterface,&RoutingReceiveInterface::registerGateway, error, gatewayDataCopy, gatewayID); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - am_Error_e error (E_UNKNOWN); - am_Sink_s sinkDataCopy(sinkData); - mSerializer.syncCall(mRoutingReceiveInterface,&RoutingReceiveInterface::registerSink, error, sinkDataCopy, sinkID); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::deregisterSink(const am_sinkID_t sinkID) -{ - am_Error_e error; - am_sinkID_t s(sinkID); //no const values allowed in syncCalls due to reference ! - mSerializer.syncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::deregisterSink, error, s); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - am_Error_e error (E_UNKNOWN); - am_Source_s sourceDataCopy(sourceData); - mSerializer.syncCall(mRoutingReceiveInterface,&RoutingReceiveInterface::registerSource, error, sourceDataCopy, sourceID); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::deregisterSource(const am_sourceID_t sourceID) -{ - am_Error_e error; - am_sourceID_t s(sourceID); //no const values allowed in syncCalls due to reference ! - mSerializer.syncCall(mRoutingReceiveInterface, &RoutingReceiveInterface::deregisterSource, error, s); - return (error); -} - -am_Error_e am::RoutingReceiverAsyncShadow::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - am_Error_e error (E_UNKNOWN); - am_Crossfader_s crossfaderDataCopy(crossfaderData); - mSerializer.syncCall(mRoutingReceiveInterface,&RoutingReceiveInterface::registerCrossfader, error, crossfaderDataCopy, crossfaderID); - return (error); -} - -void am::RoutingReceiverAsyncShadow::confirmRoutingReady(uint16_t starupHandle) -{ - mSerializer.asyncCall(mRoutingReceiveInterface,&RoutingReceiveInterface::confirmRoutingReady,starupHandle); -} - - - diff --git a/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp b/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp deleted file mode 100644 index 68b260f..0000000 --- a/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp +++ /dev/null @@ -1,1372 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file RoutingSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "RoutingSenderAsyn.h" -#include "DLTWrapper.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace am; - -DLT_DECLARE_CONTEXT(PluginRoutingAsync) - -extern "C" RoutingSendInterface* PluginRoutingInterfaceAsyncFactory() -{ - return (new AsyncRoutingSender()); -} - -extern "C" void destroyRoutingPluginInterfaceAsync(RoutingSendInterface* routingSendInterface) -{ - delete routingSendInterface; -} - -pthread_mutex_t AsyncRoutingSender::mMapConnectionMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t AsyncRoutingSender::mMapHandleWorkerMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t AsyncRoutingSender::mSinksMutex= PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t AsyncRoutingSender::mSourcesMutex= PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t AsyncRoutingSender::mDomainsMutex= PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t WorkerThreadPool::mBlockingMutex = PTHREAD_MUTEX_INITIALIZER; - -//void* AsyncRoutingSender::InterruptEvents(void *data) -//{ -// RoutingReceiverAsyncShadow *shadow=(RoutingReceiverAsyncShadow *)data; -// DBusError err; -// DBusMessage* msg; -// DBusConnection* conn; -// dbus_error_init(&err); -// conn = dbus_bus_get(DBUS_BUS_SESSION, &err); -// dbus_uint32_t serial = 0; -// DBusMessage* reply; -// DBusMessageIter args; -// dbus_bus_request_name(conn, "org.genivi.test",DBUS_NAME_FLAG_REPLACE_EXISTING , &err); -// -// while (dbus_connection_read_write_dispatch(conn, -1)) -// { -// dbus_connection_read_write(conn, 0); -// msg = dbus_connection_pop_message(conn); -// -// if (dbus_message_is_method_call(msg, "org.genivi.test", "timingChanged")) -// { -// am_connectionID_t connectionID; -// am_timeSync_t delay; -// dbus_message_iter_init(msg, &args); -// dbus_message_iter_get_basic(&args,(void*) &connectionID); -// dbus_message_iter_next(&args); -// dbus_message_iter_get_basic(&args,(void*) &delay); -// reply = dbus_message_new_method_return(msg); -// dbus_message_iter_init_append(reply, &args); -// dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &connectionID); -// dbus_connection_send(conn, reply, &serial); -// shadow->hookTimingInformationChanged(connectionID,delay); -// dbus_message_unref(reply); -// } -// else if (dbus_message_is_method_call(msg, "org.genivi.test", "SinkAvailablityStatusChange")) -// { -// am_sinkID_t sinkID; -// am_Availability_s availability; -// dbus_message_iter_init(msg, &args); -// dbus_message_iter_get_basic(&args,(void*) &sinkID); -// reply = dbus_message_new_method_return(msg); -// dbus_message_iter_init_append(reply, &args); -// dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &sinkID); -// dbus_connection_send(conn, reply, &serial); -// shadow->hookSinkAvailablityStatusChange(sinkID,availability); -// dbus_message_unref(reply); -// } -// else if (dbus_message_is_method_call(msg, "org.genivi.test", "SourceAvailablityStatusChange")) -// { -// am_sourceID_t sourceID; -// am_Availability_s availability; -// dbus_message_iter_init(msg, &args); -// dbus_message_iter_get_basic(&args,(void*) &sourceID); -// reply = dbus_message_new_method_return(msg); -// dbus_message_iter_init_append(reply, &args); -// dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &sourceID); -// dbus_connection_send(conn, reply, &serial); -// shadow->hookSourceAvailablityStatusChange(sourceID,availability); -// dbus_message_unref(reply); -// } -// else if (dbus_message_is_method_call(msg, "org.genivi.test", "InterruptStatusChange")) -// { -// am_sourceID_t sourceID; -// -// am_InterruptState_e state=IS_UNKNOWN; -// dbus_message_iter_init(msg, &args); -// dbus_message_iter_get_basic(&args,(void*) &sourceID); -// reply = dbus_message_new_method_return(msg); -// dbus_message_iter_init_append(reply, &args); -// dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &sourceID); -// dbus_connection_send(conn, reply, &serial); -// shadow->hookInterruptStatusChange(sourceID,state); -// dbus_message_unref(reply); -// } -// dbus_connection_flush(conn); -// } -// return NULL; -//} - - void *WorkerThreadPool::WorkerThread(void* data) - { - threadInfo_s *myInfo=(threadInfo_s*)data; - while (1) - { - sem_wait(&myInfo->block); - pthread_mutex_lock(&mBlockingMutex); - Worker* actWorker=myInfo->worker; - pthread_mutex_unlock(&mBlockingMutex); - actWorker->setCancelSempaphore(&myInfo->cancel); - actWorker->start2work(); - actWorker->pPool->finishedWork(myInfo->threadID); - } - return NULL; - } - - WorkerThreadPool::WorkerThreadPool(int numThreads): - mNumThreads(numThreads) - { - int workerID=0; - mListWorkers.resize(mNumThreads); - for (int i=0;i::iterator it=mListWorkers.begin(); - for(;it!=mListWorkers.end();++it) - { - if(!it->busy) - { - it->worker=worker; - it->busy=true; - pthread_mutex_unlock(&mBlockingMutex); - sem_post(&it->block); - return ((int)it->workerID); - } - } - pthread_mutex_unlock(&mBlockingMutex); - return (-1); - } - - bool WorkerThreadPool::cancelWork(int workerID) - { - std::vector::iterator it=mListWorkers.begin(); - for(;it!=mListWorkers.end();++it) - { - if(it->workerID==workerID && it->busy) - { - sem_post(&it->cancel); - return (true); - } - } - return (false); - } - - void WorkerThreadPool::finishedWork(pthread_t threadID) - { - pthread_mutex_lock(&mBlockingMutex); - std::vector::iterator it=mListWorkers.begin(); - for(;it!=mListWorkers.end();++it) - { - if(it->threadID==threadID) - { - it->busy=false; - delete it->worker; - break; - } - } - pthread_mutex_unlock(&mBlockingMutex); - } - - WorkerThreadPool::~WorkerThreadPool() - { - for (int i=0;icancelWork(); - return (true); - } - - AsyncRoutingSender::AsyncRoutingSender(): - mReceiveInterface(0), mDomains(createDomainTable()), mSinks(createSinkTable()), mSources ( createSourceTable ( ) ), mGateways ( createGatewayTable ( ) ), mMapHandleWorker ( ) , mMapConnectionIDRoute ( ) , mPool (10) -{ -} - -AsyncRoutingSender::~AsyncRoutingSender() -{ - delete mShadow; -} - -am_Error_e AsyncRoutingSender::startupInterface(RoutingReceiveInterface *routingreceiveinterface) -{ - //first, create the Shadow: - assert(routingreceiveinterface!=0); - mReceiveInterface = routingreceiveinterface; - SocketHandler* handler; - routingreceiveinterface->getSocketHandler(handler); - mShadow = new RoutingReceiverAsyncShadow(routingreceiveinterface, handler); - return E_OK; -} - -void AsyncRoutingSender::setRoutingReady(const uint16_t handle) -{ - syncRegisterWorker *worker = new syncRegisterWorker(this, &mPool, mShadow, mDomains, mSinks, mSources, handle); - - if ((mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncConnect not enough threads!"); - delete worker; - } - - //gateways -// std::vector::iterator gatewayIter=mGateways.begin(); -// for(;gatewayIter!=mGateways.end();++gatewayIter) -// { -// am_gatewayID_t gatewayID; -// gatewayIter->domainSinkID=mDomains[0].domainID; -// gatewayIter->domainSourceID=mDomains[1].domainID; -// gatewayIter->controlDomainID=mDomains[0].domainID; -// if((eCode=mReceiveInterface->registerGateway(*gatewayIter,gatewayID))!=E_OK) -// { -// logError("AsyncRoutingSender::routingInterfacesReady error on registering gateway, failed with",eCode)); -// } -// gatewayIter->gatewayID=gatewayID; -// } - - //create thread for interrupts, but only if we are testing - otherwise we get 100% cpu load: - //todo: find a solution for the 100% dbus load to uncomment this and make interrupt tests work - //pthread_create(&mInterruptThread,NULL,&AsyncRoutingSender::InterruptEvents,&mShadow); -} - -void AsyncRoutingSender::setRoutingRundown(const uint16_t handle) -{ - assert(mReceiveInterface!=0); -} - -am_Error_e AsyncRoutingSender::asyncAbort(const am_Handle_s handle) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - - //first check if we know the handle - pthread_mutex_lock(&mMapHandleWorkerMutex); - std::map::iterator iter = mMapHandleWorker.begin(); - if (mMapHandleWorker.find(handle.handle) == mMapHandleWorker.end()) - { - pthread_mutex_unlock(&mMapHandleWorkerMutex); - return (E_NON_EXISTENT); - } - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - //ok, cancel the action: - if (mPool.cancelWork(iter->second)) - return (E_OK); - return (E_UNKNOWN); -} - -am_Error_e AsyncRoutingSender::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_CONNECT); - assert(connectionID!=0); - assert(sinkID!=0); - assert(sourceID!=0); - - //check if we can take the job - am_Sink_s sink; - am_Source_s source; - int16_t work = -1; - - //find the sink - std::vector::iterator sinkIter = mSinks.begin(); - for (; sinkIter != mSinks.end(); ++sinkIter) - { - if (sinkIter->sinkID == sinkID) - { - sink = *sinkIter; - break; - } - } - if (sinkIter == mSinks.end()) - return (E_NON_EXISTENT); //not found! - - //find the source - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - source = *sourceIter; - break; - } - } - if (sourceIter == mSources.end()) - return (E_NON_EXISTENT); //not found! - - //check the format - if (std::find(source.listConnectionFormats.begin(), source.listConnectionFormats.end(), connectionFormat) == source.listConnectionFormats.end()) - return (E_WRONG_FORMAT); - if (std::find(sink.listConnectionFormats.begin(), sink.listConnectionFormats.end(), connectionFormat) == sink.listConnectionFormats.end()) - return (E_WRONG_FORMAT); - - //the operation is ok, lets create a worker, assign it to a task in the task pool - asycConnectWorker *worker = new asycConnectWorker(this, &mPool, mShadow, handle, connectionID, sourceID, sinkID, connectionFormat); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncConnect not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_DISCONNECT); - assert(connectionID!=0); - - //check if we can take the job - int16_t work = -1; - - pthread_mutex_lock(&mMapConnectionMutex); - if (mMapConnectionIDRoute.find(connectionID) == mMapConnectionIDRoute.end()) - { - pthread_mutex_unlock(&mMapConnectionMutex); - return (E_NON_EXISTENT); - } - pthread_mutex_unlock(&mMapConnectionMutex); - - //the operation is ok, lets create a worker, assign it to a task in the task pool - asycDisConnectWorker *worker = new asycDisConnectWorker(this, &mPool, mShadow, handle, connectionID); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncDisconnect not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_SETSINKVOLUME); - assert(sinkID!=0); - - //check if we can take the job - am_Sink_s sink; - int16_t work = -1; - - //find the sink - pthread_mutex_lock(&mSinksMutex); - std::vector::iterator sinkIter = mSinks.begin(); - for (; sinkIter != mSinks.end(); ++sinkIter) - { - if (sinkIter->sinkID == sinkID) - { - sink = *sinkIter; - break; - } - } - pthread_mutex_unlock(&mSinksMutex); - if (sinkIter == mSinks.end()) - return (E_NON_EXISTENT); //not found! - - asyncSetSinkVolumeWorker *worker = new asyncSetSinkVolumeWorker(this, &mPool, mShadow, sinkIter->volume, handle, sinkID, volume, ramp, time); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncSetSinkVolume not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_SETSOURCEVOLUME); - assert(sourceID!=0); - - //check if we can take the job - am_Source_s source; - int16_t work = -1; - - //find the sink - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - source = *sourceIter; - break; - } - } - pthread_mutex_unlock(&mSourcesMutex); - if (sourceIter == mSources.end()) - return (E_NON_EXISTENT); //not found! - - asyncSetSourceVolumeWorker *worker = new asyncSetSourceVolumeWorker(this, &mPool, mShadow, sourceIter->volume, handle, sourceID, volume, ramp, time); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncSetSourceVolume not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_SETSOURCESTATE); - assert(sourceID!=0); - - //check if we can take the job - am_Source_s source; - int16_t work = -1; - - //find the source - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - source = *sourceIter; - break; - } - } - pthread_mutex_unlock(&mSourcesMutex); - if (sourceIter == mSources.end()) - return (E_NON_EXISTENT); //not found! - - asyncSetSourceStateWorker *worker = new asyncSetSourceStateWorker(this, &mPool, mShadow, handle, sourceID, state); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncSetSourceState not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_SETSINKSOUNDPROPERTY); - assert(sinkID!=0); - - //check if we can take the job - am_Sink_s sink; - int16_t work = -1; - - //find the sink - pthread_mutex_lock(&mSinksMutex); - std::vector::iterator sinkIter = mSinks.begin(); - for (; sinkIter != mSinks.end(); ++sinkIter) - { - if (sinkIter->sinkID == sinkID) - { - sink = *sinkIter; - break; - } - } - pthread_mutex_unlock(&mSinksMutex); - if (sinkIter == mSinks.end()) - return (E_NON_EXISTENT); //not found! - - asyncSetSinkSoundPropertyWorker *worker = new asyncSetSinkSoundPropertyWorker(this, &mPool, mShadow, handle, soundProperty, sinkID); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncSetSinkSoundProperty not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) -{ - //todo: implement crossfader - (void) handle; - (void) crossfaderID; - (void) hotSink; - (void) rampType; - (void) time; - return E_NOT_USED; -} - -am_Error_e AsyncRoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - assert(mReceiveInterface!=0); - assert(domainID!=0); - - //check if we can take the job - am_Domain_s domain; - int16_t work = -1; - - //find the sink - pthread_mutex_lock(&mDomainsMutex); - std::vector::iterator domainIter = mDomains.begin(); - for (; domainIter != mDomains.end(); ++domainIter) - { - if (domainIter->domainID == domainID) - { - domain = *domainIter; - break; - } - } - pthread_mutex_unlock(&mDomainsMutex); - if (domainIter == mDomains.end()) - return (E_NON_EXISTENT); //not found! - - asyncDomainStateChangeWorker *worker = new asyncDomainStateChangeWorker(this, &mPool, mShadow, domainID, domainState); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::setDomainState not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - return (E_OK); - -} - -am_Error_e AsyncRoutingSender::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) -{ - assert(mReceiveInterface!=0); - assert(handle.handle!=0); - assert(handle.handleType==H_SETSOURCESOUNDPROPERTY); - assert(sourceID!=0); - - //check if we can take the job - am_Source_s source; - int16_t work = -1; - - //find the source - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - source = *sourceIter; - break; - } - } - pthread_mutex_unlock(&mSourcesMutex); - if (sourceIter == mSources.end()) - return (E_NON_EXISTENT); //not found! - - asyncSetSourceSoundPropertyWorker *worker = new asyncSetSourceSoundPropertyWorker(this, &mPool, mShadow, handle, soundProperty, sourceID); - if ((work = mPool.startWork(worker)) == -1) - { - logError("AsyncRoutingSender::asyncSetSourceState not enough threads!"); - delete worker; - return (E_NOT_POSSIBLE); - } - - //save the handle related to the workerID - pthread_mutex_lock(&mMapHandleWorkerMutex); - mMapHandleWorker.insert(std::make_pair(handle.handle, work)); - pthread_mutex_unlock(&mMapHandleWorkerMutex); - - return (E_OK); -} - -am_Error_e AsyncRoutingSender::returnBusName(std::string & BusName) const -{ - BusName = "RoutingAsync"; - return (E_OK); -} - -std::vector AsyncRoutingSender::createDomainTable() -{ - //just write two domains into the table and return it - std::vector table; - am_Domain_s item; - item.busname = "RoutingAsync"; - item.domainID = 0; - item.early = false; - item.name = "AsyncDomain1"; - item.nodename = "AsyncNode1"; - item.state = DS_CONTROLLED; - table.push_back(item); - item.busname = "RoutingAsync"; - item.domainID = 0; - item.early = false; - item.name = "AsyncDomain2"; - item.nodename = "AsyncNode2"; - item.state = DS_CONTROLLED; - table.push_back(item); - return (table); -} - -std::vector AsyncRoutingSender::createSinkTable() -{ - //create a bunch full of sinks - std::vector table; - am_Sink_s item; - am_SoundProperty_s sp; - sp.type = SP_EXAMPLE_BASS; - sp.value = 0; - - std::vector listMainSoundProperties; - am_MainSoundProperty_s msp; - msp.type = MSP_EXAMPLE_BASS; - msp.value = 5; - listMainSoundProperties.push_back(msp); - msp.type = MSP_EXAMPLE_MID; - listMainSoundProperties.push_back(msp); - msp.type = MSP_EXAMPLE_TREBLE; - listMainSoundProperties.push_back(msp); - for (int16_t i = 0; i <= 10; i++) - { - std::stringstream temp; - temp << i; - item.domainID = 0; //we cannot know this when the table is created ! - item.name = "mySink" + temp.str(); - item.sinkID = i; //take fixed ids to make thins easy - item.sinkClassID = 1; - item.volume = 0; - item.available.availability = A_AVAILABLE; - item.available.availabilityReason = AR_UNKNOWN; - item.listSoundProperties.push_back(sp); - item.listMainSoundProperties = listMainSoundProperties; - item.visible = true; - item.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - item.muteState = MS_MUTED; - item.mainVolume = 0; - table.push_back(item); - } - return (table); -} - -std::vector AsyncRoutingSender::createSourceTable() -{ - //create a bunch full of sources - std::vector table; - am_Source_s item; - for (int16_t i = 0; i <= 10; i++) - { - std::stringstream temp; - temp << i; - item.domainID = 0; //we cannot know this when the table is created ! - item.name = "mySource" + temp.str(); - item.sourceState = SS_OFF; - item.sourceID = i; //take fixed ids to make thins easy - item.sourceClassID = 1; - item.volume = 0; - item.visible = true; - item.available.availability = A_AVAILABLE; - item.available.availabilityReason = AR_UNKNOWN; - item.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - table.push_back(item); - } - return (table); -} - -void AsyncRoutingSender::insertConnectionSafe(am_connectionID_t connectionID, am_RoutingElement_s route) -{ - pthread_mutex_lock(&mMapConnectionMutex); - mMapConnectionIDRoute.insert(std::make_pair(connectionID, route)); - pthread_mutex_unlock(&mMapConnectionMutex); -} - -void AsyncRoutingSender::removeHandleSafe(uint16_t handle) -{ - pthread_mutex_lock(&mMapHandleWorkerMutex); - if (!mMapHandleWorker.erase(handle)) - { - logError("AsyncRoutingSender::removeHandle could not remove handle"); - } - pthread_mutex_unlock(&mMapHandleWorkerMutex); -} - -void AsyncRoutingSender::removeConnectionSafe(am_connectionID_t connectionID) -{ - pthread_mutex_lock(&mMapConnectionMutex); - if (!mMapConnectionIDRoute.erase(connectionID)) - { - logError("AsyncRoutingSender::removeConnectionSafe could not remove connection"); - } - pthread_mutex_unlock(&mMapConnectionMutex); -} - -void AsyncRoutingSender::updateSinkVolumeSafe(am_sinkID_t sinkID, am_volume_t volume) -{ - pthread_mutex_lock(&mSinksMutex); - std::vector::iterator sinkIter = mSinks.begin(); - for (; sinkIter != mSinks.end(); ++sinkIter) - { - if (sinkIter->sinkID == sinkID) - { - sinkIter->volume = volume; - break; - } - } - pthread_mutex_unlock(&mSinksMutex); -} - -void am::AsyncRoutingSender::updateSourceVolumeSafe(am_sourceID_t sourceID, am_volume_t volume) -{ - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - sourceIter->volume = volume; - break; - } - } - pthread_mutex_unlock(&mSourcesMutex); -} - -void am::AsyncRoutingSender::updateSourceStateSafe(am_sourceID_t sourceID, am_SourceState_e state) -{ - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - sourceIter->sourceState = state; - break; - } - } - pthread_mutex_unlock(&mSourcesMutex); -} - -void am::AsyncRoutingSender::updateSinkSoundPropertySafe(am_sinkID_t sinkID, am_SoundProperty_s soundProperty) -{ - pthread_mutex_lock(&mSinksMutex); - std::vector::iterator sinkIter = mSinks.begin(); - for (; sinkIter != mSinks.end(); ++sinkIter) - { - if (sinkIter->sinkID == sinkID) - { - std::vector::iterator spIterator = sinkIter->listSoundProperties.begin(); - for (; spIterator != sinkIter->listSoundProperties.end(); ++spIterator) - { - if (spIterator->type == soundProperty.type) - { - spIterator->value = soundProperty.value; - break; - } - } - } - } - pthread_mutex_unlock(&mSinksMutex); -} - -void am::AsyncRoutingSender::updateSourceSoundPropertySafe(am_sourceID_t sourceID, am_SoundProperty_s soundProperty) -{ - pthread_mutex_lock(&mSourcesMutex); - std::vector::iterator sourceIter = mSources.begin(); - for (; sourceIter != mSources.end(); ++sourceIter) - { - if (sourceIter->sourceID == sourceID) - { - std::vector::iterator spIterator = sourceIter->listSoundProperties.begin(); - for (; spIterator != sourceIter->listSoundProperties.end(); ++spIterator) - { - if (spIterator->type == soundProperty.type) - { - spIterator->value = soundProperty.value; - break; - } - } - } - } - pthread_mutex_unlock(&mSourcesMutex); -} - -void am::AsyncRoutingSender::updateDomainstateSafe(am_domainID_t domainID, am_DomainState_e domainState) -{ - pthread_mutex_lock(&mDomainsMutex); - std::vector::iterator domainIter = mDomains.begin(); - for (; domainIter != mDomains.end(); ++domainIter) - { - if (domainIter->domainID == domainID) - { - domainIter->state = domainState; - break; - } - } - pthread_mutex_unlock(&mDomainsMutex); -} - -void am::AsyncRoutingSender::updateDomainListSafe(std::vector listDomains) -{ - pthread_mutex_lock(&mDomainsMutex); - mDomains = listDomains; - pthread_mutex_unlock(&mDomainsMutex); -} - -void am::AsyncRoutingSender::updateSourceListSafe(std::vector listSource) -{ - pthread_mutex_lock(&mSourcesMutex); - mSources = listSource; - pthread_mutex_unlock(&mSourcesMutex); -} - -void am::AsyncRoutingSender::updateSinkListSafe(std::vector listSinks) -{ - pthread_mutex_lock(&mSinksMutex); - mSinks = listSinks; - pthread_mutex_unlock(&mSinksMutex); -} - -void AsyncRoutingSender::getInterfaceVersion(std::string & version) const -{ - version = RoutingSendVersion; -} - -am_Error_e AsyncRoutingSender::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) -{ - //todo: implement - (void) handle; - (void) sourceID; - (void) listSoundProperties; - return (E_NOT_USED); -} - -am_Error_e AsyncRoutingSender::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) -{ - //todo: implement - (void) handle; - (void) sinkID; - (void) listSoundProperties; - return (E_NOT_USED); -} - -std::vector AsyncRoutingSender::createGatewayTable() -{ - std::vector table; - am_Gateway_s item; - item.name = "myGateway"; - item.sinkID = 2; - item.sourceID = 2; - table.push_back(item); - return (table); -} - -asycConnectWorker::asycConnectWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mHandle(handle), // - mConnectionID(connectionID), // - mSourceID(sourceID), // - mSinkID(sinkID), // - mConnectionFormat(connectionFormat) -{ -} - -void asycConnectWorker::start2work() -{ - logInfo("Start connecting"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - am_RoutingElement_s route; - route.sinkID = mSinkID; - route.sourceID = mSourceID; - route.connectionFormat = mConnectionFormat; - - //enter new connectionID into the list - mAsyncSender->insertConnectionSafe(mConnectionID, route); - - //send the ack - mShadow->ackConnect(mHandle, mConnectionID, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asycConnectWorker::cancelWork() -{ - mAsyncSender->removeHandleSafe(mHandle.handle); - mShadow->ackConnect(mHandle, mConnectionID, E_ABORTED); -} - -asycDisConnectWorker::asycDisConnectWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_Handle_s handle, const am_connectionID_t connectionID) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mHandle(handle), // - mConnectionID(connectionID) -{ -} - -void asycDisConnectWorker::start2work() -{ - logInfo("Start disconnecting"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - am_RoutingElement_s route; - - //enter new connectionID into the list - mAsyncSender->insertConnectionSafe(mConnectionID, route); - - //send the ack - mShadow->ackDisconnect(mHandle, mConnectionID, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); - -} - -void asycDisConnectWorker::cancelWork() -{ - mAsyncSender->removeHandleSafe(mHandle.handle); - mShadow->ackDisconnect(mHandle, mConnectionID, E_ABORTED); -} - -asyncSetSinkVolumeWorker::asyncSetSinkVolumeWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mCurrentVolume(currentVolume), // - mHandle(handle), // - mSinkID(sinkID), // - mVolume(volume), // - mRamp(ramp), // - mTime(time) -{ -} - -void asyncSetSinkVolumeWorker::start2work() -{ - //todo: this implementation does not respect time and ramp.... - logInfo("Start setting sink volume"); - timespec t; - t.tv_nsec = 10000000; - t.tv_sec = 0; - - while (mCurrentVolume != mVolume) - { - if (mCurrentVolume < mVolume) - mCurrentVolume++; - else - mCurrentVolume--; - mShadow->ackSinkVolumeTick(mHandle, mSinkID, mCurrentVolume); - if (timedWait(t)) - return; - } - - //enter new connectionID into the list - mAsyncSender->updateSinkVolumeSafe(mSinkID, mCurrentVolume); - - //send the ack - mShadow->ackSetSinkVolumeChange(mHandle, mCurrentVolume, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asyncSetSinkVolumeWorker::cancelWork() -{ - mAsyncSender->updateSinkVolumeSafe(mSinkID, mCurrentVolume); - mAsyncSender->removeHandleSafe(mHandle.handle); - mShadow->ackSetSinkVolumeChange(mHandle, mCurrentVolume, E_ABORTED); -} - -asyncSetSourceVolumeWorker::asyncSetSourceVolumeWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_volume_t currentVolume, const am_Handle_s handle, const am_sourceID_t SourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mCurrentVolume(currentVolume), // - mHandle(handle), // - mSourceID(SourceID), // - mVolume(volume), // - mRamp(ramp), // - mTime(time) -{ -} - -void asyncSetSourceVolumeWorker::start2work() -{ - //todo: this implementation does not respect time and ramp.... - logInfo("Start setting source volume"); - timespec t; - t.tv_nsec = 10000000; - t.tv_sec = 0; - - while (mCurrentVolume != mVolume) - { - if (mCurrentVolume < mVolume) - mCurrentVolume++; - else - mCurrentVolume--; - mShadow->ackSourceVolumeTick(mHandle, mSourceID, mCurrentVolume); - if (timedWait(t)) - return; - } - - //enter new connectionID into the list - mAsyncSender->updateSourceVolumeSafe(mSourceID, mCurrentVolume); - - //send the ack - mShadow->ackSetSourceVolumeChange(mHandle, mCurrentVolume, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asyncSetSourceVolumeWorker::cancelWork() -{ - mAsyncSender->updateSourceVolumeSafe(mSourceID, mCurrentVolume); - mAsyncSender->removeHandleSafe(mHandle.handle); - mShadow->ackSetSourceVolumeChange(mHandle, mCurrentVolume, E_ABORTED); -} - -asyncSetSourceStateWorker::asyncSetSourceStateWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mHandle(handle), // - mSourceID(sourceID), // - mSourcestate(state) -{ -} - -void asyncSetSourceStateWorker::start2work() -{ - logInfo("Start setting source state"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - - //enter new connectionID into the list - mAsyncSender->updateSourceStateSafe(mSourceID, mSourcestate); - - //send the ack - mShadow->ackSetSourceState(mHandle, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asyncSetSourceStateWorker::cancelWork() -{ - //send the ack - mShadow->ackSetSourceState(mHandle, E_ABORTED); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -asyncSetSinkSoundPropertyWorker::asyncSetSinkSoundPropertyWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sinkID_t sinkID) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mHandle(handle), // - mSinkID(sinkID), // - mSoundProperty(soundProperty) -{ -} - -void asyncSetSinkSoundPropertyWorker::start2work() -{ - logInfo("Start setting sink sound property"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - - //enter new connectionID into the list - mAsyncSender->updateSinkSoundPropertySafe(mSinkID, mSoundProperty); - - //send the ack - mShadow->ackSetSinkSoundProperty(mHandle, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asyncSetSinkSoundPropertyWorker::cancelWork() -{ - //send the ack - mShadow->ackSetSinkSoundProperty(mHandle, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -asyncSetSourceSoundPropertyWorker::asyncSetSourceSoundPropertyWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sourceID_t sourceID) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mHandle(handle), // - mSourceID(sourceID), // - mSoundProperty(soundProperty) -{ -} - -void asyncSetSourceSoundPropertyWorker::start2work() -{ - logInfo("Start setting source sound property"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - - //enter new connectionID into the list - mAsyncSender->updateSourceSoundPropertySafe(mSourceID, mSoundProperty); - - //send the ack - mShadow->ackSetSourceSoundProperty(mHandle, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -void asyncSetSourceSoundPropertyWorker::cancelWork() -{ - //send the ack - mShadow->ackSetSourceSoundProperty(mHandle, E_OK); - - //destroy the handle - mAsyncSender->removeHandleSafe(mHandle.handle); -} - -asyncDomainStateChangeWorker::asyncDomainStateChangeWorker(AsyncRoutingSender *asyncSender, WorkerThreadPool *pool, RoutingReceiverAsyncShadow *shadow, const am_domainID_t domainID, const am_DomainState_e domainState) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mDomainID(domainID), // - mDomainState(domainState) -{ -} - -void asyncDomainStateChangeWorker::start2work() -{ - //todo: sendchanged data must be in here ! - logInfo("Start setting source sound property"); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 1; - - //do something for one second - if (timedWait(t)) - return; - - //enter new connectionID into the list - mAsyncSender->updateDomainstateSafe(mDomainID, mDomainState); - mShadow->hookDomainStateChange(mDomainID, mDomainState); - //send the new status - -} - -void am::asyncDomainStateChangeWorker::cancelWork() -{ - //send the new status - mShadow->hookDomainStateChange(mDomainID, mDomainState); -} - -syncRegisterWorker::syncRegisterWorker(AsyncRoutingSender * asyncSender, WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const std::vector domains, const std::vector sinks, const std::vector sources, const uint16_t handle) : - Worker(pool), // - mAsyncSender(asyncSender), // - mShadow(shadow), // - mListDomains(domains), // - mListSinks(sinks), // - mListSources(sources), - mHandle(handle) -{ -} - -void syncRegisterWorker::start2work() -{ - //todo: sendchanged data must be in here ! - logInfo("Start to register stuff"); - - am_Error_e eCode; - - std::vector::iterator domainIter = mListDomains.begin(); - for (; domainIter != mListDomains.end(); ++domainIter) - { - am_domainID_t domainID; - if ((eCode = mShadow->registerDomain(*domainIter, domainID)) != E_OK) - { - logError("syncRegisterWorker::start2work error on registering domain, failed with", eCode); - } - domainIter->domainID = domainID; - } - - mAsyncSender->updateDomainListSafe(mListDomains); - - //then sources - std::vector::iterator sourceIter = mListSources.begin(); - for (; sourceIter != mListSources.end(); ++sourceIter) - { - am_sourceID_t sourceID; - //set the correct domainID - sourceIter->domainID = mListDomains[0].domainID; - if ((eCode = mShadow->registerSource(*sourceIter, sourceID)) != E_OK) - { - logError("syncRegisterWorker::start2work error on registering source, failed with", eCode); - } - } - - mAsyncSender->updateSourceListSafe(mListSources); - - //sinks - std::vector::iterator sinkIter = mListSinks.begin(); - for (; sinkIter != mListSinks.end(); ++sinkIter) - { - am_sinkID_t sinkID; - //set the correct domainID - sinkIter->domainID = mListDomains[0].domainID; - if ((eCode = mShadow->registerSink(*sinkIter, sinkID)) != E_OK) - { - logError("syncRegisterWorker::start2work error on registering sink, failed with", eCode); - } - } - - mAsyncSender->updateSinkListSafe(mListSinks); - mShadow->confirmRoutingReady(mHandle); -} - -void syncRegisterWorker::cancelWork() -{ -} - diff --git a/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.cpp b/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.cpp new file mode 100644 index 0000000..2d3cbca --- /dev/null +++ b/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.cpp @@ -0,0 +1,518 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file testRoutingItnerfaceAsync.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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 "CAmRoutingReceiverAsync.h" +#include "config.h" +#include "CAmRoutingReceiver.h" +#include "TAmPluginTemplate.h" +#include "MockIAmRoutingReceive.h" +#include "shared/CAmDltWrapper.h" + +using namespace am; +using namespace testing; + +am_domainID_t CAmEnvironment::mDomainIDCount = 0; +static IAmRoutingSend* pRouter; +static CAmSocketHandler pSocketHandler; +static MockIAmRoutingReceive pReceiveInterface; + +CAmEnvironment::CAmEnvironment() : + ptimerCallback(this, &CAmEnvironment::timerCallback) +{ + DefaultValue::Set(E_OK); // Sets the default value to be returned. +} + +CAmEnvironment::~CAmEnvironment() +{ +} + +void CAmEnvironment::SetUp() +{ + logInfo("RoutingSendInterface Test started "); + + std::vector domainIDs; + domainIDs.push_back(0); + domainIDs.push_back(1); + + EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler), Return(E_OK))); + EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(CAmEnvironment::handleDomainRegister)); + EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(CAmEnvironment::handleSourceRegister)); + EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(CAmEnvironment::handleSinkRegister)); + EXPECT_CALL(pReceiveInterface,confirmRoutingReady(_)).Times(1); + + IAmRoutingSend* (*createFunc)(); + void* tempLibHandle = NULL; + std::string libname("../plugins/routing/libPluginRoutingInterfaceAsync.so"); + createFunc = getCreateFunction(libname, tempLibHandle); + + if (!createFunc) + { + logError("RoutingSendInterface Test Entry point of RoutingPlugin not found"); + exit(1); + } + + pRouter = createFunc(); + + if (!pRouter) + { + logError("RoutingSendInterface Test RoutingPlugin initialization failed. Entry Function not callable"); + exit(1); + } + + pRouter->startupInterface(&pReceiveInterface); + pRouter->setRoutingReady(10); + + timespec t; + t.tv_nsec = 0; + t.tv_sec = 2; + + sh_timerHandle_t handle; + + CAmShTimerCallBack *buf = &ptimerCallback; + //lets use a timeout so the test will finish + pSocketHandler.addTimer(t, buf, handle, (void*) NULL); + pSocketHandler.start_listenting(); + +} + +void CAmEnvironment::TearDown() +{ + +} + +CAmRoutingReceiverAsync::CAmRoutingReceiverAsync() : + ptimerCallback(this, &CAmRoutingReceiverAsync::timerCallback) +{ +} + +CAmRoutingReceiverAsync::~CAmRoutingReceiverAsync() +{ +} + +void CAmRoutingReceiverAsync::timerCallback(sh_timerHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + pSocketHandler.stop_listening(); +} + +void CAmRoutingReceiverAsync::SetUp() +{ +// timespec t; +// t.tv_nsec = 0; +// t.tv_sec = 2; +// +// sh_timerHandle_t handle; +// +// shTimerCallBack *buf = &ptimerCallback; +// //lets use a timeout so the test will finish +// pSocketHandler.addTimer(t, buf, handle, (void*) NULL); +} + +std::vector CAmEnvironment::returnListPlugins() +{ + std::vector list; + list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); + return (list); +} + +am_Error_e CAmEnvironment::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + sourceID = sourceData.sourceID; + return (E_OK); +} + +am_Error_e CAmEnvironment::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + sinkID = sinkData.sinkID; + return (E_OK); +} + +am_Error_e CAmEnvironment::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + am_Domain_s domain = domainData; + domainID = ++mDomainIDCount; + domain.domainID = domainID; + return (E_OK); +} + +void CAmEnvironment::timerCallback(sh_timerHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + pSocketHandler.stop_listening(); + timespec t; + t.tv_nsec = 0; + t.tv_sec = 2; + pSocketHandler.restartTimer(handle, t); +} + +void CAmRoutingReceiverAsync::TearDown() +{ +} + +TEST_F(CAmRoutingReceiverAsync,setDomainState) +{ + am_domainID_t domainID = 1; + am_DomainState_e state = DS_INDEPENDENT_RUNDOWN; + + EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1); + + ASSERT_EQ(E_OK, pRouter->setDomainState(domainID,state)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSourceSoundProperty) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSOURCESOUNDPROPERTY; + + am_sourceID_t sourceID = 3; + am_SoundProperty_s property; + property.type = SP_EXAMPLE_MID; + property.value = 24; + + EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSourceSoundProperty(handle,sourceID,property)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSinkSoundProperty) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSINKSOUNDPROPERTY; + + am_sinkID_t sinkID = 1; + am_SoundProperty_s property; + property.type = SP_EXAMPLE_MID; + property.value = 24; + + EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSinkSoundProperty(handle,sinkID,property)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSourceState) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSOURCESTATE; + + am_sourceID_t sourceID = 1; + am_SourceState_e state = SS_OFF; + + EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSourceState(handle,sourceID,state)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSourceVolume) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSOURCEVOLUME; + + am_sourceID_t sourceID = 3; + am_volume_t volume = 3; + am_RampType_e ramp = RAMP_GENIVI_DIRECT; + am_time_t myTime = 25; + + EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(AtLeast(1)); + EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSinkVolume) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSINKVOLUME; + + am_sinkID_t sinkID = 1; + am_volume_t volume = 9; + am_RampType_e ramp = RAMP_GENIVI_DIRECT; + am_time_t myTime = 25; + + EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(AtLeast(2)); + EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,setSinkVolumeAbort) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_SETSINKVOLUME; + + am_sinkID_t sinkID = 2; + am_volume_t volume = 25; + am_RampType_e ramp = RAMP_GENIVI_DIRECT; + am_time_t myTime = 25; + + EXPECT_CALL(pReceiveInterface, ackSinkVolumeTick(_,sinkID,_)); + EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1); + + ASSERT_EQ(E_OK, pRouter->asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime)); + sleep(0.5); + ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,disconnectNonExisting) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_DISCONNECT; + + am_connectionID_t connectionID = 4; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); + EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0); + ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncDisconnect(handle,connectionID)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,disconnectTooEarly) +{ + + am_Handle_s handle_c; + handle_c.handle = 1; + handle_c.handleType = H_CONNECT; + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_DISCONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); + EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); + ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncDisconnect(handle,connectionID)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,disconnectAbort) +{ + + am_Handle_s handle_c; + handle_c.handle = 1; + handle_c.handleType = H_CONNECT; + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_DISCONNECT; + + am_connectionID_t connectionID = 5; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); + EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_ABORTED)); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); + sleep(2); + ASSERT_EQ(E_OK, pRouter->asyncDisconnect(handle,connectionID)); + ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,disconnect) +{ + + am_Handle_s handle_c; + handle_c.handle = 1; + handle_c.handleType = H_CONNECT; + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_DISCONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); + EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_OK)); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); + sleep(2); + ASSERT_EQ(E_OK, pRouter->asyncDisconnect(handle,connectionID)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectNoMoreThreads) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 1; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10); + for (int i = 0; i < 9; i++) + { + handle.handle++; + connectionID++; + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + }ASSERT_EQ(E_NOT_POSSIBLE, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectAbortTooLate) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + sleep(3); + ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncAbort(handle)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectAbort) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + sleep(0.5); + ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectWrongFormat) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_MONO; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); + ASSERT_EQ(E_WRONG_FORMAT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectWrongSink) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 122; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); + ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connectWrongSource) +{ + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 25; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); + ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + pSocketHandler.start_listenting(); +} + +TEST_F(CAmRoutingReceiverAsync,connect) +{ + + am_Handle_s handle; + handle.handle = 1; + handle.handleType = H_CONNECT; + + am_connectionID_t connectionID = 4; + am_sourceID_t sourceID = 2; + am_sinkID_t sinkID = 1; + am_ConnectionFormat_e format = CF_GENIVI_ANALOG; + + EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); + ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); + pSocketHandler.start_listenting(); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new CAmEnvironment); + (void) env; + return RUN_ALL_TESTS(); +} + diff --git a/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.h b/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.h new file mode 100644 index 0000000..ec33c9f --- /dev/null +++ b/PluginRoutingInterfaceAsync/test/CAmRoutingReceiverAsync.h @@ -0,0 +1,73 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger AudioManagerDaemon + * + * \file testRoutingItnerfaceAsync.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + */ + +#ifndef TESTROUTINGINTERFACEASYNC_H_ +#define TESTROUTINGINTERFACEASYNC_H_ + +#include +#include + +#include "MockIAmRoutingReceive.h" +#include "shared/CAmSocketHandler.h" +#include "shared/CAmSerializer.h" +#include "../../AudioManagerDaemon/include/CAmRoutingSender.h" + +#define UNIT_TEST 1 + +namespace am +{ + +class CAmEnvironment: public ::testing::Environment +{ +public: + static std::vector returnListPlugins(); + static am_Error_e handleDomainRegister(const am_Domain_s& domainData, am_domainID_t& domainID); + static am_Error_e handleSourceRegister(const am_Source_s& sourceData, am_sourceID_t& sourceID); + static am_Error_e handleSinkRegister(const am_Sink_s& sinkData, am_sinkID_t& sinkID); + void timerCallback(sh_timerHandle_t handle, void* userData); + TAmShTimerCallBack ptimerCallback; + CAmEnvironment(); + ~CAmEnvironment(); + // Override this to define how to set up the environment. + void SetUp(); + // Override this to define how to tear down the environment. + void TearDown(); +private: + static am_domainID_t mDomainIDCount; +}; + +class CAmRoutingReceiverAsync: public ::testing::Test +{ +public: + CAmRoutingReceiverAsync(); + ~CAmRoutingReceiverAsync(); + void timerCallback(sh_timerHandle_t handle, void* userData); + TAmShTimerCallBack ptimerCallback; + void SetUp(); + void TearDown(); +private: +}; + +} /* namespace am */ +#endif /* TESTROUTINGINTERFACEASYNC_H_ */ diff --git a/PluginRoutingInterfaceAsync/test/CMakeLists.txt b/PluginRoutingInterfaceAsync/test/CMakeLists.txt index aa4c39d..59c50dc 100644 --- a/PluginRoutingInterfaceAsync/test/CMakeLists.txt +++ b/PluginRoutingInterfaceAsync/test/CMakeLists.txt @@ -23,7 +23,7 @@ cmake_minimum_required(VERSION 2.6) -PROJECT(routingAsyncTest) +PROJECT(AmRoutingReceiverAsync) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") @@ -40,10 +40,10 @@ INCLUDE_DIRECTORIES( ${STD_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} ${CMAKE_SOURCE_DIR} ${DLT_INCLUDE_DIRS} - ${INCLUDES_FOLDER} + ${include_FOLDER} ${GTEST_INCLUDE_DIR} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR} @@ -52,26 +52,17 @@ INCLUDE_DIRECTORIES( ) file(GLOB ASYNC_PLUGIN_INTERFACE_SRCS_CXX - "../../AudioManagerDaemon/src/SocketHandler.cpp" - "../../AudioManagerDaemon/src/DLTWrapper.cpp" + "../../AudioManagerDaemon/src/CAmSocketHandler.cpp" + "../../AudioManagerDaemon/src/CAmDltWrapper.cpp" "../src/*.cpp" - "testRoutingInterfaceAsync.cpp" + "CAmRoutingReceiverAsync.cpp" ) -file(GLOB ASYNC_PLUGIN_INTERFACE_INTERRUPT_SRCS_CXX - "../../AudioManagerDaemon/src/SocketHandler.cpp" - "../../AudioManagerDaemon/src/RoutingSender.cpp" - "../../AudioManagerDaemon/src/DLTWrapper.cpp" - "../src/*.cpp" - "testRoutingInterfaceAsyncInterrupt.cpp" - -) -ADD_EXECUTABLE(asyncRoutingInterfaceTest ${ASYNC_PLUGIN_INTERFACE_SRCS_CXX}) -#ADD_EXECUTABLE(asyncRoutingInterfaceInterruptTest ${ASYNC_PLUGIN_INTERFACE_INTERRUPT_SRCS_CXX}) +ADD_EXECUTABLE(AmRoutingReceiveAsyncTest ${ASYNC_PLUGIN_INTERFACE_SRCS_CXX}) -TARGET_LINK_LIBRARIES(asyncRoutingInterfaceTest +TARGET_LINK_LIBRARIES(AmRoutingReceiveAsyncTest ${DLT_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} @@ -81,16 +72,7 @@ TARGET_LINK_LIBRARIES(asyncRoutingInterfaceTest gmock ) -#TARGET_LINK_LIBRARIES(asyncRoutingInterfaceInterruptTest -# ${DLT_LIBRARIES} -# ${CMAKE_DL_LIBS} -# ${CMAKE_THREAD_LIBS_INIT} -# ${GTEST_LIBRARIES} -# ${DBUS_LIBRARY} -# gmock -#) - -INSTALL(TARGETS asyncRoutingInterfaceTest +INSTALL(TARGETS AmRoutingReceiveAsyncTest DESTINATION "~/AudioManagerTest/" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ COMPONENT tests diff --git a/PluginRoutingInterfaceAsync/test/MockIAmRoutingReceive.h b/PluginRoutingInterfaceAsync/test/MockIAmRoutingReceive.h new file mode 100644 index 0000000..145afd4 --- /dev/null +++ b/PluginRoutingInterfaceAsync/test/MockIAmRoutingReceive.h @@ -0,0 +1,91 @@ +#ifndef MOCKROUTINGINTERFACE_H_ +#define MOCKROUTINGINTERFACE_H_ + +#include "routing/IAmRoutingReceive.h" + +namespace am { + +class MockIAmRoutingReceive : public IAmRoutingReceive { + public: + MOCK_METHOD3(ackConnect, + void(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)); + MOCK_METHOD3(ackDisconnect, + void(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)); + MOCK_METHOD3(ackSetSinkVolumeChange, + void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); + MOCK_METHOD3(ackSetSourceVolumeChange, + void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); + MOCK_METHOD2(ackSetSourceState, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(ackSetSinkSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(ackSetSinkSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(ackSetSourceSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(ackSetSourceSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD3(ackCrossFading, + void(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)); + MOCK_METHOD3(ackSourceVolumeTick, + void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); + MOCK_METHOD3(ackSinkVolumeTick, + void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); + MOCK_METHOD2(peekDomain, + am_Error_e(const std::string& name, am_domainID_t& domainID)); + MOCK_METHOD2(registerDomain, + am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); + MOCK_METHOD1(deregisterDomain, + am_Error_e(const am_domainID_t domainID)); + MOCK_METHOD2(registerGateway, + am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); + MOCK_METHOD1(deregisterGateway, + am_Error_e(const am_gatewayID_t gatewayID)); + MOCK_METHOD2(peekSink, + am_Error_e(const std::string& name, am_sinkID_t& sinkID)); + MOCK_METHOD2(registerSink, + am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); + MOCK_METHOD1(deregisterSink, + am_Error_e(const am_sinkID_t sinkID)); + MOCK_METHOD2(peekSource, + am_Error_e(const std::string& name, am_sourceID_t& sourceID)); + MOCK_METHOD2(registerSource, + am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); + MOCK_METHOD1(deregisterSource, + am_Error_e(const am_sourceID_t sourceID)); + MOCK_METHOD2(registerCrossfader, + am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); + MOCK_METHOD1(deregisterCrossfader, + am_Error_e(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD2(peekSourceClassID, + am_Error_e(const std::string& name, am_sourceClass_t& sourceClassID)); + MOCK_METHOD2(peekSinkClassID, + am_Error_e(const std::string& name, am_sinkClass_t& sinkClassID)); + MOCK_METHOD2(hookInterruptStatusChange, + void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); + MOCK_METHOD1(hookDomainRegistrationComplete, + void(const am_domainID_t domainID)); + MOCK_METHOD2(hookSinkAvailablityStatusChange, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSourceAvailablityStatusChange, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(hookDomainStateChange, + void(const am_domainID_t domainID, const am_DomainState_e domainState)); + MOCK_METHOD2(hookTimingInformationChanged, + void(const am_connectionID_t connectionID, const am_timeSync_t delay)); + MOCK_METHOD1(sendChangedData, + void(const std::vector& earlyData)); + MOCK_CONST_METHOD1(getDBusConnectionWrapper, + am_Error_e(CAmDbusWrapper*& dbusConnectionWrapper)); + MOCK_CONST_METHOD1(getSocketHandler, + am_Error_e(CAmSocketHandler*& socketHandler)); + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(confirmRoutingReady, + void(const uint16_t handle)); + MOCK_METHOD1(confirmRoutingRundown, + void(const uint16_t handle)); +}; + +} // namespace am +#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/PluginRoutingInterfaceAsync/test/mocklnterfaces.h b/PluginRoutingInterfaceAsync/test/mocklnterfaces.h deleted file mode 100644 index d8eef1f..0000000 --- a/PluginRoutingInterfaceAsync/test/mocklnterfaces.h +++ /dev/null @@ -1,119 +0,0 @@ -/** -* Copyright (C) 2011, BMW AG -* -* GeniviAudioMananger AudioManagerDaemon -* -* \file mockInterfaces.h -* -* \date 20-Oct-2011 3:42:04 PM -* \author Christian Mueller (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 Mueller 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 . -* 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. -* -*/ - -#ifndef MOCKLNTERFACES_H_ -#define MOCKLNTERFACES_H_ - -#include - -namespace am { - -class MockRoutingReceiveInterface : public RoutingReceiveInterface { - public: - MOCK_METHOD3(ackConnect, - void(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)); - MOCK_METHOD3(ackDisconnect, - void(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)); - MOCK_METHOD3(ackSetSinkVolumeChange, - void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); - MOCK_METHOD3(ackSetSourceVolumeChange, - void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); - MOCK_METHOD2(ackSetSourceState, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(ackSetSinkSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(ackSetSinkSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(ackSetSourceSoundProperties, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(ackSetSourceSoundProperty, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD3(ackCrossFading, - void(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)); - MOCK_METHOD3(ackSourceVolumeTick, - void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); - MOCK_METHOD3(ackSinkVolumeTick, - void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); - MOCK_METHOD2(peekDomain, - am_Error_e(const std::string& name, am_domainID_t& domainID)); - MOCK_METHOD2(registerDomain, - am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); - MOCK_METHOD1(deregisterDomain, - am_Error_e(const am_domainID_t domainID)); - MOCK_METHOD2(registerGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(deregisterGateway, - am_Error_e(const am_gatewayID_t gatewayID)); - MOCK_METHOD2(peekSink, - am_Error_e(const std::string& name, am_sinkID_t& sinkID)); - MOCK_METHOD2(registerSink, - am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); - MOCK_METHOD1(deregisterSink, - am_Error_e(const am_sinkID_t sinkID)); - MOCK_METHOD2(peekSource, - am_Error_e(const std::string& name, am_sourceID_t& sourceID)); - MOCK_METHOD2(registerSource, - am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); - MOCK_METHOD1(deregisterSource, - am_Error_e(const am_sourceID_t sourceID)); - MOCK_METHOD2(registerCrossfader, - am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); - MOCK_METHOD1(deregisterCrossfader, - am_Error_e(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD2(peekSourceClassID, - am_Error_e(const std::string& name, am_sourceClass_t& sourceClassID)); - MOCK_METHOD2(peekSinkClassID, - am_Error_e(const std::string& name, am_sinkClass_t& sinkClassID)); - MOCK_METHOD2(hookInterruptStatusChange, - void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); - MOCK_METHOD1(hookDomainRegistrationComplete, - void(const am_domainID_t domainID)); - MOCK_METHOD2(hookSinkAvailablityStatusChange, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSourceAvailablityStatusChange, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(hookDomainStateChange, - void(const am_domainID_t domainID, const am_DomainState_e domainState)); - MOCK_METHOD2(hookTimingInformationChanged, - void(const am_connectionID_t connectionID, const am_timeSync_t delay)); - MOCK_METHOD1(sendChangedData, - void(const std::vector& earlyData)); - MOCK_CONST_METHOD1(getDBusConnectionWrapper, - am_Error_e(DBusWrapper*& dbusConnectionWrapper)); - MOCK_CONST_METHOD1(getSocketHandler, - am_Error_e(SocketHandler*& socketHandler)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD1(confirmRoutingReady, - void(const uint16_t handle)); - MOCK_METHOD1(confirmRoutingRundown, - void(const uint16_t handle)); - - }; - -} // namespace am - - - -#endif /* MOCKLNTERFACES_H_ */ diff --git a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.cpp b/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.cpp deleted file mode 100644 index 1e672a6..0000000 --- a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file testRoutingItnerfaceAsync.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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 "testRoutingInterfaceAsync.h" -#include "config.h" -#include "DLTWrapper.h" -#include "RoutingReceiver.h" -#include "PluginTemplate.h" - -using namespace am; -using namespace testing; - -am_domainID_t MyEnvironment::mDomainIDCount = 0; -static RoutingSendInterface* pRouter; -static SocketHandler pSocketHandler; -static MockRoutingReceiveInterface pReceiveInterface; - -MyEnvironment::MyEnvironment() : - ptimerCallback(this, &MyEnvironment::timerCallback) -{ - DefaultValue::Set(E_OK); // Sets the default value to be returned. -} - -MyEnvironment::~MyEnvironment() -{ -} - -void MyEnvironment::SetUp() -{ - logInfo("RoutingSendInterface Test started "); - - std::vector domainIDs; - domainIDs.push_back(0); - domainIDs.push_back(1); - - EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler), Return(E_OK))); - EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(MyEnvironment::handleDomainRegister)); - EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(MyEnvironment::handleSourceRegister)); - EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(MyEnvironment::handleSinkRegister)); - EXPECT_CALL(pReceiveInterface,confirmRoutingReady(_)).Times(1); - - RoutingSendInterface* (*createFunc)(); - void* tempLibHandle = NULL; - std::string libname("../plugins/routing/libPluginRoutingInterfaceAsync.so"); - createFunc = getCreateFunction(libname, tempLibHandle); - - if (!createFunc) - { - logError("RoutingSendInterface Test Entry point of RoutingPlugin not found"); - exit(1); - } - - pRouter = createFunc(); - - if (!pRouter) - { - logError("RoutingSendInterface Test RoutingPlugin initialization failed. Entry Function not callable"); - exit(1); - } - - pRouter->startupInterface(&pReceiveInterface); - pRouter->setRoutingReady(10); - - timespec t; - t.tv_nsec = 0; - t.tv_sec = 2; - - sh_timerHandle_t handle; - - shTimerCallBack *buf = &ptimerCallback; - //lets use a timeout so the test will finish - pSocketHandler.addTimer(t, buf, handle, (void*) NULL); - pSocketHandler.start_listenting(); - -} - -void MyEnvironment::TearDown() -{ - -} - -testRoutingInterfaceAsync::testRoutingInterfaceAsync() : - ptimerCallback(this, &testRoutingInterfaceAsync::timerCallback) -{ -} - -testRoutingInterfaceAsync::~testRoutingInterfaceAsync() -{ -} - -void testRoutingInterfaceAsync::timerCallback(sh_timerHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - pSocketHandler.stop_listening(); -} - -void testRoutingInterfaceAsync::SetUp() -{ -// timespec t; -// t.tv_nsec = 0; -// t.tv_sec = 2; -// -// sh_timerHandle_t handle; -// -// shTimerCallBack *buf = &ptimerCallback; -// //lets use a timeout so the test will finish -// pSocketHandler.addTimer(t, buf, handle, (void*) NULL); -} - -std::vector MyEnvironment::returnListPlugins() -{ - std::vector list; - list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); - return (list); -} - -am_Error_e MyEnvironment::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - sourceID = sourceData.sourceID; - return (E_OK); -} - -am_Error_e MyEnvironment::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - sinkID = sinkData.sinkID; - return (E_OK); -} - -am_Error_e MyEnvironment::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - am_Domain_s domain = domainData; - domainID = ++mDomainIDCount; - domain.domainID = domainID; - return (E_OK); -} - -void MyEnvironment::timerCallback(sh_timerHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - pSocketHandler.stop_listening(); - timespec t; - t.tv_nsec = 0; - t.tv_sec = 2; - pSocketHandler.restartTimer(handle, t); -} - -void testRoutingInterfaceAsync::TearDown() -{ -} - -TEST_F(testRoutingInterfaceAsync,setDomainState) -{ - am_domainID_t domainID = 1; - am_DomainState_e state = DS_INDEPENDENT_RUNDOWN; - - EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1); - - ASSERT_EQ(E_OK, pRouter->setDomainState(domainID,state)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSourceSoundProperty) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSOURCESOUNDPROPERTY; - - am_sourceID_t sourceID = 3; - am_SoundProperty_s property; - property.type = SP_EXAMPLE_MID; - property.value = 24; - - EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSourceSoundProperty(handle,sourceID,property)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSinkSoundProperty) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSINKSOUNDPROPERTY; - - am_sinkID_t sinkID = 1; - am_SoundProperty_s property; - property.type = SP_EXAMPLE_MID; - property.value = 24; - - EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSinkSoundProperty(handle,sinkID,property)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSourceState) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSOURCESTATE; - - am_sourceID_t sourceID = 1; - am_SourceState_e state = SS_OFF; - - EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSourceState(handle,sourceID,state)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSourceVolume) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSOURCEVOLUME; - - am_sourceID_t sourceID = 3; - am_volume_t volume = 3; - am_RampType_e ramp = RAMP_GENIVI_DIRECT; - am_time_t myTime = 25; - - EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(AtLeast(1)); - EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSinkVolume) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSINKVOLUME; - - am_sinkID_t sinkID = 1; - am_volume_t volume = 9; - am_RampType_e ramp = RAMP_GENIVI_DIRECT; - am_time_t myTime = 25; - - EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(AtLeast(2)); - EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,setSinkVolumeAbort) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_SETSINKVOLUME; - - am_sinkID_t sinkID = 2; - am_volume_t volume = 25; - am_RampType_e ramp = RAMP_GENIVI_DIRECT; - am_time_t myTime = 25; - - EXPECT_CALL(pReceiveInterface, ackSinkVolumeTick(_,sinkID,_)); - EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1); - - ASSERT_EQ(E_OK, pRouter->asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime)); - sleep(0.5); - ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,disconnectNonExisting) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_DISCONNECT; - - am_connectionID_t connectionID = 4; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); - EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0); - ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncDisconnect(handle,connectionID)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,disconnectTooEarly) -{ - - am_Handle_s handle_c; - handle_c.handle = 1; - handle_c.handleType = H_CONNECT; - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_DISCONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); - EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); - ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncDisconnect(handle,connectionID)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,disconnectAbort) -{ - - am_Handle_s handle_c; - handle_c.handle = 1; - handle_c.handleType = H_CONNECT; - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_DISCONNECT; - - am_connectionID_t connectionID = 5; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); - EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_ABORTED)); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); - sleep(2); - ASSERT_EQ(E_OK, pRouter->asyncDisconnect(handle,connectionID)); - ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,disconnect) -{ - - am_Handle_s handle_c; - handle_c.handle = 1; - handle_c.handleType = H_CONNECT; - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_DISCONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); - EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_OK)); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle_c,connectionID,sourceID,sinkID,format)); - sleep(2); - ASSERT_EQ(E_OK, pRouter->asyncDisconnect(handle,connectionID)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectNoMoreThreads) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 1; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10); - for (int i = 0; i < 9; i++) - { - handle.handle++; - connectionID++; - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - }ASSERT_EQ(E_NOT_POSSIBLE, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectAbortTooLate) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - sleep(3); - ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncAbort(handle)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectAbort) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - sleep(0.5); - ASSERT_EQ(E_OK, pRouter->asyncAbort(handle)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectWrongFormat) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_MONO; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); - ASSERT_EQ(E_WRONG_FORMAT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectWrongSink) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 122; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); - ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connectWrongSource) -{ - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 25; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0); - ASSERT_EQ(E_NON_EXISTENT, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,connect) -{ - - am_Handle_s handle; - handle.handle = 1; - handle.handleType = H_CONNECT; - - am_connectionID_t connectionID = 4; - am_sourceID_t sourceID = 2; - am_sinkID_t sinkID = 1; - am_ConnectionFormat_e format = CF_GENIVI_ANALOG; - - EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK)); - ASSERT_EQ(E_OK, pRouter->asyncConnect(handle,connectionID,sourceID,sinkID,format)); - pSocketHandler.start_listenting(); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new MyEnvironment); - (void) env; - return RUN_ALL_TESTS(); -} - diff --git a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.h b/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.h deleted file mode 100644 index 3139b5a..0000000 --- a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsync.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file testRoutingItnerfaceAsync.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef TESTROUTINGINTERFACEASYNC_H_ -#define TESTROUTINGINTERFACEASYNC_H_ - -#include -#include -#include "mocklnterfaces.h" -#include "SocketHandler.h" -#include "../../AudioManagerDaemon/include/RoutingSender.h" -#include "CAmSerializer.h" - -#define UNIT_TEST 1 - -namespace am -{ - -class MyEnvironment: public ::testing::Environment -{ -public: - static std::vector returnListPlugins(); - static am_Error_e handleDomainRegister(const am_Domain_s& domainData, am_domainID_t& domainID); - static am_Error_e handleSourceRegister(const am_Source_s& sourceData, am_sourceID_t& sourceID); - static am_Error_e handleSinkRegister(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - void timerCallback(sh_timerHandle_t handle, void* userData); - shTimerCallBack_T ptimerCallback; - MyEnvironment(); - ~MyEnvironment(); - // Override this to define how to set up the environment. - void SetUp(); - // Override this to define how to tear down the environment. - void TearDown(); -private: - static am_domainID_t mDomainIDCount; -}; - -class testRoutingInterfaceAsync: public ::testing::Test -{ -public: - testRoutingInterfaceAsync(); - ~testRoutingInterfaceAsync(); - void timerCallback(sh_timerHandle_t handle, void* userData); - shTimerCallBack_T ptimerCallback; - void SetUp(); - void TearDown(); -private: -}; - -} /* namespace am */ -#endif /* TESTROUTINGINTERFACEASYNC_H_ */ diff --git a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsyncInterrupt.cpp b/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsyncInterrupt.cpp deleted file mode 100644 index e00de40..0000000 --- a/PluginRoutingInterfaceAsync/test/testRoutingInterfaceAsyncInterrupt.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file testRoutingItnerfaceAsyncInterrupt.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#define INTERRUPT_TEST 1 - -#include "testRoutingInterfaceAsync.h" -#include "config.h" -#include "DLTWrapper.h" - -using namespace am; -using namespace testing; - -std::vector testRoutingInterfaceAsync::pListRoutingPluginDirs = returnListPlugins(); -am_domainID_t testRoutingInterfaceAsync::mDomainIDCount = 0; -RoutingSender testRoutingInterfaceAsync::pRoutingSender = RoutingSender(pListRoutingPluginDirs); - -testRoutingInterfaceAsync::testRoutingInterfaceAsync() : - pSocketHandler(), // - pReceiveInterface(), // - ptimerCallback(this, &testRoutingInterfaceAsync::timerCallback) -{ -} - -testRoutingInterfaceAsync::~testRoutingInterfaceAsync() -{ -} - -void testRoutingInterfaceAsync::SetUp() -{ - logInfo("RoutingSendInterface Test started "); - - std::vector domainIDs; - domainIDs.push_back(0); - domainIDs.push_back(1); - - EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler), Return(E_OK))); - EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleDomainRegister)); - EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSourceRegister)); - EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSinkRegister)); - - //pRoutingSender.startupRoutingInterface(&pReceiveInterface); - //pRoutingSender.routingInterfacesReady(); - - timespec t; - t.tv_nsec = 0; - t.tv_sec = 4; - - sh_timerHandle_t handle; - - shTimerCallBack *buf = &ptimerCallback; - //lets use a timeout so the test will finish - pSocketHandler.addTimer(t, buf, handle, (void*) NULL); -} - -std::vector am::testRoutingInterfaceAsync::returnListPlugins() -{ - std::vector list; - list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); - return (list); -} - -am_Error_e am::testRoutingInterfaceAsync::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - sourceID = sourceData.sourceID; - pRoutingSender.addSourceLookup(sourceData); - return (E_OK); -} - -am_Error_e am::testRoutingInterfaceAsync::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - sinkID = sinkData.sinkID; - pRoutingSender.addSinkLookup(sinkData); - return (E_OK); -} - -am_Error_e am::testRoutingInterfaceAsync::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - am_Domain_s domain = domainData; - domainID = mDomainIDCount++; - domain.domainID = domainID; - pRoutingSender.addDomainLookup(domain); - return (E_OK); -} - -void testRoutingInterfaceAsync::timerCallback(sh_timerHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - pSocketHandler.stop_listening(); -} - -void testRoutingInterfaceAsync::TearDown() -{ -} - -std::string DBUSCOMMAND = "dbus-send --session --print-reply --dest=org.genivi.test /org/genivi/test org.genivi.test."; - -TEST_F(testRoutingInterfaceAsync,hookInterruptStatusChange) -{ - am_sourceID_t sourceID = 2; - EXPECT_CALL(pReceiveInterface,hookInterruptStatusChange(sourceID,_)).Times(1); - system((DBUSCOMMAND + std::string("InterruptStatusChange int16:2")).c_str()); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,hookSourceAvailablityStatusChange) -{ - am_sourceID_t sourceID = 2; - EXPECT_CALL(pReceiveInterface,hookSourceAvailablityStatusChange(sourceID,_)).Times(1); - system((DBUSCOMMAND + std::string("SourceAvailablityStatusChange int16:2")).c_str()); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,hookSinkAvailablityStatusChange) -{ - am_sinkID_t sinkID = 2; - EXPECT_CALL(pReceiveInterface,hookSinkAvailablityStatusChange(sinkID,_)).Times(1); - system((DBUSCOMMAND + std::string("SinkAvailablityStatusChange int16:2")).c_str()); - pSocketHandler.start_listenting(); -} - -TEST_F(testRoutingInterfaceAsync,hookTimingInformationChanged) -{ - am_connectionID_t connectionID = 4; - am_timeSync_t delay = 35; - EXPECT_CALL(pReceiveInterface,hookTimingInformationChanged(connectionID,delay)).Times(1); - system((DBUSCOMMAND + std::string("timingChanged int16:4 int16:35")).c_str()); - pSocketHandler.start_listenting(); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/PluginRoutingInterfaceDbus/CMakeLists.txt b/PluginRoutingInterfaceDbus/CMakeLists.txt index 5bf20aa..5242f51 100644 --- a/PluginRoutingInterfaceDbus/CMakeLists.txt +++ b/PluginRoutingInterfaceDbus/CMakeLists.txt @@ -4,11 +4,11 @@ PROJECT(PluginRoutingInterfaceDbus) set(LIBRARY_OUTPUT_PATH ${PLUGINS_OUTPUT_PATH}/routing) set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/RoutingPlugin) -set(INCLUDES_FOLDER "include") +set(include_FOLDER "include") -FILE(READ "${AUDIO_INCLUDES_FOLDER}/routing/RoutingSendInterface.h" VERSION_BUFFER LIMIT 6000) +FILE(READ "${AUDIO_include_FOLDER}/routing/IAmRoutingSend.h" VERSION_BUFFER LIMIT 6000) STRING(REGEX MATCH "RoutingSendVersion*.[^0-9]*[0-9].[0-9]*[0-9]" LIB_INTERFACE_VERSION_STRING ${VERSION_BUFFER}) -STRING(REGEX REPLACE "RoutingSendVersion*." "" LIB_INTERFACE_VERSION ${LIB_INTERFACE_VERSION_STRING}) +STRING(REGEX REPLACE "RoutingSendVersion*.." "" LIB_INTERFACE_VERSION ${LIB_INTERFACE_VERSION_STRING}) MESSAGE(STATUS "Building against routing interface version ${LIB_INTERFACE_VERSION}") FIND_PACKAGE(DBUS REQUIRED) @@ -18,8 +18,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR} - ${AUDIO_INCLUDES_FOLDER} - ${INCLUDES_FOLDER} + ${AUDIO_include_FOLDER} + ${include_FOLDER} ) # all source files go here diff --git a/PluginRoutingInterfaceDbus/include/CAmRoutingSenderDbus.h b/PluginRoutingInterfaceDbus/include/CAmRoutingSenderDbus.h new file mode 100644 index 0000000..6e27a31 --- /dev/null +++ b/PluginRoutingInterfaceDbus/include/CAmRoutingSenderDbus.h @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmRoutingSender.h + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#ifndef ROUTINGSENDER_H_ +#define ROUTINGSENDER_H_ + +#include "routing/IAmRoutingSend.h" + +using namespace am; + +class CAmRoutingSenderDbus: public IAmRoutingSend +{ +public: + CAmRoutingSenderDbus(); + virtual ~CAmRoutingSenderDbus(); + am_Error_e startupInterface(IAmRoutingReceive* routingreceiveinterface) ; + void setRoutingReady(const uint16_t handle) ; + void setRoutingRundown(const uint16_t handle) ; + am_Error_e asyncAbort(const am_Handle_s handle) ; + am_Error_e asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) ; + am_Error_e asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) ; + am_Error_e asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) ; + am_Error_e asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) ; + am_Error_e asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) ; + am_Error_e asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties) ; + am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) ; + am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) ; + am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) ; + am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) ; + am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) ; + am_Error_e returnBusName(std::string& BusName) const ; + void getInterfaceVersion(std::string& version) const ; +}; + +#endif /* ROUTINGSENDER_H_ */ diff --git a/PluginRoutingInterfaceDbus/include/RoutingSender.h b/PluginRoutingInterfaceDbus/include/RoutingSender.h deleted file mode 100644 index 276bd1e..0000000 --- a/PluginRoutingInterfaceDbus/include/RoutingSender.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file RoutingSender.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef ROUTINGSENDER_H_ -#define ROUTINGSENDER_H_ - -#include - -using namespace am; - -class DbusRoutingSender: public RoutingSendInterface -{ -public: - DbusRoutingSender(); - virtual ~DbusRoutingSender(); - am_Error_e startupInterface(RoutingReceiveInterface* routingreceiveinterface) ; - void setRoutingReady(const uint16_t handle) ; - void setRoutingRundown(const uint16_t handle) ; - am_Error_e asyncAbort(const am_Handle_s handle) ; - am_Error_e asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) ; - am_Error_e asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) ; - am_Error_e asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) ; - am_Error_e asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) ; - am_Error_e asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) ; - am_Error_e asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties) ; - am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) ; - am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) ; - am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) ; - am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) ; - am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) ; - am_Error_e returnBusName(std::string& BusName) const ; - void getInterfaceVersion(std::string& version) const ; -}; - -#endif /* ROUTINGSENDER_H_ */ diff --git a/PluginRoutingInterfaceDbus/src/CAmRoutingSenderDbus.cpp b/PluginRoutingInterfaceDbus/src/CAmRoutingSenderDbus.cpp new file mode 100644 index 0000000..53d4380 --- /dev/null +++ b/PluginRoutingInterfaceDbus/src/CAmRoutingSenderDbus.cpp @@ -0,0 +1,174 @@ +/** + * Copyright (C) 2011, BMW AG + * + * GeniviAudioMananger DbusPlugin + * + * \file CAmRoutingSender.cpp + * + * \date 20-Oct-2011 3:42:04 PM + * \author Christian Mueller (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 Mueller 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 . + * 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. + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ + +#include "CAmRoutingSenderDbus.h" + +extern "C" IAmRoutingSend* PluginRoutingInterfaceDbusFactory() +{ + return (new CAmRoutingSenderDbus()); +} + +extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface) +{ + delete routingSendInterface; +} + +CAmRoutingSenderDbus::CAmRoutingSenderDbus() +{ +} + +CAmRoutingSenderDbus::~CAmRoutingSenderDbus() +{ +} + +am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle) +{ + (void) handle; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) +{ + (void) handle; + (void) connectionID; + (void) sourceID; + (void) sinkID; + (void) connectionFormat; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) +{ + (void) handle; + (void) connectionID; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + (void) handle; + (void) sinkID; + (void) volume; + (void) ramp; + (void) time; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) +{ + (void) handle; + (void) sourceID; + (void) volume; + (void) ramp; + (void) time; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) +{ + (void) handle; + (void) sourceID; + (void) state; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) +{ + (void) handle; + (void) crossfaderID; + (void) hotSink; + (void) rampType; + (void) time; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + (void) domainID; + (void) domainState; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive *routingreceiveinterface) +{ + (void)routingreceiveinterface; + return (E_NOT_USED); +} + +void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle) +{ + (void) handle; +} + +void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle) +{ + (void) handle; +} + +am_Error_e CAmRoutingSenderDbus::returnBusName(std::string & BusName) const +{ + BusName = "DbusPlugin"; + return (E_OK); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) +{ + (void) handle; + (void) sinkID; + (void) soundProperty; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) +{ + (void) handle; + (void) sinkID; + (void) listSoundProperties; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) +{ + (void) handle; + (void) sourceID; + (void) soundProperty; + return (E_NOT_USED); +} + +am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) +{ + (void) handle; + (void) sourceID; + (void) listSoundProperties; + return (E_NOT_USED); +} + +void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const +{ + version=RoutingSendVersion; +} + + + diff --git a/PluginRoutingInterfaceDbus/src/RoutingSender.cpp b/PluginRoutingInterfaceDbus/src/RoutingSender.cpp deleted file mode 100644 index 3606c66..0000000 --- a/PluginRoutingInterfaceDbus/src/RoutingSender.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger DbusPlugin - * - * \file RoutingSender.cpp - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#include "RoutingSender.h" - -extern "C" RoutingSendInterface* PluginRoutingInterfaceDbusFactory() -{ - return (new DbusRoutingSender()); -} - -extern "C" void destroyRoutingPluginInterfaceDbus(RoutingSendInterface* routingSendInterface) -{ - delete routingSendInterface; -} - -DbusRoutingSender::DbusRoutingSender() -{ -} - -DbusRoutingSender::~DbusRoutingSender() -{ -} - -am_Error_e DbusRoutingSender::asyncAbort(const am_Handle_s handle) -{ - (void) handle; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) -{ - (void) handle; - (void) connectionID; - (void) sourceID; - (void) sinkID; - (void) connectionFormat; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) -{ - (void) handle; - (void) connectionID; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - (void) handle; - (void) sinkID; - (void) volume; - (void) ramp; - (void) time; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) -{ - (void) handle; - (void) sourceID; - (void) volume; - (void) ramp; - (void) time; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) -{ - (void) handle; - (void) sourceID; - (void) state; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) -{ - (void) handle; - (void) crossfaderID; - (void) hotSink; - (void) rampType; - (void) time; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - (void) domainID; - (void) domainState; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::startupInterface(RoutingReceiveInterface *routingreceiveinterface) -{ - (void)routingreceiveinterface; - return (E_NOT_USED); -} - -void DbusRoutingSender::setRoutingReady(const uint16_t handle) -{ - (void) handle; -} - -void DbusRoutingSender::setRoutingRundown(const uint16_t handle) -{ - (void) handle; -} - -am_Error_e DbusRoutingSender::returnBusName(std::string & BusName) const -{ - BusName = "DbusPlugin"; - return (E_OK); -} - -am_Error_e DbusRoutingSender::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty) -{ - (void) handle; - (void) sinkID; - (void) soundProperty; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector & listSoundProperties) -{ - (void) handle; - (void) sinkID; - (void) listSoundProperties; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty) -{ - (void) handle; - (void) sourceID; - (void) soundProperty; - return (E_NOT_USED); -} - -am_Error_e DbusRoutingSender::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector & listSoundProperties) -{ - (void) handle; - (void) sourceID; - (void) listSoundProperties; - return (E_NOT_USED); -} - -void DbusRoutingSender::getInterfaceVersion(std::string & version) const -{ - version=RoutingSendVersion; -} - - - diff --git a/cmake/AudioManagerCodestyle.xml b/cmake/AudioManagerCodestyle.xml new file mode 100644 index 0000000..0ecdb53 --- /dev/null +++ b/cmake/AudioManagerCodestyle.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmake/AudioManager_Codestyle.xml b/cmake/AudioManager_Codestyle.xml deleted file mode 100644 index 0ecdb53..0000000 --- a/cmake/AudioManager_Codestyle.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cmake/FindDBUS.cmake b/cmake/FindDBUS.cmake index e37b93a..0935b2f 100644 --- a/cmake/FindDBUS.cmake +++ b/cmake/FindDBUS.cmake @@ -35,8 +35,8 @@ 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}") + message(STATUS "Found DBUS include: ${DBUS_INCLUDE_DIR}") + message(STATUS "Found DBUS arch dependent include: ${DBUS_ARCH_INCLUDE_DIR}") ENDIF(DBUS_LIBRARY) MARK_AS_ADVANCED( diff --git a/cmake/config.cmake b/cmake/config.cmake index 2349bb7..8d1a8e6 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -19,6 +19,4 @@ #cmakedefine DBUS_SERVICE_PREFIX "@DBUS_SERVICE_PREFIX@" #cmakedefine DBUS_SERVICE_OBJECT_PATH "@DBUS_SERVICE_OBJECT_PATH@" -#cmakedefine INTROSPECTION_COMMAND_XML_FILE "@INTROSPECTION_COMMAND_XML_FILE@" - #endif /* _CONFIG_H */ diff --git a/include/audiomanagertypes.h b/include/audiomanagertypes.h new file mode 100644 index 0000000..afc5519 --- /dev/null +++ b/include/audiomanagertypes.h @@ -0,0 +1,819 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_1F9A0AD1_FF28_4de6_A5C7_2F570F618734__INCLUDED_) +#define EA_1F9A0AD1_FF28_4de6_A5C7_2F570F618734__INCLUDED_ + +#include +#include "projecttypes.h" +#include +#include + +#define AM_MUTE -3000 + +namespace am { + /** + * a domain ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_domainID_t; + + /** + * a source ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_sourceID_t; + + /** + * a sink ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_sinkID_t; + + /** + * a gateway ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_gatewayID_t; + + /** + * a crossfader ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_crossfaderID_t; + + /** + * a connection ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_connectionID_t; + + /** + * a mainConnection ID + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_mainConnectionID_t; + + /** + * speed + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_speed_t; + + /** + * The unit is 0.1 db steps,The smallest value -3000 (=AM_MUTE). The minimum and maximum can be limited by actual project. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef int16_t am_volume_t; + + /** + * This is the volume presented on the command interface. It is in the duty of the Controller to change the volumes given here into meaningful values on the routing interface. + * The range of this type is customer specific. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef int16_t am_mainVolume_t; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_sourceClass_t; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_sinkClass_t; + + /** + * time in ms! + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef uint16_t am_time_t; + + /** + * offset time that is introduced in milli seconds. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + typedef int16_t am_timeSync_t; + + /** + * with the help of this enum, sinks and sources can report their availability state + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_Availablility_e + { + /** + * default + */ + A_UNKNOWN = 0, + /** + * The source / sink is available + */ + A_AVAILABLE = 1, + /** + * the source / sink is not available + */ + A_UNAVAILABLE = 2, + A_MAX + }; + + /** + * represents the connection state + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_ConnectionState_e + { + CS_UNKNOWN = 0, + /** + * This means the connection is just building up + */ + CS_CONNECTING = 1, + /** + * the connection is ready to be used + */ + CS_CONNECTED = 2, + /** + * the connection is in the course to be knocked down + */ + CS_DISCONNECTING = 3, + /** + * only relevant for connectionStatechanged. Is send after the connection was removed + */ + CS_DISCONNECTED = 4, + /** + * this means the connection is still build up but unused at the moment + */ + CS_SUSPENDED = 5, + CS_MAX + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_DomainState_e + { + /** + * default + */ + DS_UNKNOWN = 0, + /** + * the domain is controlled by the daemon + */ + DS_CONTROLLED = 1, + /** + * the domain is independent starting up + */ + DS_INDEPENDENT_STARTUP = 1, + /** + * the domain is independent running down + */ + DS_INDEPENDENT_RUNDOWN = 2, + DS_MAX + }; + + /** + * This enum characterizes the data of the EarlyData_t + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_EarlyDataType_e + { + /** + * default + */ + ES_UNKNOWN = 0, + /** + * the source volume + */ + ED_SOURCE_VOLUME = 1, + /** + * the sink volume + */ + ED_SINK_VOLUME = 2, + /** + * a source property + */ + ED_SOURCE_PROPERTY = 3, + /** + * a sink property + */ + ED_SINK_PROPERTY = 4, + ED_MAX + }; + + /** + * the errors of the audiomanager. All possible errors are in here. This enum is used widely as return parameter. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_Error_e + { + /** + * default + */ + E_UNKNOWN = 0, + /** + * no error - positive reply + */ + E_OK = 1, + /** + * value out of range + */ + E_OUT_OF_RANGE = 2, + /** + * not used + */ + E_NOT_USED = 3, + /** + * a database error occurred + */ + E_DATABASE_ERROR = 4, + /** + * the desired object already exists + */ + E_ALREADY_EXISTS = 5, + /** + * there is no change + */ + E_NO_CHANGE = 6, + /** + * the desired action is not possible + */ + E_NOT_POSSIBLE = 7, + /** + * the desired object is non existent + */ + E_NON_EXISTENT = 8, + /** + * the asynchronous action was aborted + */ + E_ABORTED = 9, + /** + * This error is returned in case a connect is issued with a connectionFormat that cannot be selected for the connection. This could be either due to the capabilities of a source or a sink or gateway compatibilities for example + */ + E_WRONG_FORMAT = 10, + E_MAX + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_MuteState_e + { + /** + * default + */ + MS_UNKNOWN = 0, + /** + * the source / sink is muted + */ + MS_MUTED = 1, + /** + * the source / sink is unmuted + */ + MS_UNMUTED = 2, + MS_MAX + }; + + /** + * The source state reflects the state of the source + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_SourceState_e + { + SS_UNKNNOWN = 0, + /** + * The source can be activly heared + */ + SS_ON = 1, + /** + * The source cannot be heared + */ + SS_OFF = 2, + /** + * The source is paused. Meaning it cannot be heared but should be prepared to play again soon. + */ + SS_PAUSED = 3, + SS_MAX + }; + + /** + * This enumeration is used to define the type of the action that is correlated to a handle. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_Handle_e + { + H_UNKNOWN = 0, + H_CONNECT = 1, + H_DISCONNECT = 2, + H_SETSOURCESTATE = 3, + H_SETSINKVOLUME = 4, + H_SETSOURCEVOLUME = 5, + H_SETSINKSOUNDPROPERTY = 6, + H_SETSOURCESOUNDPROPERTY = 7, + H_SETSINKSOUNDPROPERTIES = 8, + H_SETSOURCESOUNDPROPERTIES = 9, + H_CROSSFADE = 10, + H_MAX + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_InterruptState_e + { + /** + * default + */ + IS_UNKNOWN = 0, + /** + * the interrupt state is off - no interrupt + */ + IS_OFF = 1, + /** + * the interrupt state is interrupted - the interrupt is active + */ + IS_INTERRUPTED = 2, + IS_MAX + }; + + /** + * describes the active sink of a crossfader. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:36 PM + */ + enum am_HotSink_e + { + /** + * default + */ + HS_UNKNOWN = 0, + /** + * sinkA is active + */ + HS_SINKA = 1, + /** + * sinkB is active + */ + HS_SINKB = 2, + /** + * the crossfader is in the transition state + */ + HS_INTERMEDIATE = 3, + HS_MAX + }; + + /** + * this describes the availability of a sink or a source together with the latest change + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_Availability_s + { + + public: + /** + * the current availability state + */ + am_Availablility_e availability; + /** + * the reason for the last change. This can be used to trigger events that deal with state changes. + */ + am_AvailabilityReason_e availabilityReason; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_ClassProperty_s + { + + public: + am_ClassProperty_e classProperty; + int16_t value; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_Crossfader_s + { + + public: + am_crossfaderID_t crossfaderID; + std::string name; + am_sinkID_t sinkID_A; + am_sinkID_t sinkID_B; + am_sourceID_t sourceID; + am_HotSink_e hotSink; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_Gateway_s + { + + public: + am_gatewayID_t gatewayID; + std::string name; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + am_domainID_t domainSinkID; + am_domainID_t domainSourceID; + am_domainID_t controlDomainID; + std::vector listSourceFormats; + std::vector listSinkFormats; + /** + * This is matrix holding information about the conversion capability of the gateway, it's length is defined by the length(listSinkFormats) x length(listSourceFormats). + * If a SinkFormat can be converted into a SourceFormat, the vector will hold a 1, if no conversion is possible, a 0. + * The data is stored row orientated, where the rows are related to the sinksFormats and the columns to the sourceFormats. The first value will hold the conversion information from the first sourceFormat to the first sinkFormat for example and the seventh value the information about the 3rd sinkFormat to the 1st sourceFormat in case we would have 3 sourceFormats. + * + * This matrix + * 110 011 000 111 001 + * + * reads as this: + * Source + * ** 1 2 3 + * ********************* + * S 1* 1 1 0 + * i 2* 0 1 1 + * n 3* 0 0 0 + * k 4* 1 1 1 + * 5* 0 0 1 + */ + std::vector convertionMatrix; + + }; + + /** + * This represents one "hopp" in a route + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_RoutingElement_s + { + + public: + am_sourceID_t sourceID; + am_sinkID_t sinkID; + am_domainID_t domainID; + am_ConnectionFormat_e connectionFormat; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_Route_s + { + + public: + am_sourceID_t sourceID; + am_sinkID_t sinkID; + std::vector route; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_SoundProperty_s + { + + public: + am_SoundPropertyType_e type; + int16_t value; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:37 PM + */ + struct am_SystemProperty_s + { + + public: + /** + * the type that is set + */ + am_SystemPropertyType_e type; + /** + * the value + */ + int16_t value; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_SinkClass_s + { + + public: + am_sinkClass_t sinkClassID; + std::string name; + std::vector listClassProperties; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_SourceClass_s + { + + public: + /** + * the source ID + */ + am_sourceClass_t sourceClassID; + std::string name; + std::vector listClassProperties; + + }; + + /** + * this type holds all information of sources relevant to the HMI + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_SourceType_s + { + + public: + am_sourceID_t sourceID; + std::string name; + am_Availability_s availability; + am_sourceClass_t sourceClassID; + + }; + + /** + * this type holds all information of sinks relevant to the HMI + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_SinkType_s + { + + public: + am_sinkID_t sinkID; + std::string name; + am_Availability_s availability; + am_mainVolume_t volume; + am_MuteState_e muteState; + am_sinkClass_t sinkClassID; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_Handle_s + { + + public: + am_Handle_e handleType:4; + uint16_t handle:12; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_MainSoundProperty_s + { + + public: + am_MainSoundPropertyType_e type; + int16_t value; + + }; + + /** + * this type holds all information of connections relevant to the HMI + * @author Christian Mueller + * @created 29-Feb-2012 6:16:38 PM + */ + struct am_MainConnectionType_s + { + + public: + am_mainConnectionID_t mainConnectionID; + am_sourceID_t sourceID; + am_sinkID_t sinkID; + am_timeSync_t delay; + am_ConnectionState_e connectionState; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + struct am_MainConnection_s + { + + public: + am_mainConnectionID_t mainConnectionID; + am_ConnectionState_e connectionState; + /** + * the sinkID + */ + am_sinkID_t sinkID; + /** + * the sourceID + */ + am_sourceID_t sourceID; + am_timeSync_t delay; + std::vector listConnectionID; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + struct am_Sink_s + { + + public: + am_sinkID_t sinkID; + std::string name; + am_domainID_t domainID; + am_sinkClass_t sinkClassID; + am_volume_t volume; + bool visible; + am_Availability_s available; + am_MuteState_e muteState; + am_mainVolume_t mainVolume; + std::vector listSoundProperties; + std::vector listConnectionFormats; + std::vector listMainSoundProperties; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + struct am_Source_s + { + + public: + am_sourceID_t sourceID; + am_domainID_t domainID; + std::string name; + am_sourceClass_t sourceClassID; + am_SourceState_e sourceState; + am_volume_t volume; + bool visible; + am_Availability_s available; + am_InterruptState_e interruptState; + /** + * This list holds all soundProperties of the source + */ + std::vector listSoundProperties; + /** + * list of the supported ConnectionFormats + */ + std::vector listConnectionFormats; + /** + * This list holds all MainSoundProperties of the source (all the ones that can be set via the HMI) + */ + std::vector listMainSoundProperties; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + struct am_Domain_s + { + + public: + am_domainID_t domainID; + std::string name; + std::string busname; + std::string nodename; + bool early; + bool complete; + am_DomainState_e state; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + struct am_Connection_s + { + + public: + am_connectionID_t connectionID; + am_sourceID_t sourceID; + am_sinkID_t sinkID; + am_timeSync_t delay; + am_ConnectionFormat_e connectionFormat; + + }; + + /** + * data type depends of am_EarlyDataType_e: + * volume_t in case of ED_SOURCE_VOLUME, ED_SINK_VOLUME + * soundProperty_t in case of ED_SOURCE_PROPERTY, ED_SINK_PROPERTY + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + union am_EarlyData_u + { + + public: + am_volume_t volume; + am_SoundProperty_s soundProperty; + + }; + + /** + * data type depends of am_EarlyDataType_e: + * sourceID in case of ED_SOURCE_VOLUME, ED_SOURCE_PROPERTY + * sinkID in case of ED_SINK_VOLUME, ED_SINK_PROPERTY + * @author Christian Mueller + * @created 29-Feb-2012 6:16:39 PM + */ + union am_DataType_u + { + + public: + am_sinkID_t sink; + am_sourceID_t source; + + }; + + /** + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + struct am_EarlyData_s + { + + public: + am_EarlyDataType_e type; + am_DataType_u sinksource; + am_EarlyData_u data; + + }; +} +#endif // !defined(EA_1F9A0AD1_FF28_4de6_A5C7_2F570F618734__INCLUDED_) diff --git a/include/command/IAmCommandReceive.h b/include/command/IAmCommandReceive.h new file mode 100644 index 0000000..f56c838 --- /dev/null +++ b/include/command/IAmCommandReceive.h @@ -0,0 +1,220 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_33827DF9_2BDB_4811_85B2_0EA4CD5519E4__INCLUDED_) +#define EA_33827DF9_2BDB_4811_85B2_0EA4CD5519E4__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" +namespace am { +class CAmDbusWrapper; +class CAmSocketHandler; +} + + +#define CommandReceiveVersion "1.0" +namespace am { + /** + * The interface towards the Controlling Instance (e.g HMI). It handles the communication towards the HMI and other system components who need to interact with the audiomanagement. + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:42 PM + */ + class IAmCommandReceive + { + + public: + IAmCommandReceive() { + + } + + virtual ~IAmCommandReceive() { + + } + + /** + * connects a source to sink + * @return E_OK on success, E_NOT_POSSIBLE on failure, E_ALREADY_EXISTS if the connection does already exists + * + * @param sourceID + * @param sinkID + * @param mainConnectionID + */ + virtual am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) =0; + /** + * disconnects a mainConnection + * @return E_OK on successes, E_NON_EXISTENT if the connection does not exist, E_NOT_POSSIBLE on error. + * + * @param mainConnectionID + */ + virtual am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID) =0; + /** + * sets the volume for a sink + * @return E_OK on success, E_UNKOWN on error, E_OUT_OF_RANGE in case the value is out of range + * + * @param sinkID the sink + * @param volume the volume + */ + virtual am_Error_e setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume) =0; + /** + * This function is used to increment or decrement the current volume for a sink. + * @return E_OK on success, E_UNKNOWN on error and E_OUT_OF_RANGE if the value is not in the given volume range. + * + * @param sinkID + * @param volumeStep indicated the number of steps that should be incremented or decremented. Positive values here inkrement, negative values decrement + */ + virtual am_Error_e volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep) =0; + /** + * sets the mute state of a sink + * @return E_OK on success, E_UNKNOWN on error. If the mute state is already the desired one, the Daemon will return E_OK. + * + * @param sinkID + * @param muteState + */ + virtual am_Error_e setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; + /** + * This method is used to set sound properties, e.g. Equalizer Values. Since the capabilities of the system can differ, the exact key value pairs can be extended in each product + * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error + * + * @param soundProperty + * @param sinkID + */ + virtual am_Error_e setMainSinkSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) =0; + /** + * This method is used to set sound properties, e.g. Equalizer Values. Since the capabilities of the system can differ, the exact key value pairs can be extended in each product + * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error + * + * @param soundProperty + * @param sourceID + */ + virtual am_Error_e setMainSourceSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) =0; + /** + * is used to set a specific system property. + * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error + * + * @param property the property that shall be set + */ + virtual am_Error_e setSystemProperty(const am_SystemProperty_s& property) =0; + /** + * returns the actual list of MainConnections + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listConnections returns a list of all connections + */ + virtual am_Error_e getListMainConnections(std::vector& listConnections) const =0; + /** + * returns the actual list of Sinks + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listMainSinks the list of the sinks + */ + virtual am_Error_e getListMainSinks(std::vector& listMainSinks) const =0; + /** + * returns the actual list of Sources + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listMainSources the list of sources + */ + virtual am_Error_e getListMainSources(std::vector& listMainSources) const =0; + /** + * This is used to retrieve all source sound properties related to a source. Returns a vector of the sound properties and values as pair + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param sinkID + * @param listSoundProperties + */ + virtual am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const =0; + /** + * This is used to retrieve all source sound properties related to a source. + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param sourceID + * @param listSourceProperties + */ + virtual am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const =0; + /** + * This is used to retrieve SourceClass Information of all source classes + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSourceClasses + */ + virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const =0; + /** + * This is used to retrieve SinkClass Information of all sink classes + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSinkClasses + */ + virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const =0; + /** + * Retrieves a complete list of all systemProperties. + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSystemProperties + */ + virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const =0; + /** + * returns the delay in ms that the audiopath for the given mainConnection has + * @return E_OK on success, E_NOT_POSSIBLE if timing information is not yet retrieved, E_DATABASE_ERROR on read error on the database + * + * @param mainConnectionID + * @param delay + */ + virtual am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const =0; + /** + * this function is used to retrieve a pointer to the dBusConnectionWrapper + * @return E_OK if pointer is valid, E_UKNOWN if AudioManager was compiled without DBus Support + * + * @param dbusConnectionWrapper This is a wrapper class that is needed to keep dbus inclusions away from the interface. The DBusWrapperClass will return the pointer to the DbusConnection call (getDBusConnection) + */ + virtual am_Error_e getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const =0; + /** + * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. + * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, + * + * @param socketHandler + */ + virtual am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) const =0; + /** + * This function returns the version of the interface. + * + * @param version + */ + virtual void getInterfaceVersion(std::string& version) const =0; + /** + * asynchronous confirmation of setCommandReady. + * + * @param handle the handle that was handed over by setCommandReady + */ + virtual void confirmCommandReady(const uint16_t handle) =0; + /** + * asynchronous confirmation of setCommandRundown + * + * @param handle the handle that was given via setCommandRundown + */ + virtual void confirmCommandRundown(const uint16_t handle) =0; + + }; +} +#endif // !defined(EA_33827DF9_2BDB_4811_85B2_0EA4CD5519E4__INCLUDED_) diff --git a/include/command/IAmCommandSend.h b/include/command/IAmCommandSend.h new file mode 100644 index 0000000..0a447f9 --- /dev/null +++ b/include/command/IAmCommandSend.h @@ -0,0 +1,194 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_E4CFF16E_3331_4608_971A_20131753B26D__INCLUDED_) +#define EA_E4CFF16E_3331_4608_971A_20131753B26D__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" + +namespace am { +class IAmCommandReceive; +} + +#include "IAmCommandReceive.h" + +#define CommandSendVersion "1.0" +namespace am { + /** + * This interface handles all communication from the AudioManagerDaemon towards the system. It is designed in such a way that only callbacks with no return types are implemented. So when the CommandInterfacePlugins are designed in such a way that they broadcast signals to any node who is interested in the particular information (like signals on Dbus for example), more information can be retrieved via the CommandReceiveInterface. + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:43 PM + */ + class IAmCommandSend + { + + public: + IAmCommandSend() { + + } + + virtual ~IAmCommandSend() { + + } + + /** + * This command starts the interface, the plugin itself. This is not meant to start communication with the HMI itself. It is a good idea to implement here everything that sets up the basic communication like DbusCommunication etc... + * Be aware of side effects with systemd and socketbased communication! + * @return E_OK on success, E_UNKNOWN on error + * + * @param commandreceiveinterface pointer to the receive interface. Is used to call the audiomanagerdaemon + */ + virtual am_Error_e startupInterface(IAmCommandReceive* commandreceiveinterface) =0; + /** + * This function will indirectly be called by the Controller and is used to start the Communication. Before this command, all communication will be ignored by the AudioManager. + * After the Plugin is ready, it will asynchronously answer with condfirmCommandReady, the handle that is handed over must be returned. + * + * @param handle the handle uniquely idenfies the request + */ + virtual void setCommandReady(const uint16_t handle) =0; + /** + * This function will indirectly be called by the Controller and is used to stop the Communication. After this command, all communication will be ignored by the AudioManager. The plugin has to be prepared that either the power will be switched off or the Interface is started again with setCommandReady + * After the Plugin is ready to rundown, it will asynchronously answer with condfirmCommandRundown, the handle that is handed over must be returned. + * + * @param handle This handle uniquly idenfies the request + */ + virtual void setCommandRundown(const uint16_t handle) =0; + /** + * Callback that is called when the number of connections change + * + * @param mainConnection + */ + virtual void cbNewMainConnection(const am_MainConnectionType_s mainConnection) =0; + /** + * Callback that is called when the number of connections change + * + * @param mainConnection + */ + virtual void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) =0; + /** + * Callback that is called when the number of sinks change + * + * @param sink + */ + virtual void cbNewSink(const am_SinkType_s& sink) =0; + /** + * Callback that is called when the number of sinks change + * + * @param sinkID + */ + virtual void cbRemovedSink(const am_sinkID_t sinkID) =0; + /** + * Callback that is called when the number of sources change + * + * @param source + */ + virtual void cbNewSource(const am_SourceType_s& source) =0; + /** + * Callback that is called when the number of sources change + * + * @param source + */ + virtual void cbRemovedSource(const am_sourceID_t source) =0; + /** + * this callback is fired if the number of sink classes changed + */ + virtual void cbNumberOfSinkClassesChanged() =0; + /** + * this callback is fired if the number of source classes changed + */ + virtual void cbNumberOfSourceClassesChanged() =0; + /** + * This callback is called when the ConnectionState of a connection changed. + * + * @param connectionID + * @param connectionState + */ + virtual void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) =0; + /** + * this callback indicates that a sinkSoundProperty has changed. + * + * @param sinkID + * @param soundProperty + */ + virtual void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) =0; + /** + * this callback indicates that a sourceSoundProperty has changed. + * + * @param sourceID + * @param soundProperty + */ + virtual void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) =0; + /** + * this callback is called when the availability of a sink has changed + * + * @param sinkID + * @param availability + */ + virtual void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; + /** + * this callback is called when the availability of source has changed. + * + * @param sourceID + * @param availability + */ + virtual void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; + /** + * this callback indicates a volume change on the indicated sink + * + * @param sinkID + * @param volume + */ + virtual void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) =0; + /** + * this callback indicates a mute state change on a sink. + * + * @param sinkID + * @param muteState + */ + virtual void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; + /** + * is fired if a systemProperty changed + * + * @param systemProperty + */ + virtual void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty) =0; + /** + * This callback is fired if the timinginformation for a mainConnectionID changed + * + * @param mainConnectionID + * @param time + */ + virtual void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) =0; + /** + * returns the interface version as string. + * + * @param version + */ + virtual void getInterfaceVersion(std::string& version) const =0; + + }; +} +#endif // !defined(EA_E4CFF16E_3331_4608_971A_20131753B26D__INCLUDED_) diff --git a/include/control/IAmControlReceive.h b/include/control/IAmControlReceive.h new file mode 100644 index 0000000..bc160aa --- /dev/null +++ b/include/control/IAmControlReceive.h @@ -0,0 +1,614 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_857044C8_1BA8_4972_9083_E7BDD50F6922__INCLUDED_) +#define EA_857044C8_1BA8_4972_9083_E7BDD50F6922__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" +namespace am { +class CAmSocketHandler; +} + + +#define ControlReceiveVersion "1.0" +namespace am { + /** + * This interface gives access to all important functions of the audiomanager that are used by the AudioManagerController to control the system. + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:43 PM + */ + class IAmControlReceive + { + + public: + IAmControlReceive() { + + } + + virtual ~IAmControlReceive() { + + } + + /** + * calculates a route from source to sink. + * @return E_OK on success, E_UNKNOWN on error + * + * @param onlyfree if true return only routes which use gateways that are not in use at the moment + * @param sourceID + * @param sinkID + * @param returnList this is a list of routes that are possible to take. unsorted! The longest could be first. + * In case not route can be found, the list will return empty. + */ + virtual am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList) =0; + /** + * With this function, elementary connects can be triggered by the controller. + * @return E_OK on success, E_UNKNOWN on error, E_WRONG_FORMAT of connectionFormats do not match, E_NO_CHANGE if the desired connection is already build up + * + * @param handle + * @param connectionID + * @param format + * @param sourceID + * @param sinkID + */ + virtual am_Error_e connect(am_Handle_s& handle, am_connectionID_t& connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID) =0; + /** + * is used to disconnect a connection + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if connection was not found, E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param connectionID + */ + virtual am_Error_e disconnect(am_Handle_s& handle, const am_connectionID_t connectionID) =0; + /** + * triggers a cross fade. + * @return E_OK on success, E_UNKNOWN on error E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param hotSource this is the source that is going to be the active one after the fading + * @param crossfaderID + * @param rampType + * @param rampTime rampTime 0 means default value + */ + virtual am_Error_e crossfade(am_Handle_s& handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime) =0; + /** + * with this method, all actions that have a handle assigned can be stopped. + * @return E_OK on success, E_UNKNOWN on error + * + * @param handle the handle of the action to be stopped + */ + virtual am_Error_e abortAction(const am_Handle_s handle) =0; + /** + * this method sets a source state for a source. This function will trigger the callback cbAckSetSourceState + * @return E_OK on success, E_NO_CHANGE if the desired value is already correct, E_UNKNOWN on error, E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param sourceID + * @param state + */ + virtual am_Error_e setSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state) =0; + /** + * with this function, setting of sinks volumes is done. The behavior of the volume set is depended on the given ramp and time information. + * This function is not only used to ramp volume, but also to mute and direct set the level. Exact behavior is depended on the selected mute ramps. + * @return E_OK on success, E_NO_CHANGE if the volume is already on the desired value, E_OUT_OF_RANGE is the volume is out of range, E_UNKNOWN on every other error. + * + * @param handle + * @param sinkID + * @param volume + * @param ramp + * @param time + */ + virtual am_Error_e setSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; + /** + * with this function, setting of source volumes is done. The behavior of the volume set is depended on the given ramp and time information. + * This function is not only used to ramp volume, but also to mute and direct set the level. Exact behavior is depended on the selected mute ramps. + * @return E_OK on success, E_NO_CHANGE if the volume is already on the desired value, E_OUT_OF_RANGE is the volume is out of range, E_UNKNOWN on every other error. + * + * @param handle + * @param sourceID + * @param volume + * @param rampType + * @param time + */ + virtual am_Error_e setSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time) =0; + /** + * is used to set several sinkSoundProperties at a time + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range, E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param sinkID + * @param soundProperty + */ + virtual am_Error_e setSinkSoundProperties(am_Handle_s& handle, const am_sinkID_t sinkID, const std::vector& soundProperty) =0; + /** + * is used to set sinkSoundProperties + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range, E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param sinkID + * @param soundProperty + */ + virtual am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) =0; + /** + * is used to set several SourceSoundProperties at a time + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range. E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param sourceID + * @param soundProperty + */ + virtual am_Error_e setSourceSoundProperties(am_Handle_s& handle, const am_sourceID_t sourceID, const std::vector& soundProperty) =0; + /** + * is used to set sourceSoundProperties + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range. E_NO_CHANGE if no change is neccessary + * + * @param handle + * @param sourceID + * @param soundProperty + */ + virtual am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) =0; + /** + * sets the domain state of a domain + * @return E_OK on success, E_UNKNOWN on error, E_NO_CHANGE if no change is neccessary + * + * @param domainID + * @param domainState + */ + virtual am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) =0; + /** + * enters a domain in the database, creates and ID + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param domainData domainID in am_Domain_s must be 0 here + * @param domainID + */ + virtual am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID) =0; + /** + * enters a mainconnection in the database, creates and ID + * @return E_OK on success, E_DATABASE_ERROR if the database had an error + * + * @param mainConnectionData the MainConnectionID is omitted since it is created during the registration + * @param connectionID + */ + virtual am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID) =0; + /** + * enters a sink in the database. + * The sinkID in am_Sink_s shall be 0 in case of a dynamic added source A sinkID greater than 100 will be assigned. If a specific sinkID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param sinkData the sinkID will be omitted since it is created during the registration + * @param sinkID + */ + virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; + /** + * enters a crossfader in the database. + * The crossfaderID in am_Crossfader_s shall be 0 in case of a dynamic added source A crossfaderID greater than 100 will be assigned. If a specific crossfaderID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param crossfaderData the ID in the data will be ignored since it is created during the registration + * @param crossfaderID + */ + virtual am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; + /** + * enters a gateway in the database. + * The gatewayID in am_Gateway_s shall be 0 in case of a dynamic added source A gatewayID greater than 100 will be assigned. If a specific gatewayID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param gatewayData In a fixed setup, the gatewayID must be below 100. In a dynamic setup, the gatewayID shall be 0! listSourceFormats and listSinkFormats are empty at registration time. Values are taken over when sources and sinks are registered. + * @param gatewayID + */ + virtual am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; + /** + * enters a source in the database. + * The sourceID in am_Source_s shall be 0 in case of a dynamic added source A sourceID greater than 100 will be assigned. If a specific sourceID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param sourceData sourceID is omitted here since it is created during registration + * @param sourceID + */ + virtual am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; + /** + * Enters a sourceClass into the database. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param sinkClass IDs given with the SinkCLassID are valid below 100 (static). If given as 0, sinkClass will be enterd dynamic and ID above 100 will be created. + * @param sinkClassID + */ + virtual am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID) =0; + /** + * Enters a sourceClass into the database. + * The sourceClassID in am_sourceClass_s shall be 0 in case of a dynamic added source A sourceClassID greater than 100 will be assigned. If a specific sourceClassID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. + * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error + * + * @param sourceClassID + * @param sourceClass IDs given with the SourceCLassID are valid below 100 (static). If given as 0, sourceClass will be enterd dynamic and ID above 100 will be created. + */ + virtual am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass) =0; + /** + * changes class information of a sinkclass. + * The properties will overwrite the values of the sinkClassID given in the sinkClass. + * It is the duty of the controller to check if the property is valid. If it does not exist, the daemon will not return an error. + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sinkClassID was not found. + * + * @param sinkClass if a SourceClass ID other than 0 is given, the classInformation replaces the existing one. In case of ClassID 0, a new classID is created and returned + */ + virtual am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) =0; + /** + * changes class information of a sourceClass. + * The properties will overwrite the values of the sourceClassID given in the sourceClass. + * It is the duty of the controller to check if the property is valid. If it does not exist, the daemon will not return an error. + * @return E_OK on success, E_DATABASE_ERROR on error and E_NON_EXISTENT if the ClassID does not exist. + * + * @param sourceClass if a SourceClass ID other than 0 is given, the classInformation replaces the existing one. In case of ClassID 0, a new classID is created and returned + */ + virtual am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) =0; + /** + * This function is used to enter the system Properties into the database. + * All entries in the database will be erased before entering the new List. It should only be called once at system startup. + * @return E_OK on success, E_DATABASE_ERROR if the database had an error + * + * @param listSystemProperties + */ + virtual am_Error_e enterSystemPropertiesListDB(const std::vector& listSystemProperties) =0; + /** + * changes the mainConnectionState of MainConnection + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if mainconnection + * + * @param mainconnectionID + * @param listConnectionID + */ + virtual am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) =0; + /** + * changes the mainConnectionState of MainConnection + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if mainconnection + * + * @param mainconnectionID + * @param connectionState + */ + virtual am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) =0; + /** + * changes the sink volume of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param mainVolume + * @param sinkID + */ + virtual am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) =0; + /** + * changes the availablility of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param availability + * @param sinkID + */ + virtual am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID) =0; + /** + * changes the domainstate of a domain + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found + * + * @param domainState + * @param domainID + */ + virtual am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) =0; + /** + * changes the mute state of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param muteState + * @param sinkID + */ + virtual am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) =0; + /** + * changes the mainsinksoundproperty of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param soundProperty + * @param sinkID + */ + virtual am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) =0; + /** + * changes the mainsourcesoundproperty of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found + * + * @param soundProperty + * @param sourceID + */ + virtual am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) =0; + /** + * changes the availablility of a source + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found + * + * @param availability + * @param sourceID + */ + virtual am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID) =0; + /** + * changes a systemProperty + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if property was not found + * + * @param property + */ + virtual am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property) =0; + /** + * removes a mainconnection from the DB + * @return E_OK on success, E_NON_EXISTENT if main connection was not found, E_DATABASE_ERROR if the database had an error + * + * @param mainConnectionID + */ + virtual am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) =0; + /** + * removes a sink from the DB + * @return E_OK on success, E_NON_EXISTENT if sink was not found, E_DATABASE_ERROR if the database had an error + * + * @param sinkID + */ + virtual am_Error_e removeSinkDB(const am_sinkID_t sinkID) =0; + /** + * removes a source from the DB + * @return E_OK on success, E_NON_EXISTENT if source was not found, E_DATABASE_ERROR if the database had an error + * + * @param sourceID + */ + virtual am_Error_e removeSourceDB(const am_sourceID_t sourceID) =0; + /** + * removes a gateway from the DB + * @return E_OK on success, E_NON_EXISTENT if gateway was not found, E_DATABASE_ERROR if the database had an error + * + * @param gatewayID + */ + virtual am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID) =0; + /** + * removes a crossfader from the DB + * @return E_OK on success, E_NON_EXISTENT if crossfader was not found, E_DATABASE_ERROR if the database had an error + * + * @param crossfaderID + */ + virtual am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID) =0; + /** + * removes a domain from the DB + * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error + * + * @param domainID + */ + virtual am_Error_e removeDomainDB(const am_domainID_t domainID) =0; + /** + * removes a domain from the DB + * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error + * + * @param sinkClassID + */ + virtual am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID) =0; + /** + * removes a domain from the DB + * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error + * + * @param sourceClassID + */ + virtual am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID) =0; + /** + * returns the ClassInformation of a source + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found + * + * @param sourceID + * @param classInfo + */ + virtual am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const =0; + /** + * returns the ClassInformation of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param sinkID + * @param sinkClass + */ + virtual am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const =0; + /** + * returns the sinkData of a sink + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param sinkID + * @param sinkData + */ + virtual am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const =0; + /** + * returns the sourcekData of a source + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found + * + * @param sourceID + * @param sourceData + */ + virtual am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const =0; + /** + * return source and sink of a gateway + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if gateway was not found + * + * @param gatewayID + * @param gatewayData + */ + virtual am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const =0; + /** + * returns sources and the sink of a crossfader + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if crossfader was not found + * + * @param crossfaderID + * @param crossfaderData + */ + virtual am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const =0; + /** + * returns sources and the sink of a crossfader + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if crossfader was not found + * + * @param mainConnectionID + * @param mainConnectionData + */ + virtual am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const =0; + /** + * returns all sinks of a domain + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found + * + * @param domainID + * @param listSinkID + */ + virtual am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const =0; + /** + * returns all source of a domain + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found + * + * @param domainID + * @param listSourceID + */ + virtual am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const =0; + /** + * returns all crossfaders of a domain + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found + * + * @param domainID + * @param listCrossfadersID + */ + virtual am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listCrossfadersID) const =0; + /** + * returns all gateways of a domain + * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found + * + * @param domainID + * @param listGatewaysID + */ + virtual am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const =0; + /** + * returns a complete list of all MainConnections + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listMainConnections + */ + virtual am_Error_e getListMainConnections(std::vector& listMainConnections) const =0; + /** + * returns a complete list of all domains + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listDomains + */ + virtual am_Error_e getListDomains(std::vector& listDomains) const =0; + /** + * returns a complete list of all Connections + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listConnections + */ + virtual am_Error_e getListConnections(std::vector& listConnections) const =0; + /** + * returns a list of all sinks + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSinks + */ + virtual am_Error_e getListSinks(std::vector& listSinks) const =0; + /** + * returns a list of all sources + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSources + */ + virtual am_Error_e getListSources(std::vector& listSources) const =0; + /** + * returns a list of all source classes + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSourceClasses + */ + virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const =0; + /** + * returns a list of all handles + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listHandles + */ + virtual am_Error_e getListHandles(std::vector& listHandles) const =0; + /** + * returns a list of all crossfaders + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listCrossfaders + */ + virtual am_Error_e getListCrossfaders(std::vector& listCrossfaders) const =0; + /** + * returns a list of gateways + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listGateways + */ + virtual am_Error_e getListGateways(std::vector& listGateways) const =0; + /** + * returns a list of all sink classes + * @return E_OK on success, E_DATABASE_ERROR on error + * + * @param listSinkClasses + */ + virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const =0; + /** + * returns the list of SystemProperties + * + * @param listSystemProperties + */ + virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const =0; + /** + * sets the command interface to ready. Will send setCommandReady to each of the plugins. The corresponding answer is confirmCommandReady. + */ + virtual void setCommandReady() =0; + /** + * sets the command interface into the rundown state. Will send setCommandRundown to each of the plugins. The corresponding answer is confirmCommandRundown. + */ + virtual void setCommandRundown() =0; + /** + * sets the routinginterface to ready. Will send the command setRoutingReady to each of the plugins. The related answer is confirmRoutingReady. + */ + virtual void setRoutingReady() =0; + /** + * sets the routinginterface to the rundown state. Will send the command setRoutingRundown to each of the plugins. The related answer is confirmRoutingRundown. + */ + virtual void setRoutingRundown() =0; + /** + * acknowledges the setControllerReady call. + */ + virtual void confirmControllerReady() =0; + /** + * acknowledges the setControllerRundown call. + */ + virtual void confirmControllerRundown() =0; + /** + * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. + * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, + * + * @param socketHandler + */ + virtual am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) =0; + /** + * This function returns the version of the interface + * + * @param version + */ + virtual void getInterfaceVersion(std::string& version) const =0; + + }; +} +#endif // !defined(EA_857044C8_1BA8_4972_9083_E7BDD50F6922__INCLUDED_) diff --git a/include/control/IAmControlSend.h b/include/control/IAmControlSend.h new file mode 100644 index 0000000..edf6d2e --- /dev/null +++ b/include/control/IAmControlSend.h @@ -0,0 +1,388 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_4CA53F2D_FD24_4389_9279_AD92791BD0B6__INCLUDED_) +#define EA_4CA53F2D_FD24_4389_9279_AD92791BD0B6__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" + +namespace am { +class IAmControlReceive; +} + +#define ControlSendVersion "1.0" +namespace am { + /** + * This interface is presented by the AudioManager controller. + * All the hooks represent system events that need to be handled. The callback functions are used to handle for example answers to function calls on the AudioManagerCoreInterface. + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:44 PM + */ + class IAmControlSend + { + + public: + IAmControlSend() { + + } + + virtual ~IAmControlSend() { + + } + + /** + * Starts up the controller. + * + * @param controlreceiveinterface This is a pointer to the ControlReceiveInterface so that the controller knows to whom to communicate. + */ + virtual am_Error_e startupController(IAmControlReceive* controlreceiveinterface) =0; + /** + * this message is used tell the controller that it should get ready. This message must be acknowledged via confirmControllerReady. + */ + virtual void setControllerReady() =0; + /** + * this message tells the controller that he should prepare everything for the power to be switched off. This message must be acknowledged via confirmControllerRundown. + */ + virtual void setControllerRundown() =0; + /** + * is called when a connection request comes in via the command interface + * @return E_OK on success, E_NOT_POSSIBLE on error, E_ALREADY_EXISTENT if already exists + * + * @param sourceID + * @param sinkID + * @param mainConnectionID + */ + virtual am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) =0; + /** + * is called when a disconnection request comes in via the command interface + * @return E_OK on success, E_NOT_POSSIBLE on error, E_NON_EXISTENT if connection does not exists + * + * @param connectionID + */ + virtual am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) =0; + /** + * sets a user MainSinkSoundProperty + * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error + * + * @param sinkID + * @param soundProperty + */ + virtual am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) =0; + /** + * sets a user MainSourceSoundProperty + * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error + * + * @param sourceID + * @param soundProperty + */ + virtual am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) =0; + /** + * sets a user SystemProperty + * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error + * + * @param property + */ + virtual am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property) =0; + /** + * sets a user volume + * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error + * + * @param SinkID + * @param newVolume + */ + virtual am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) =0; + /** + * sets a user volume as increment + * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error + * + * @param SinkID + * @param increment the steps + */ + virtual am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) =0; + /** + * sets the mute state of a sink + * @return E_OK on success, E_UNKNOWN on error + * + * @param sinkID + * @param muteState true=muted + */ + virtual am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; + /** + * is called when a routing adaptor registers its domain + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists + * + * @param domainData ID is omitted here since it has not been created yet + * @param domainID + */ + virtual am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID) =0; + /** + * is called when a routing adaptor wants to derigister a domain + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found + * + * @param domainID + */ + virtual am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID) =0; + /** + * is called when a domain registered all the elements + * + * @param domainID + */ + virtual void hookSystemDomainRegistrationComplete(const am_domainID_t domainID) =0; + /** + * is called when a routing adaptor registers a sink + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists + * + * @param sinkData Id is omitted here, since it has not been created yet + * @param sinkID + */ + virtual am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; + /** + * is called when a routing adaptor deregisters a sink + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found + * + * @param sinkID + */ + virtual am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID) =0; + /** + * is called when a routing adaptor registers a source + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists + * + * @param sourceData ID is omitted here since it is not yet created + * @param sourceID + */ + virtual am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; + /** + * is called when a routing adaptor deregisters a source + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found + * + * @param sourceID + */ + virtual am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) =0; + /** + * is called when a routing adaptor registers a gateway + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists + * + * @param gatewayData gatewayID is not set here since it is not created at this point of time + * @param gatewayID + */ + virtual am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; + /** + * is called when a routing adaptor deregisters a gateway + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found + * + * @param gatewayID + */ + virtual am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) =0; + /** + * is called when a routing adaptor registers a crossfader + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists + * + * @param crossfaderData gatewayID is not set here since it is not created at this point of time + * @param crossfaderID + */ + virtual am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; + /** + * is called when a routing adaptor deregisters a crossfader + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found + * + * @param crossfaderID + */ + virtual am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) =0; + /** + * volumeticks. therse are used to indicate volumechanges during a ramp + * + * @param handle + * @param sinkID + * @param volume + */ + virtual void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) =0; + /** + * volumeticks. therse are used to indicate volumechanges during a ramp + * + * @param handle + * @param sourceID + * @param volume + */ + virtual void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) =0; + /** + * is called when an low level interrupt changed its state + * + * @param sourceID + * @param interruptState + */ + virtual void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) =0; + /** + * id called when a sink changed its availability + * + * @param sinkID + * @param availability + */ + virtual void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; + /** + * id called when a source changed its availability + * + * @param sourceID + * @param availability + */ + virtual void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; + /** + * id called when domainstate was changed + * + * @param domainID + * @param state + */ + virtual void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) =0; + /** + * when early data was received + * + * @param data + */ + virtual void hookSystemReceiveEarlyData(const std::vector& data) =0; + /** + * this hook provides information about speed changes. + * The quantization and sampling rate of the speed can be adjusted at compile time of the AudioManagerDaemon. + * + * @param speed + */ + virtual void hookSystemSpeedChange(const am_speed_t speed) =0; + /** + * this hook is fired whenever the timing information of a mainconnection has changed. + * + * @param mainConnectionID + * @param time + */ + virtual void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) =0; + /** + * ack for connect + * + * @param handle + * @param errorID + */ + virtual void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) =0; + /** + * ack for disconnect + * + * @param handle + * @param errorID + */ + virtual void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) =0; + /** + * ack for crossfading + * + * @param handle + * @param hostsink + * @param error + */ + virtual void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) =0; + /** + * ack for sink volume changes + * + * @param handle + * @param volume + * @param error + */ + virtual void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; + /** + * ack for source volume changes + * + * @param handle the handle that is connected to the volume change + * @param voulme the volume after the action ended (the desired volume if everything went right, the actual one in case of abortion) + * @param error + */ + virtual void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) =0; + /** + * ack for setting of source states + * + * @param handle + * @param error + */ + virtual void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) =0; + /** + * ack for setting of sourcesoundproperties + * + * @param handle + * @param error + */ + virtual void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; + /** + * ack for setting of sourcesoundproperties + * + * @param handle + * @param error + */ + virtual void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; + /** + * ack for setting of sinksoundproperties + * + * @param handle + * @param error + */ + virtual void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; + /** + * ack for setting of sinksoundproperties + * + * @param handle + * @param error + */ + virtual void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; + /** + * This function is used by the routing algorithm to retrieve a priorized list of connectionFormats from the Controller. + * @return E_OK in case of successfull priorisation. + * + * @param sourceID sourceID of source that shall be connected + * @param sinkID sinkID of sink that shall be connected + * @param listRoute This route is the one the priorized connectionFormats is for. + * @param listPossibleConnectionFormats list of possible connectionformats + * @param listPrioConnectionFormats the list return with prioos from the controller. Best choice on first position. + */ + virtual am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats) =0; + /** + * This function returns the version of the interface + * returns E_OK, E_UNKOWN if version is unknown. + * + * @param version + */ + virtual void getInterfaceVersion(std::string& version) const =0; + /** + * confirms the setCommandReady call + */ + virtual void confirmCommandReady() =0; + /** + * confirms the setRoutingReady call + */ + virtual void confirmRoutingReady() =0; + /** + * confirms the setCommandRundown call + */ + virtual void confirmCommandRundown() =0; + /** + * confirms the setRoutingRundown command + */ + virtual void confirmRoutingRundown() =0; + + }; +} +#endif // !defined(EA_4CA53F2D_FD24_4389_9279_AD92791BD0B6__INCLUDED_) diff --git a/include/projecttypes.h b/include/projecttypes.h new file mode 100644 index 0000000..2c03d5a --- /dev/null +++ b/include/projecttypes.h @@ -0,0 +1,203 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_3B985F0B_FAF4_4ad9_B5EA_59C989D2321B__INCLUDED_) +#define EA_3B985F0B_FAF4_4ad9_B5EA_59C989D2321B__INCLUDED_ + +namespace am { + /** + * This enum classifies the format in which data is exchanged within a connection. The enum itself is project specific although there are some Genivi standard formats defined. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_ConnectionFormat_e + { + /** + * default + */ + CF_UNKNOWN = 0, + /** + * plain mono + */ + CF_GENIVI_MONO = 1, + /** + * stereo connection + */ + CF_GENIVI_STEREO = 2, + /** + * analog connection + */ + CF_GENIVI_ANALOG = 3, + /** + * automatic connection. + */ + CF_GENIVI_AUTO = 4, + CF_MAX + }; + + /** + * This enum gives the information about reason for reason for Source/Sink change + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_AvailabilityReason_e + { + /** + * default + */ + AR_UNKNOWN = 0, + /** + * the availability changed because an new media was entered + */ + AR_GENIVI_NEWMEDIA = 1, + /** + * the availability changed because the same media was entered + */ + AR_GENIVI_SAMEMEDIA = 2, + /** + * the availability changed because there is no media + */ + AR_GENIVI_NOMEDIA = 3, + /** + * the availability changed because of a temperature event + */ + AR_GENIVI_TEMPERATURE = 4, + /** + * the availability changed because of a voltage event + */ + AR_GENIVI_VOLTAGE = 5, + /** + * the availability changed because of fatal errors reading or accessing media + */ + AR_GENIVI_ERRORMEDIA = 6, + AR_MAX + }; + + /** + * product specific identifier of property + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_ClassProperty_e + { + /** + * default + */ + CP_UNKNOWN = 0, + /** + * defines the source type of a source. Project specific, could be for example differentiation between interrupt source and main source. + */ + CP_GENIVI_SOURCE_TYPE = 1, + /** + * defines the SINK_TYPE. Project specific + */ + CP_GENIVI_SINK_TYPE = 2, + CP_MAX + }; + + /** + * The given ramp types here are just a possiblity. for products, different ramp types can be defined here. + * It is in the responsibility of the product to make sure that the routing plugins are aware of the ramp types used. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_RampType_e + { + RAMP_UNKNOWN = 0, + /** + * this ramp type triggers a direct setting of the value without a ramp + */ + RAMP_GENIVI_DIRECT = 1, + /** + * This ramp type will set the volume as fast as possible. + */ + RAMP_GENIVI_NO_PLOB = 2, + RAMP_GENIVI_EXP_INV = 3, + RAMP_GENIVI_LINEAR = 4, + RAMP_GENIVI_EXP = 5, + RAMP_MAX + }; + + /** + * sound properties. Within genivi only the standard properties are defined, for products these need to be extended. + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_SoundPropertyType_e + { + /** + * default + */ + SP_UNKNOWN = 0, + /** + * example treble value min =-10 max =10 + */ + SP_EXAMPLE_TREBLE = 1, + /** + * example mid value min =-10 max =10 + */ + SP_EXAMPLE_MID = 2, + /** + * example bass value min =-10 max =10 + */ + SP_EXAMPLE_BASS = 3, + SP_MAX + }; + + /** + * Here are all SoundProperties that can be set via the CommandInterface. Product specific + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_MainSoundPropertyType_e + { + /** + * default + */ + MSP_UNKNOWN = 0, + /** + * example value between -10 and +10 + */ + MSP_EXAMPLE_TREBLE = 1, + /** + * example value between -10 and +10 + */ + MSP_EXAMPLE_MID = 2, + /** + * example value between -10 and +10 + */ + MSP_EXAMPLE_BASS = 3, + MSP_MAX + }; + + /** + * describes the different system properties. Project specific + * @author Christian Mueller + * @created 29-Feb-2012 6:16:40 PM + */ + enum am_SystemPropertyType_e + { + /** + * default + */ + SYP_UNKNOWN = 0, + SYP_MAX + }; +} +#endif // !defined(EA_3B985F0B_FAF4_4ad9_B5EA_59C989D2321B__INCLUDED_) diff --git a/include/routing/IAmRoutingReceive.h b/include/routing/IAmRoutingReceive.h new file mode 100644 index 0000000..d654d23 --- /dev/null +++ b/include/routing/IAmRoutingReceive.h @@ -0,0 +1,348 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_8A0F2164_0638_43df_A114_D343F60C0938__INCLUDED_) +#define EA_8A0F2164_0638_43df_A114_D343F60C0938__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" + +namespace am { +class CAmDbusWrapper; +class CAmSocketHandler; +} + + +#define RoutingReceiveVersion "1.0" +namespace am { + /** + * Routing Receive sendInterface description. This class implements everything from RoutingAdapter -> Audiomanager + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:44 PM + */ + class IAmRoutingReceive + { + + public: + IAmRoutingReceive() { + + } + + virtual ~IAmRoutingReceive() { + + } + + /** + * acknowledges a asyncConnect + * + * @param handle + * @param connectionID + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) =0; + /** + * acknowledges a asyncDisconnect + * + * @param handle + * @param connectionID + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) =0; + /** + * acknowledges a asyncsetSinkVolume + * + * @param handle + * @param volume The current actual value that is set + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; + /** + * acknowledges a asyncsetSourceVolume + * + * @param handle handle that belongs to the change + * @param volume the current volume + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; + /** + * acknowlegde for asyncSetSourceState + * + * @param handle + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSourceState(const am_Handle_s handle, const am_Error_e error) =0; + /** + * acknowledges asyncSetSinkSoundProperties + * + * @param handle + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; + /** + * acknowledges asyncSetSinkSoundProperty + * + * @param handle + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; + /** + * acknowledges asyncSetSourceSoundProperties + * + * @param handle + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; + /** + * acknowledges asyncSetSourceSoundProperty + * + * @param handle + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; + /** + * acknowledges asyncCrossFade + * + * @param handle + * @param hotSink this is the current hot sink, HS_INTERMEDIATE is here when a crossfading action did not reach the end + * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error + */ + virtual void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) =0; + /** + * acknowledges a volume tick. This can be used to display volumechanges during ramps + * + * @param handle + * @param sourceID + * @param volume + */ + virtual void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) =0; + /** + * acknowledges a volume tick. This can be used to display volumechanges during ramps + * + * @param handle + * @param sinkID + * @param volume + */ + virtual void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) =0; + /** + * This function returns the ID to the given domainName. If already a domain is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the domain. The other parameters of the domain will be overwritten when the domain is registered. + * @return E_OK on success, E_UNKNOWN on error + * + * @param name + * @param domainID + */ + virtual am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID) =0; + /** + * registers a domain + * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error + * + * @param domainData domainID in am_Domain_s must be 0! + * @param domainID + */ + virtual am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID) =0; + /** + * deregisters a domain. All sources, sinks, gateways and crossfaders from that domain will be removed as well. + * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error + * + * @param domainID < the nonde of the bus + */ + virtual am_Error_e deregisterDomain(const am_domainID_t domainID) =0; + /** + * registers a gateway. @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error + * + * @param gatewayData In a fixed setup, the gatewayID must be below 100. In a dynamic setup, the gatewayID shall be 0. listSourceFormats and listSinkFormats are empty at registration time. Values are taken over when sources and sinks are registered. + * + * + * @param gatewayID + */ + virtual am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; + /** + * deregisters a gateway. Also removes all sinks and sources of the controlling domain. + * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error + * + * @param gatewayID domainID of the control domain + */ + virtual am_Error_e deregisterGateway(const am_gatewayID_t gatewayID) =0; + /** + * This function returns the ID to the given sinkName. If already a sink is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the sink. The other parameters of the sink will be overwritten when the sink is registered. + * @return E_OK on success, E_UNKNOWN on error + * + * @param name ID is not valid since not created yet + * @param sinkID + */ + virtual am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID) =0; + /** + * Registers a sink. If the sink is part of a gateway, the listconnectionFormats is copied to the gatewayInformation + * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error + * + * @param sinkData In a fixed setup, the sinkID within am_Sink_s must be below 100. In a dynamic setup the sinkID must be 0 in am_Sink_s. + * @param sinkID + */ + virtual am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; + /** + * deregisters a sink. + * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error + * + * @param sinkID + */ + virtual am_Error_e deregisterSink(const am_sinkID_t sinkID) =0; + /** + * This function returns the ID to the given sourceName. If already a source is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the source. The other parameters of the source will be overwritten when the source is registered. + * @return E_OK on success, E_UNKNOWN on error + * + * @param name + * @param sourceID + */ + virtual am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID) =0; + /** + * registers a source. If the source is part of a gateway, the listconnectionFormats is copied to the gatewayInformation + * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXIST if either name or sourceID already exists + * + * @param sourceData In a fixed setup, the sourceID within am_Source_s must be below 100. In a dynamic setup the sourceID must be 0 in am_Source_s + * @param sourceID + */ + virtual am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; + /** + * deregisters a source + * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error + * + * @param sourceID + */ + virtual am_Error_e deregisterSource(const am_sourceID_t sourceID) =0; + /** + * this function registers a crossfader. + * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error + * + * @param crossfaderData in a fixed setup, the crossfaderID must be below 100. In a dynamic setup the crossfasderID shall be 0 + * @param crossfaderID + */ + virtual am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; + /** + * this function deregisters a crossfader. removes all sources and sinks assiated as well. + * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error + * + * @param crossfaderID + */ + virtual am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID) =0; + /** + * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. + * @return E_OK on succes, E_DATABASE_ERROR on error + * + * @param name + * @param sourceClassID + */ + virtual am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) =0; + /** + * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. + * @return E_OK on succes, E_DATABASE_ERROR on error + * + * @param name + * @param sinkClassID + */ + virtual am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) =0; + /** + * is called when a low level interrupt changes it status. + * + * @param sourceID + * @param interruptState + */ + virtual void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) =0; + /** + * This hook is called when all elements from a domain are registered. + * Is used by the Controller to know when all expected domains are finally registered + * + * @param domainID + */ + virtual void hookDomainRegistrationComplete(const am_domainID_t domainID) =0; + /** + * is called when a sink changes its availability + * + * @param sinkID + * @param availability + */ + virtual void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; + /** + * is called when a source changes its availability + * + * @param sourceID + * @param availability + */ + virtual void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; + /** + * is called when a domain changes its status. This used for early domains only + * + * @param domainID + * @param domainState + */ + virtual void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) =0; + /** + * is called when the timinginformation (delay) changed for a connection. + * + * @param connectionID + * @param delay + */ + virtual void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) =0; + /** + * this function is used to send out all data that has been changed in an early state. + * @return E_OK on success, E_UNKNOWN on error + * + * @param earlyData + */ + virtual void sendChangedData(const std::vector& earlyData) =0; + /** + * this function is used to retrieve a pointer to the dBusConnectionWrapper + * @return E_OK if pointer is valid, E_UKNOWN if AudioManager was compiled without DBus Support + * + * @param dbusConnectionWrapper This is a wrapper class that is needed to keep dbus inclusions away from the interface. The DBusWrapperClass will return the pointer to the DbusConnection call (getDBusConnection) + */ + virtual am_Error_e getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const =0; + /** + * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. + * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, + * + * @param socketHandler + */ + virtual am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) const =0; + /** + * This function returns the version of the interface + * + * @param version retrieves the verison of the interface + */ + virtual void getInterfaceVersion(std::string& version) const =0; + /** + * confirms the setRoutingReady Command + * + * @param handle the handle that was given via setRoutingReady + */ + virtual void confirmRoutingReady(const uint16_t handle) =0; + /** + * confirms the setRoutingRundown Command + * + * @param handle handle that was given via setRoutingRundown + */ + virtual void confirmRoutingRundown(const uint16_t handle) =0; + + }; +} +#endif // !defined(EA_8A0F2164_0638_43df_A114_D343F60C0938__INCLUDED_) diff --git a/include/routing/IAmRoutingSend.h b/include/routing/IAmRoutingSend.h new file mode 100644 index 0000000..d22489b --- /dev/null +++ b/include/routing/IAmRoutingSend.h @@ -0,0 +1,204 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * @author Christian Mueller, BMW + * + * @copyright + * { + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * } + * + * + * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN + */ +#if !defined(EA_98A8173D_A5F4_4ee2_B909_152612E7BF00__INCLUDED_) +#define EA_98A8173D_A5F4_4ee2_B909_152612E7BF00__INCLUDED_ + +#include +#include +#include "audiomanagertypes.h" + +namespace am { +class IAmRoutingReceive; +} + +#include "IAmRoutingReceive.h" + +#define RoutingSendVersion "1.0" +namespace am { + /** + * This class implements everything from Audiomanager -> RoutingAdapter + * There are two rules that have to be kept in mind when implementing against this interface:\n + * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n + * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n + * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n + * For more information, please check CAmSerializer + * @author Christian Mueller + * @created 29-Feb-2012 6:16:44 PM + */ + class IAmRoutingSend + { + + public: + IAmRoutingSend() { + + } + + virtual ~IAmRoutingSend() { + + } + + /** + * starts up the interface. In the implementations, here is the best place for init routines. + * + * @param routingreceiveinterface pointer to the receive interface + */ + virtual am_Error_e startupInterface(IAmRoutingReceive* routingreceiveinterface) =0; + /** + * indicates that the routing now ready to be used. Should be used as trigger to register all sinks, sources, etc... + * + * @param handle handle that uniquely identifies the request + */ + virtual void setRoutingReady(const uint16_t handle) =0; + /** + * indicates that the routing plugins need to be prepared to switch the power off or be ready again. + * + * @param handle the handle that uniquely identifies the request + */ + virtual void setRoutingRundown(const uint16_t handle) =0; + /** + * aborts an asynchronous action. + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if handle was not found + * + * @param handle + */ + virtual am_Error_e asyncAbort(const am_Handle_s handle) =0; + /** + * connects a source to a sink + * @return E_OK on success, E_UNKNOWN on error, E_WRONG_FORMAT in case am_ConnectionFormat_e does not match + * + * @param handle + * @param connectionID + * @param sourceID + * @param sinkID + * @param connectionFormat + */ + virtual am_Error_e asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) =0; + /** + * disconnect a connection with given connectionID + * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if connection was not found + * + * @param handle + * @param connectionID + */ + virtual am_Error_e asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) =0; + /** + * this method is used to set the volume of a sink. This function is used to drive ramps, to mute or unmute or directly set the value. The difference is made through the ramptype. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if new volume is out of range + * + * @param handle + * @param sinkID + * @param volume + * @param ramp + * @param time + */ + virtual am_Error_e asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; + /** + * sets the volume of a source. This method is used to set the volume of a sink. This function is used to drive ramps, to mute or unmute or directly set the value. The difference is made through the ramptype. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if volume is out of range. + * triggers the acknowledge ackSourceVolumeChange + * + * @param handle + * @param sourceID + * @param volume + * @param ramp + * @param time + */ + virtual am_Error_e asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; + /** + * This function is used to set the source state of a particular source. + * @return E_OK on success, E_UNKNOWN on error + * + * @param handle + * @param sourceID + * @param state + */ + virtual am_Error_e asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) =0; + /** + * this function sets the sinksoundproperty. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range + * + * @param handle + * @param sinkID + * @param listSoundProperties + */ + virtual am_Error_e asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties) =0; + /** + * this function sets the sinksoundproperty. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range + * + * @param handle + * @param sinkID + * @param soundProperty + */ + virtual am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) =0; + /** + * this function sets the sourcesoundproperty. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range + * + * @param handle + * @param sourceID + * @param listSoundProperties + */ + virtual am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) =0; + /** + * this function sets the sourcesoundproperty. + * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range + * + * @param handle + * @param sourceID + * @param soundProperty + */ + virtual am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) =0; + /** + * this function triggers crossfading. + * @return E_OK on success, E_UNKNOWN on error + * + * @param handle + * @param crossfaderID + * @param hotSink + * @param rampType + * @param time + */ + virtual am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) =0; + /** + * this function is used for early and late audio functions to set the domain state + * @return E_OK on success, E_UNKNOWN on error + * + * @param domainID + * @param domainState + */ + virtual am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) =0; + /** + * this method is used to retrieve the busname during startup of the plugin. Needs to be implemented + * @return E_OK on success, E_UNKNOWN on error + * + * @param BusName + */ + virtual am_Error_e returnBusName(std::string& BusName) const =0; + /** + * This function returns the version of the interface + * + * @param version + */ + virtual void getInterfaceVersion(std::string& version) const =0; + + }; +} +#endif // !defined(EA_98A8173D_A5F4_4ee2_B909_152612E7BF00__INCLUDED_) diff --git a/include/shared/CAmDbusWrapper.h b/include/shared/CAmDbusWrapper.h new file mode 100644 index 0000000..26131c2 --- /dev/null +++ b/include/shared/CAmDbusWrapper.h @@ -0,0 +1,92 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * \author Christian Mueller, BMW + * + * \section license + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef DBUSWRAPPER_H_ +#define DBUSWRAPPER_H_ + +#include +#include +#include +#include +#include "shared/CAmSocketHandler.h" + +namespace am +{ +/** + * This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins) + */ +class CAmDbusWrapper +{ +public: + CAmDbusWrapper(CAmSocketHandler* socketHandler); + virtual ~CAmDbusWrapper(); + + /** + * registers a callback that is entered as path below the main path. + * The configuration of the mainpath is done via DBusConfiguration.h + * @param vtable the vtable that holds a pointer to the callback that is called when the path is called from the dbus + * @param path the name of the path + * @param userdata pointer to the class that will handle the callback + */ + void registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata); + + /** + * returns the dbus connection + * @param connection pointer to the connection + */ + void getDBusConnection(DBusConnection*& connection) const; + + static dbus_bool_t addWatch(DBusWatch *watch, void *userData); + static void removeWatch(DBusWatch *watch, void *userData); + static void toogleWatch(DBusWatch *watch, void *userData); + + static dbus_bool_t addTimeout(DBusTimeout *timeout, void* userData); + static void removeTimeout(DBusTimeout *timeout, void* userData); + static void toggleTimeout(DBusTimeout *timeout, void* userData); + + bool dbusDispatchCallback(const sh_pollHandle_t handle, void* userData); + TAmShPollDispatch pDbusDispatchCallback; + + void dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); + TAmShPollFired pDbusFireCallback; + + bool dbusCheckCallback(const sh_pollHandle_t handle, void* userData); + TAmShPollCheck pDbusCheckCallback; + + void dbusTimerCallback(sh_timerHandle_t handle, void* userData); + TAmShTimerCallBack pDbusTimerCallback; + +private: + static CAmDbusWrapper* mpReference; + static DBusHandlerResult cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference); + dbus_bool_t addWatchDelegate(DBusWatch * watch, void* userData); + void removeWatchDelegate(DBusWatch *watch, void *userData); + void toogleWatchDelegate(DBusWatch *watch, void *userData); + dbus_bool_t addTimeoutDelegate(DBusTimeout *timeout, void* userData); + void removeTimeoutDelegate(DBusTimeout *timeout, void* userData); + void toggleTimeoutDelegate(DBusTimeout *timeout, void* userData); + DBusObjectPathVTable mObjectPathVTable; + DBusConnection* mpDbusConnection; + DBusError mDBusError; + std::list mListNodes; + std::vector mpListTimerhandles; + CAmSocketHandler *mpSocketHandler; + std::map mMapHandleWatch; +}; + +} + +#endif /* DBUSWRAPPER_H_ */ diff --git a/include/shared/CAmDltWrapper.h b/include/shared/CAmDltWrapper.h new file mode 100644 index 0000000..ea6f246 --- /dev/null +++ b/include/shared/CAmDltWrapper.h @@ -0,0 +1,820 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * \author Christian Mueller, BMW + * + * \section license + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef DLTWRAPPER_H_ +#define DLTWRAPPER_H_ + +#include "config.h" + +#ifdef WITH_DLT +#include +#else + +#include + +namespace am { + +#define DLT_USER_BUF_MAX_SIZE 2048 + +/** + * This structure is used for every context used in an application. + */ +typedef struct +{ + char contextID[4]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ +} DltContext; + +/** + * Definitions of DLT log level + */ +typedef enum +{ + DLT_LOG_DEFAULT = -1, /**< Default log level */ + DLT_LOG_OFF = 0x00, /**< Log level off */ + DLT_LOG_FATAL = 0x01, /**< fatal system error */ + DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ + DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ + DLT_LOG_INFO = 0x04, /**< informational */ + DLT_LOG_DEBUG = 0x05, /**< debug */ + DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ +} DltLogLevelType; + +/** + * This structure is used for context data used in an application. + */ +typedef struct +{ + DltContext *handle; /**< pointer to DltContext */ + char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/ + int32_t size; /**< payload size */ + int32_t log_level; /**< log level */ + int32_t trace_status; /**< trace status */ + int32_t args_num; /**< number of arguments for extended header*/ + uint8_t mcnt; /**< message counter */ + char* context_description; /**< description of context */ +} DltContextData; + +#define DLT_DECLARE_CONTEXT(CONTEXT) \ +DltContext CONTEXT; + + +#define DLT_IMPORT_CONTEXT(CONTEXT) \ +extern DltContext CONTEXT; + +} + +#endif + +#include + +namespace am +{ + +/** + * Wraps around the dlt wrapper. This class is instantiated as a singleton and offers a default + * context (maincontext) that is registered to log to. + * Logging under the default context can simply be done with the logInfo/logError templates with up to 10 values at a time. + * For logging with a different context, you can use the log template. First register a context with registerContext. + */ +class CAmDltWrapper +{ +public: + static CAmDltWrapper* instance(const bool enableNoDLTDebug = false); + void registerApp(const char *appid, const char * description); + void registerContext(DltContext& handle, const char *contextid, const char * description); + void unregisterContext(DltContext& handle); + + void init(DltLogLevelType loglevel, DltContext* context = NULL); + void send(); + void append(const int8_t value); + void append(const uint8_t value); + void append(const int16_t value); + void append(const uint16_t value); + void append(const int32_t value); + void append(const uint32_t value); + void append(const char*& value); + void append(const std::string& value); + void append(const bool value); +#ifndef WITH_DLT + void enableNoDLTDebug(const bool enableNoDLTDebug = true); +#endif + ~CAmDltWrapper(); +private: + CAmDltWrapper(const bool enableNoDLTDebug); //is private because of singleton pattern +#ifndef WITH_DLT + template void appendNoDLT(T value); + bool mEnableNoDLTDebug; +#endif + DltContext mDltContext; //!< the default context + DltContextData mDltContextData; //!< contextdata + static CAmDltWrapper* mpDLTWrapper; //!< pointer to the wrapper instance + +}; + +/** + * returns the instance of the CAmDltWrapper + * @return + */ +inline CAmDltWrapper* getWrapper() +{ + return CAmDltWrapper::instance(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + */ +template void logInfo(T value) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + */ +template void logInfo(T value, T1 value1) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + */ +template void logInfo(T value, T1 value1, T2 value2) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_INFO); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + * @param value9 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->append(value9); + inst->send(); +} + +/** + * logs a given value with infolevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + * @param value9 + * @param value10 + */ +template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->append(value9); + inst->append(value10); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + */ +template void logError(T value) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + */ +template void logError(T value, T1 value1) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + */ +template void logError(T value, T1 value1, T2 value2) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + * @param value9 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->append(value9); + inst->send(); +} + +/** + * logs a given value with errorlevel with the default context + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + * @param value9 + * @param value10 + */ +template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(DLT_LOG_ERROR); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->append(value9); + inst->append(value10); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->send(); +} + +/** + * logs a given value with a given context (register first!) and given loglevel + * @param context + * @param loglevel + * @param value + * @param value1 + * @param value2 + * @param value3 + * @param value4 + * @param value5 + * @param value6 + * @param value7 + * @param value8 + */ +template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) +{ + CAmDltWrapper* inst(getWrapper()); + inst->init(loglevel, context); + inst->append(value); + inst->append(value1); + inst->append(value2); + inst->append(value3); + inst->append(value4); + inst->append(value5); + inst->append(value6); + inst->append(value7); + inst->append(value8); + inst->send(); +} +} + +#endif /* DLTWRAPPER_H_ */ diff --git a/include/shared/CAmSerializer.h b/include/shared/CAmSerializer.h new file mode 100644 index 0000000..a27edaf --- /dev/null +++ b/include/shared/CAmSerializer.h @@ -0,0 +1,708 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * \author Christian Mueller, BMW + * + * \section license + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef CAMSERIALIZER_H_ +#define CAMSERIALIZER_H_ + +#include +#include +#include +#include +#include +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" + +//todo: performance improvement we could implement a memory pool that is more efficient here and avoids allocation and deallocation times. + +namespace am +{ +/** + * magic class that does the serialization of functions calls + * The constructor must be called within the main threadcontext, after that using the + * overloaded template function call will serialize all calls and call them within the + * main thread context.\n + * If you want to use synchronous calls make sure that you use one instance of this class + * per thread otherwise you could be lost in never returning calls. + */ +class CAmSerializer +{ +private: + + /** + * Prototype for a delegate + */ + class CAmDelegate + { + public: + virtual ~CAmDelegate(){}; + virtual bool call(int* pipe)=0; + + }; + + typedef CAmDelegate* CAmDelegagePtr; //!< pointer to a delegate + + /** + * delegate template for no argument + */ + template class CAmNoArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + void (TClass::*mFunction)(); + + public: + CAmNoArgDelegate(TClass* instance, void(TClass::*function)()) : + mInstance(instance), // + mFunction(function){}; + + bool call(int* pipe) + { + (void)pipe; + (*mInstance.*mFunction)(); + return true; + }; + }; + + /** + * delegate template for one argument + */ + template class CAmOneArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + void (TClass::*mFunction)(Targ); + Targ mArgument; + + public: + CAmOneArgDelegate(TClass* instance, void(TClass::*function)(Targ), Targ argument) : + mInstance(instance), // + mFunction(function), // + mArgument(argument) { }; + + bool call(int* pipe) + { + (void)pipe; + (*mInstance.*mFunction)(mArgument); + return true; + }; + }; + + /** + * delegate template for two arguments + */ + template class CAmTwoArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + void (TClass::*mFunction)(Targ argument,Targ1 argument1); + Targ mArgument; + Targ1 mArgument1; + + public: + CAmTwoArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1), Targ argument, Targ1 argument1) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1){}; + + bool call(int* pipe) + { + (void)pipe; + (*mInstance.*mFunction)(mArgument,mArgument1); + return true; + }; + }; + + /** + * delegate template for three arguments + */ + template class CAmThreeArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + void (TClass::*mFunction)(Targ argument,Targ1 argument1,Targ2 argument2); + Targ mArgument; + Targ1 mArgument1; + Targ2 mArgument2; + + public: + CAmThreeArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1,Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1), // + mArgument2(argument2){}; + + bool call(int* pipe) + { + (void)pipe; + (*mInstance.*mFunction)(mArgument,mArgument1,mArgument2); + return true; + }; + }; + + /** + * delegate template for four arguments + */ + template class CAmFourArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + void (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3); + Targ mArgument; + Targ1 mArgument1; + Targ2 mArgument2; + Targ3 mArgument3; + + public: + CAmFourArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1,Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1), // + mArgument2(argument2), // + mArgument3(argument3){}; + + bool call(int* pipe) + { + (void)pipe; + (*mInstance.*mFunction)(mArgument,mArgument1,mArgument2,mArgument3); + return true; + }; + }; + + /** + * Template for synchronous calls with no argument + */ + template class CAmSyncNoArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + TretVal (TClass::*mFunction)(); + TretVal mRetval; + + public: + friend class CAmSerializer; + CAmSyncNoArgDelegate(TClass* instance, TretVal(TClass::*function)()) : + mInstance(instance), // + mFunction(function), // + mRetval(){}; + + bool call(int* pipe) + { + mRetval = (*mInstance.*mFunction)(); + write(pipe[1], this, sizeof(this)); + return false; + }; + + TretVal returnResults() + { + return mRetval; + } + }; + + /** + * template for synchronous calls with one argument + */ + template class CAmSyncOneArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + TretVal (TClass::*mFunction)(Targ argument); + Targ mArgument; + TretVal mRetval; + + public: + friend class CAmSerializer; + CAmSyncOneArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument), Targ argument) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mRetval(){}; + + bool call(int* pipe) + { + mRetval = (*mInstance.*mFunction)(mArgument); + write(pipe[1], this, sizeof(this)); + return false; + }; + + TretVal returnResults(Targ& argument) + { + argument=mArgument; + return mRetval; + } + }; + + /** + * template for synchronous calls with two arguments + */ + template class CAmSyncTwoArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + TretVal (TClass::*mFunction)(TargCall,TargCall1); + Targ mArgument; + Targ1 mArgument1; + TretVal mRetval; + + public: + friend class CAmSerializer; + CAmSyncTwoArgDelegate(TClass* instance, TretVal(TClass::*function)(TargCall, TargCall1), Targ& argument, Targ1& argument1) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1), // + mRetval(){}; + + bool call(int* pipe) + { + mRetval = (*mInstance.*mFunction)(mArgument, mArgument1); + write(pipe[1], this, sizeof(this)); + return false; + }; + + TretVal returnResults(Targ& argument, Targ1& argument1) + { + argument=mArgument; + argument1=mArgument1; + return mRetval; + } + }; + + /** + * template for synchronous calls with three arguments + */ + template class CAmSyncThreeArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + TretVal (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2); + Targ mArgument; + Targ1 mArgument1; + Targ2 mArgument2; + TretVal mRetval; + + public: + CAmSyncThreeArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1,Targ2 argument2) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1), // + mArgument2(argument2), // + mRetval(){}; + + bool call(int* pipe) + { + mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); + write(pipe[1], this, sizeof(this)); + return false; + }; + + TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2) + { + argument=mArgument; + argument1=mArgument1; + argument2=mArgument2; + return mRetval; + } + }; + + /** + * template for synchronous calls with four arguments + */ + template class CAmSyncFourArgDelegate: public CAmDelegate + { + private: + TClass* mInstance; + TretVal (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3); + Targ mArgument; + Targ1 mArgument1; + Targ2 mArgument2; + Targ3 mArgument3; + TretVal mRetval; + + CAmSyncFourArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : + mInstance(instance), // + mFunction(function), // + mArgument(argument), // + mArgument1(argument1), // + mArgument2(argument2), // + mArgument3(argument3), // + mRetval(){}; + + bool call(int* pipe) + { + mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3); + write(pipe[1], this, sizeof(this)); + return false; + }; + + TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) + { + argument=mArgument; + argument1=mArgument1; + argument2=mArgument2; + argument3=mArgument3; + return mRetval; + } + }; + + /** + * rings the line of the pipe and adds the delegate pointer to the queue + * @param p delegate pointer + */ + inline void send(CAmDelegagePtr p) + { + if (write(mPipe[1], &p, sizeof(p)) == -1) + { + throw std::runtime_error("could not write to pipe !"); + } + } + int mPipe[2]; //!< the pipe + int mReturnPipe[2]; //!< pipe handling returns + std::deque mListDelegatePoiters; //!< intermediate queue to store the pipe results + +public: + + /** + * calls a function with no arguments threadsafe + * @param instance the instance of the class that shall be called + * @param function the function that shall be called as memberfunction pointer. + * Here is an example: + * @code + * class myClass + * { + * public: + * void myfunction(); + * } + * CAmSerializer serial(&Sockethandler); + * myClass instanceMyClass; + * serial(&instanceMyClass,&myClass::myfunction); + * @endcode + */ + template + void asyncCall(TClass* instance, void(TClass::*function)()) + { + CAmDelegagePtr p(new CAmNoArgDelegate(instance, function)); + send(p); + } + + /** + * calls a function with one arguments asynchronously threadsafe + * @param instance the instance of the class that shall be called + * @param function the function that shall be called as memberfunction pointer. + * Here is an example: + * @code + * class myClass + * { + * public: + * void myfunction(int k); + * } + * CAmSerializer serial(&Sockethandler); + * myClass instanceMyClass; + * serial(&instanceMyClass,&myClass::myfunction,k); + * @endcode + */ + template + void asyncCall(TClass1* instance, void(TClass1::*function)(Targ), Targ argument) + { + CAmDelegagePtr p(new CAmOneArgDelegate(instance, function, argument)); + send(p); + } + + /** + * calls a function with two arguments asynchronously threadsafe. for more see asyncCall with one argument + * @param instance + * @param function + * @param argument + * @param argument1 + */ + template + void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1), Targ argument, Targ1 argument1) + { + CAmDelegagePtr p(new CAmTwoArgDelegate(instance, function, argument,argument1)); + send(p); + } + + /** + * calls a function with three arguments asynchronously threadsafe. for more see asyncCall with one argument + * @param instance + * @param function + * @param argument + * @param argument1 template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1), TretVal& retVal, Targ& argument, Targ1& argument1) + { + CAmSyncTwoArgDelegate* p(new CAmSyncTwoArgDelegate(instance, function, argument, argument1)); + send(static_cast(p)); + int numReads; + CAmDelegagePtr ptr; + if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + //working with friend class here is not the finest of all programming stiles but it works... + retVal=p->returnResults(argument,argument1); + } + * @param argument2 + */ + template + void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) + { + CAmDelegagePtr p(new CAmThreeArgDelegate(instance, function, argument,argument1, argument2)); + send(p); + } + + /** + * calls a function with four arguments asynchronously threadsafe. for more see asyncCall with one argument + * @param instance + * @param function + * @param argument + * @param argument1 + * @param argument2 + * @param argument3 + */ + template + void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) + { + CAmDelegagePtr p(new CAmFourArgDelegate(instance, function, argument,argument1, argument2, argument3)); + send(p); + } + + /** + * calls a synchronous function with no arguments threadsafe + * @param instance the instance of the class that shall be called + * @param function the function that shall be called as memberfunction pointer. + * Here is an example: + * @code + * class myClass + * { + * public: + * am_Error_e myfunction(); + * } + * CAmSerializer serial(&Sockethandler); + * myClass instanceMyClass; + * am_Error_e error; + * serial(&instanceMyClass,&myClass::myfunction, error); + * @endcode + * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments. + * + */ + template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(), TretVal& retVal) + { + CAmSyncNoArgDelegate* p(new CAmSyncNoArgDelegate(instance, function)); + send(static_cast(p)); + int numReads; + CAmDelegagePtr ptr; + if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + //working with friend class here is not the finest of all programming stiles but it works... + retVal=p->returnResults(); + delete p; + } + + /** + * calls a function with one argument synchronous threadsafe + * @param instance the instance of the class that shall be called + * @param function the function that shall be called as memberfunction pointer. + * Here is an example: + * @code + * class myClass + * { + * public: + * am_Error_e myfunction(int k); + * } + * CAmSerializer serial(&Sockethandler); + * myClass instanceMyClass; + * am_Error_e error; + * int l; + * serial(&instanceMyClass,&myClass::myfunction,error,l); + * @endcode + * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments. + */ + template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ), TretVal& retVal,Targ& argument) + { + CAmSyncOneArgDelegate* p(new CAmSyncOneArgDelegate(instance, function, argument)); + send(static_cast(p)); + int numReads; + CAmDelegagePtr ptr; + if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + //working with friend class here is not the finest of all programming stiles but it works... + retVal=p->returnResults(argument); + delete p; + } + + /** + * calls a function with two arguments synchronously threadsafe. for more see syncCall with one argument + * @param instance + * @param function + * @param retVal + * @param argument + * @param argument1 + */ + template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(TargCall,Targ1Call), TretVal& retVal, Targ& argument, Targ1& argument1) + { + CAmSyncTwoArgDelegate* p(new CAmSyncTwoArgDelegate(instance, function, argument, argument1)); + send(dynamic_cast(p)); + + CAmDelegagePtr ptr; + if (read(mReturnPipe[0],&ptr, sizeof(ptr)) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + retVal=p->returnResults(argument,argument1); + delete p; + } + + /** + * calls a function with three arguments synchronously threadsafe. for more see syncCall with one argument + * @param instance + * @param function + * @param retVal + * @param argument + * @param argument1 + * @param argument2 + */ + template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1,Targ2), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) + { + CAmSyncThreeArgDelegate* p(new CAmSyncThreeArgDelegate(instance, function, argument, argument1, argument2)); + send(static_cast(p)); + int numReads; + CAmDelegagePtr ptr; + if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + //working with friend class here is not the finest of all programming stiles but it works... + retVal=p->returnResults(argument, argument1, argument2); + delete p; + } + + /** + * calls a function with four arguments synchronously threadsafe. for more see syncCall with one argument + * @param instance + * @param function + * @param retVal + * @param argument + * @param argument1 + * @param argument2 + * @param argument3 + */ + template + void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1,Targ2,Targ3), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) + { + CAmSyncFourArgDelegate* p(new CAmSyncFourArgDelegate(instance, function, argument, argument1, argument2, argument3)); + send(static_cast(p)); + int numReads; + CAmDelegagePtr ptr; + if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + //working with friend class here is not the finest of all programming stiles but it works... + retVal=p->returnResults(argument, argument1, argument2, argument3); + delete p; + } + + + void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) + { + (void) handle; + (void) userData; + int numReads; + CAmDelegagePtr listPointers[3]; + if ((numReads=read(pollfd.fd,&listPointers, sizeof(listPointers))) == -1) + { + logError("CAmSerializer::receiverCallback could not read pipe!"); + throw std::runtime_error("CAmSerializer Could not read pipe!"); + } + mListDelegatePoiters.assign(listPointers, listPointers+(numReads/sizeof(CAmDelegagePtr))); + } + + bool checkerCallback(const sh_pollHandle_t handle, void* userData) + { + (void) handle; + (void) userData; + if (mListDelegatePoiters.empty()) + return false; + return true; + } + + bool dispatcherCallback(const sh_pollHandle_t handle, void* userData) + { + (void) handle; + (void) userData; + CAmDelegagePtr delegatePoiter = mListDelegatePoiters.front(); + mListDelegatePoiters.pop_front(); + if(delegatePoiter->call(mReturnPipe)) + delete delegatePoiter; + if (mListDelegatePoiters.empty()) + return false; + return true; + } + + TAmShPollFired receiverCallbackT; + TAmShPollDispatch dispatcherCallbackT; + TAmShPollCheck checkerCallbackT; + + /** + * The constructor must be called in the mainthread context ! + * @param iSocketHandler pointer to the sockethandler + */ + CAmSerializer(CAmSocketHandler *iSocketHandler) : + mPipe(), // + mListDelegatePoiters(), // + receiverCallbackT(this, &CAmSerializer::receiverCallback), // + dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback), // + checkerCallbackT(this, &CAmSerializer::checkerCallback) + { + if (pipe(mPipe) == -1) + { + logError("CAmSerializer could not create pipe!"); + throw std::runtime_error("CAmSerializer Could not open pipe!"); + } + + if (pipe(mReturnPipe) == -1) + { + logError("CAmSerializer could not create mReturnPipe!"); + throw std::runtime_error("CAmSerializer Could not open mReturnPipe!"); + } + + short event = 0; + sh_pollHandle_t handle; + event |= POLLIN; + iSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, NULL, &dispatcherCallbackT, NULL, handle); + } + + ~CAmSerializer(){} +}; +} /* namespace am */ +#endif /* CAMSERIALIZER_H_ */ diff --git a/include/shared/CAmSocketHandler.h b/include/shared/CAmSocketHandler.h new file mode 100644 index 0000000..e0ea797 --- /dev/null +++ b/include/shared/CAmSocketHandler.h @@ -0,0 +1,258 @@ +/** Copyright (c) 2012 GENIVI Alliance + * Copyright (c) 2012 BMW + * + * \author Christian Mueller, BMW + * + * \section license + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef SOCKETHANDLER_H_ +#define SOCKETHANDLER_H_ + +#include "audiomanagertypes.h" +#include +#include +#include +#include +#include +#include +#include + +namespace am +{ + +static volatile sig_atomic_t gDispatchDone = 0; //this global is used to stop the mainloop + +typedef uint16_t sh_timerHandle_t; //! mListPollfd_t; //! mListPoll_t; //! mListTimer; //! mListActiveTimer; //! class TAmShTimerCallBack: public CAmShTimerCallBack +{ +private: + TClass* mInstance; + void (TClass::*mFunction)(sh_timerHandle_t handle, void* userData); + +public: + TAmShTimerCallBack(TClass* instance, void(TClass::*function)(sh_timerHandle_t handle, void* userData)) : + mInstance(instance),// + mFunction(function) {}; + + virtual void Call(sh_timerHandle_t handle, void* userData) + { + (*mInstance.*mFunction)(handle, userData); + } +}; + +/** + * template to create the functor for a class + */ +template class TAmShPollPrepare: public CAmShPollPrepare +{ +private: + TClass* mInstance; + void (TClass::*mFunction)(const sh_timerHandle_t handle, void* userData); + +public: + TAmShPollPrepare(TClass* instance, void(TClass::*function)(const sh_timerHandle_t handle, void* userData)) : + mInstance(instance), // + mFunction(function){}; + + virtual void Call(const sh_timerHandle_t handle, void* userData) + { + (*mInstance.*mFunction)(handle, userData); + }; +}; + +template class TAmShPollFired: public CAmShPollFired +{ +private: + TClass* mInstance; + void (TClass::*mFunction)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); + +public: + TAmShPollFired(TClass* instance, void(TClass::*function)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)) : + mInstance(instance), // + mFunction(function){}; + + virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) + { + (*mInstance.*mFunction)(pollfd, handle, userData); + }; +}; + +template class TAmShPollCheck: public CAmShPollCheck +{ +private: + TClass* mInstance; + bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData); + +public: + TAmShPollCheck(TClass* instance, bool(TClass::*function)(const sh_pollHandle_t handle, void* userData)) : + mInstance(instance), // + mFunction(function){}; + + virtual bool Call(const sh_pollHandle_t handle, void* userData) + { + return (*mInstance.*mFunction)(handle, userData); + }; +}; + +template class TAmShPollDispatch: public CAmShPollDispatch +{ +private: + TClass* mInstance; + bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData); + +public: + TAmShPollDispatch(TClass* instance, bool(TClass::*function)(const sh_pollHandle_t handle, void* userData)) : + mInstance(instance), // + mFunction(function) {}; + + virtual bool Call(const sh_pollHandle_t handle, void* userData) + { + return (*mInstance.*mFunction)(handle, userData); + }; +}; +} /* namespace am */ +#endif /* SOCKETHANDLER_H_ */ diff --git a/includes/CAmSerializer.h b/includes/CAmSerializer.h deleted file mode 100644 index ab6ff03..0000000 --- a/includes/CAmSerializer.h +++ /dev/null @@ -1,708 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef CAMSERIALIZER_H_ -#define CAMSERIALIZER_H_ - -#include -#include -#include -#include -#include -#include "DLTWrapper.h" -#include "SocketHandler.h" - -//todo: performance improvement we could implement a memory pool that is more efficient here and avoids allocation and deallocation times. - -namespace am -{ -/** - * magic class that does the serialization of functions calls - * The constructor must be called within the main threadcontext, after that using the - * overloaded template function call will serialize all calls and call them within the - * main thread context.\n - * If you want to use synchronous calls make sure that you use one instance of this class - * per thread otherwise you could be lost in never returning calls. - */ -class CAmSerializer -{ -private: - - /** - * Prototype for a delegate - */ - class CAmDelegate - { - public: - virtual ~CAmDelegate(){}; - virtual bool call(int* pipe)=0; - - }; - - typedef CAmDelegate* CAmDelegagePtr; //!< pointer to a delegate - - /** - * delegate template for no argument - */ - template class CAmNoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(); - - public: - CAmNoArgDelegate(TClass* instance, void(TClass::*function)()) : - mInstance(instance), // - mFunction(function){}; - - bool call(int* pipe) - { - (void)pipe; - (*mInstance.*mFunction)(); - return true; - }; - }; - - /** - * delegate template for one argument - */ - template class CAmOneArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ); - Targ mArgument; - - public: - CAmOneArgDelegate(TClass* instance, void(TClass::*function)(Targ), Targ argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument) { }; - - bool call(int* pipe) - { - (void)pipe; - (*mInstance.*mFunction)(mArgument); - return true; - }; - }; - - /** - * delegate template for two arguments - */ - template class CAmTwoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument,Targ1 argument1); - Targ mArgument; - Targ1 mArgument1; - - public: - CAmTwoArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1), Targ argument, Targ1 argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1){}; - - bool call(int* pipe) - { - (void)pipe; - (*mInstance.*mFunction)(mArgument,mArgument1); - return true; - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument,Targ1 argument1,Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1,Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2){}; - - bool call(int* pipe) - { - (void)pipe; - (*mInstance.*mFunction)(mArgument,mArgument1,mArgument2); - return true; - }; - }; - - /** - * delegate template for four arguments - */ - template class CAmFourArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - - public: - CAmFourArgDelegate(TClass* instance, void(TClass::*function)(Targ argument,Targ1 argument1,Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3){}; - - bool call(int* pipe) - { - (void)pipe; - (*mInstance.*mFunction)(mArgument,mArgument1,mArgument2,mArgument3); - return true; - }; - }; - - /** - * Template for synchronous calls with no argument - */ - template class CAmSyncNoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(); - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncNoArgDelegate(TClass* instance, TretVal(TClass::*function)()) : - mInstance(instance), // - mFunction(function), // - mRetval(){}; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(); - write(pipe[1], this, sizeof(this)); - return false; - }; - - TretVal returnResults() - { - return mRetval; - } - }; - - /** - * template for synchronous calls with one argument - */ - template class CAmSyncOneArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(Targ argument); - Targ mArgument; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncOneArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument), Targ argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mRetval(){}; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument); - write(pipe[1], this, sizeof(this)); - return false; - }; - - TretVal returnResults(Targ& argument) - { - argument=mArgument; - return mRetval; - } - }; - - /** - * template for synchronous calls with two arguments - */ - template class CAmSyncTwoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall,TargCall1); - Targ mArgument; - Targ1 mArgument1; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncTwoArgDelegate(TClass* instance, TretVal(TClass::*function)(TargCall, TargCall1), Targ& argument, Targ1& argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mRetval(){}; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1); - write(pipe[1], this, sizeof(this)); - return false; - }; - - TretVal returnResults(Targ& argument, Targ1& argument1) - { - argument=mArgument; - argument1=mArgument1; - return mRetval; - } - }; - - /** - * template for synchronous calls with three arguments - */ - template class CAmSyncThreeArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - TretVal mRetval; - - public: - CAmSyncThreeArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1,Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mRetval(){}; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - write(pipe[1], this, sizeof(this)); - return false; - }; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2) - { - argument=mArgument; - argument1=mArgument1; - argument2=mArgument2; - return mRetval; - } - }; - - /** - * template for synchronous calls with four arguments - */ - template class CAmSyncFourArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - TretVal mRetval; - - CAmSyncFourArgDelegate(TClass* instance, TretVal(TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3), // - mRetval(){}; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3); - write(pipe[1], this, sizeof(this)); - return false; - }; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) - { - argument=mArgument; - argument1=mArgument1; - argument2=mArgument2; - argument3=mArgument3; - return mRetval; - } - }; - - /** - * rings the line of the pipe and adds the delegate pointer to the queue - * @param p delegate pointer - */ - inline void send(CAmDelegagePtr p) - { - if (write(mPipe[1], &p, sizeof(p)) == -1) - { - throw std::runtime_error("could not write to pipe !"); - } - } - int mPipe[2]; //!< the pipe - int mReturnPipe[2]; //!< pipe handling returns - std::deque mListDelegatePoiters; //!< intermediate queue to store the pipe results - -public: - - /** - * calls a function with no arguments threadsafe - * @param instance the instance of the class that shall be called - * @param function the function that shall be called as memberfunction pointer. - * Here is an example: - * @code - * class myClass - * { - * public: - * void myfunction(); - * } - * CAmSerializer serial(&Sockethandler); - * myClass instanceMyClass; - * serial(&instanceMyClass,&myClass::myfunction); - * @endcode - */ - template - void asyncCall(TClass* instance, void(TClass::*function)()) - { - CAmDelegagePtr p(new CAmNoArgDelegate(instance, function)); - send(p); - } - - /** - * calls a function with one arguments asynchronously threadsafe - * @param instance the instance of the class that shall be called - * @param function the function that shall be called as memberfunction pointer. - * Here is an example: - * @code - * class myClass - * { - * public: - * void myfunction(int k); - * } - * CAmSerializer serial(&Sockethandler); - * myClass instanceMyClass; - * serial(&instanceMyClass,&myClass::myfunction,k); - * @endcode - */ - template - void asyncCall(TClass1* instance, void(TClass1::*function)(Targ), Targ argument) - { - CAmDelegagePtr p(new CAmOneArgDelegate(instance, function, argument)); - send(p); - } - - /** - * calls a function with two arguments asynchronously threadsafe. for more see asyncCall with one argument - * @param instance - * @param function - * @param argument - * @param argument1 - */ - template - void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1), Targ argument, Targ1 argument1) - { - CAmDelegagePtr p(new CAmTwoArgDelegate(instance, function, argument,argument1)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see asyncCall with one argument - * @param instance - * @param function - * @param argument - * @param argument1 template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1), TretVal& retVal, Targ& argument, Targ1& argument1) - { - CAmSyncTwoArgDelegate* p(new CAmSyncTwoArgDelegate(instance, function, argument, argument1)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal=p->returnResults(argument,argument1); - } - * @param argument2 - */ - template - void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegate(instance, function, argument,argument1, argument2)); - send(p); - } - - /** - * calls a function with four arguments asynchronously threadsafe. for more see asyncCall with one argument - * @param instance - * @param function - * @param argument - * @param argument1 - * @param argument2 - * @param argument3 - */ - template - void asyncCall(TClass1* instance, void(TClass1::*function)(Targ argument,Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) - { - CAmDelegagePtr p(new CAmFourArgDelegate(instance, function, argument,argument1, argument2, argument3)); - send(p); - } - - /** - * calls a synchronous function with no arguments threadsafe - * @param instance the instance of the class that shall be called - * @param function the function that shall be called as memberfunction pointer. - * Here is an example: - * @code - * class myClass - * { - * public: - * am_Error_e myfunction(); - * } - * CAmSerializer serial(&Sockethandler); - * myClass instanceMyClass; - * am_Error_e error; - * serial(&instanceMyClass,&myClass::myfunction, error); - * @endcode - * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments. - * - */ - template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(), TretVal& retVal) - { - CAmSyncNoArgDelegate* p(new CAmSyncNoArgDelegate(instance, function)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal=p->returnResults(); - delete p; - } - - /** - * calls a function with one argument synchronous threadsafe - * @param instance the instance of the class that shall be called - * @param function the function that shall be called as memberfunction pointer. - * Here is an example: - * @code - * class myClass - * { - * public: - * am_Error_e myfunction(int k); - * } - * CAmSerializer serial(&Sockethandler); - * myClass instanceMyClass; - * am_Error_e error; - * int l; - * serial(&instanceMyClass,&myClass::myfunction,error,l); - * @endcode - * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments. - */ - template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ), TretVal& retVal,Targ& argument) - { - CAmSyncOneArgDelegate* p(new CAmSyncOneArgDelegate(instance, function, argument)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal=p->returnResults(argument); - delete p; - } - - /** - * calls a function with two arguments synchronously threadsafe. for more see syncCall with one argument - * @param instance - * @param function - * @param retVal - * @param argument - * @param argument1 - */ - template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(TargCall,Targ1Call), TretVal& retVal, Targ& argument, Targ1& argument1) - { - CAmSyncTwoArgDelegate* p(new CAmSyncTwoArgDelegate(instance, function, argument, argument1)); - send(dynamic_cast(p)); - - CAmDelegagePtr ptr; - if (read(mReturnPipe[0],&ptr, sizeof(ptr)) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - retVal=p->returnResults(argument,argument1); - delete p; - } - - /** - * calls a function with three arguments synchronously threadsafe. for more see syncCall with one argument - * @param instance - * @param function - * @param retVal - * @param argument - * @param argument1 - * @param argument2 - */ - template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1,Targ2), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) - { - CAmSyncThreeArgDelegate* p(new CAmSyncThreeArgDelegate(instance, function, argument, argument1, argument2)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal=p->returnResults(argument, argument1, argument2); - delete p; - } - - /** - * calls a function with four arguments synchronously threadsafe. for more see syncCall with one argument - * @param instance - * @param function - * @param retVal - * @param argument - * @param argument1 - * @param argument2 - * @param argument3 - */ - template - void syncCall(TClass1* instance, TretVal(TClass1::*function)(Targ,Targ1,Targ2,Targ3), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) - { - CAmSyncFourArgDelegate* p(new CAmSyncFourArgDelegate(instance, function, argument, argument1, argument2, argument3)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads=read(mReturnPipe[0],&ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal=p->returnResults(argument, argument1, argument2, argument3); - delete p; - } - - - void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) - { - (void) handle; - (void) userData; - int numReads; - CAmDelegagePtr listPointers[3]; - if ((numReads=read(pollfd.fd,&listPointers, sizeof(listPointers))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - mListDelegatePoiters.assign(listPointers, listPointers+(numReads/sizeof(CAmDelegagePtr))); - } - - bool checkerCallback(const sh_pollHandle_t handle, void* userData) - { - (void) handle; - (void) userData; - if (mListDelegatePoiters.empty()) - return false; - return true; - } - - bool dispatcherCallback(const sh_pollHandle_t handle, void* userData) - { - (void) handle; - (void) userData; - CAmDelegagePtr delegatePoiter = mListDelegatePoiters.front(); - mListDelegatePoiters.pop_front(); - if(delegatePoiter->call(mReturnPipe)) - delete delegatePoiter; - if (mListDelegatePoiters.empty()) - return false; - return true; - } - - shPollFired_T receiverCallbackT; - shPollDispatch_T dispatcherCallbackT; - shPollCheck_T checkerCallbackT; - - /** - * The constructor must be called in the mainthread context ! - * @param iSocketHandler pointer to the sockethandler - */ - CAmSerializer(SocketHandler *iSocketHandler) : - mPipe(), // - mListDelegatePoiters(), // - receiverCallbackT(this, &CAmSerializer::receiverCallback), // - dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback), // - checkerCallbackT(this, &CAmSerializer::checkerCallback) - { - if (pipe(mPipe) == -1) - { - logError("CAmSerializer could not create pipe!"); - throw std::runtime_error("CAmSerializer Could not open pipe!"); - } - - if (pipe(mReturnPipe) == -1) - { - logError("CAmSerializer could not create mReturnPipe!"); - throw std::runtime_error("CAmSerializer Could not open mReturnPipe!"); - } - - short event = 0; - sh_pollHandle_t handle; - event |= POLLIN; - iSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, NULL, &dispatcherCallbackT, NULL, handle); - } - - ~CAmSerializer(){} -}; -} /* namespace am */ -#endif /* CAMSERIALIZER_H_ */ diff --git a/includes/DLTWrapper.h b/includes/DLTWrapper.h deleted file mode 100644 index 3a9482a..0000000 --- a/includes/DLTWrapper.h +++ /dev/null @@ -1,521 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DLTWrapper.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef DLTWRAPPER_H_ -#define DLTWRAPPER_H_ - -#include "config.h" - -#ifdef WITH_DLT -#include -#else - -#include - -#define DLT_USER_BUF_MAX_SIZE 2048 - -/** - * This structure is used for every context used in an application. - */ -typedef struct -{ - char contextID[4]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ -} DltContext; - -/** - * Definitions of DLT log level - */ -typedef enum -{ - DLT_LOG_DEFAULT = -1, /**< Default log level */ - DLT_LOG_OFF = 0x00, /**< Log level off */ - DLT_LOG_FATAL = 0x01, /**< fatal system error */ - DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ - DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ - DLT_LOG_INFO = 0x04, /**< informational */ - DLT_LOG_DEBUG = 0x05, /**< debug */ - DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ -} DltLogLevelType; - -/** - * This structure is used for context data used in an application. - */ -typedef struct -{ - DltContext *handle; /**< pointer to DltContext */ - char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/ - int32_t size; /**< payload size */ - int32_t log_level; /**< log level */ - int32_t trace_status; /**< trace status */ - int32_t args_num; /**< number of arguments for extended header*/ - uint8_t mcnt; /**< message counter */ - char* context_description; /**< description of context */ -} DltContextData; - -#define DLT_DECLARE_CONTEXT(CONTEXT) \ -DltContext CONTEXT; - - -#define DLT_IMPORT_CONTEXT(CONTEXT) \ -extern DltContext CONTEXT; - -#endif - -#include - -class DLTWrapper -{ -public: - static DLTWrapper* instance(const bool enableNoDLTDebug = false); - void registerApp(const char *appid, const char * description); - void registerContext(DltContext& handle, const char *contextid, const char * description); - void unregisterContext(DltContext& handle); - void init(DltLogLevelType loglevel, DltContext* context = NULL); - void send(); - void append(const int8_t value); - void append(const uint8_t value); - void append(const int16_t value); - void append(const uint16_t value); - void append(const int32_t value); - void append(const uint32_t value); - void append(const char*& value); - void append(const std::string& value); - void append(const bool value); -#ifndef WITH_DLT - void enableNoDLTDebug(const bool enableNoDLTDebug = true); -#endif - ~DLTWrapper(); -private: - DLTWrapper(const bool enableNoDLTDebug); //is private because of singleton pattern -#ifndef WITH_DLT - template void appendNoDLT(T value); - bool mEnableNoDLTDebug; -#endif - DltContext mDltContext; - DltContextData mDltContextData; - static DLTWrapper* mDLTWrapper; - -}; - -inline DLTWrapper* getWrapper() -{ - return DLTWrapper::instance(); -} - -template void logInfo(T value) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->send(); -} - -template void logInfo(T value, T1 value1) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_INFO); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->send(); -} - -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->append(value10); - inst->send(); -} - -template void logError(T value) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->send(); -} - -template void logError(T value, T1 value1) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->send(); -} - -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) -{ - DLTWrapper* inst(getWrapper()); - inst->init(DLT_LOG_ERROR); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->append(value10); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); -} - -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - DLTWrapper* inst(getWrapper()); - inst->init(loglevel, context); - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); -} - -#endif /* DLTWRAPPER_H_ */ diff --git a/includes/SocketHandler.h b/includes/SocketHandler.h deleted file mode 100644 index 2a20af6..0000000 --- a/includes/SocketHandler.h +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file SocketHandler.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - */ - -#ifndef SOCKETHANDLER_H_ -#define SOCKETHANDLER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace am -{ - -static volatile sig_atomic_t gDispatchDone = 0; //this global is used to stop the mainloop - -typedef uint16_t sh_timerHandle_t; //! mPollfd_t; //! mListPoll_t; //! mListTimer; //! mListActiveTimer; //! class shTimerCallBack_T: public shTimerCallBack -{ -private: - TClass* mInstance; - void (TClass::*mFunction)(sh_timerHandle_t handle, void* userData); - -public: - shTimerCallBack_T(TClass* instance, void(TClass::*function)(sh_timerHandle_t handle, void* userData)) : - mInstance(instance),// - mFunction(function) {}; - - virtual void Call(sh_timerHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(handle, userData); - } -}; - -/** - * template to create the functor for a class - */ -template class shPollPrepare_T: public shPollPrepare -{ -private: - TClass* mInstance; - void (TClass::*mFunction)(const sh_timerHandle_t handle, void* userData); - -public: - shPollPrepare_T(TClass* instance, void(TClass::*function)(const sh_timerHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function){}; - - virtual void Call(const sh_timerHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(handle, userData); - }; -}; - -template class shPollFired_T: public shPollFired -{ -private: - TClass* mInstance; - void (TClass::*mFunction)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - -public: - shPollFired_T(TClass* instance, void(TClass::*function)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function){}; - - virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(pollfd, handle, userData); - }; -}; - -template class shPollCheck_T: public shPollCheck -{ -private: - TClass* mInstance; - bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData); - -public: - shPollCheck_T(TClass* instance, bool(TClass::*function)(const sh_pollHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function){}; - - virtual bool Call(const sh_pollHandle_t handle, void* userData) - { - return (*mInstance.*mFunction)(handle, userData); - }; -}; - -template class shPollDispatch_T: public shPollDispatch -{ -private: - TClass* mInstance; - bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData); - -public: - shPollDispatch_T(TClass* instance, bool(TClass::*function)(const sh_pollHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function) {}; - - virtual bool Call(const sh_pollHandle_t handle, void* userData) - { - return (*mInstance.*mFunction)(handle, userData); - }; -}; -} /* namespace am */ -#endif /* SOCKETHANDLER_H_ */ diff --git a/includes/audiomanagertypes.h b/includes/audiomanagertypes.h deleted file mode 100644 index a489720..0000000 --- a/includes/audiomanagertypes.h +++ /dev/null @@ -1,819 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_20D4CA94_946F_4462_BD28_0ABEC8125573__INCLUDED_) -#define EA_20D4CA94_946F_4462_BD28_0ABEC8125573__INCLUDED_ - -#include -#include "projecttypes.h" -#include -#include - -#define AM_MUTE -3000 - -namespace am { - /** - * a domain ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_domainID_t; - - /** - * a source ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_sourceID_t; - - /** - * a sink ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_sinkID_t; - - /** - * a gateway ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_gatewayID_t; - - /** - * a crossfader ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_crossfaderID_t; - - /** - * a connection ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_connectionID_t; - - /** - * a mainConnection ID - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_mainConnectionID_t; - - /** - * speed - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_speed_t; - - /** - * The unit is 0.1 db steps,The smallest value -3000 (=AM_MUTE). The minimum and maximum can be limited by actual project. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef int16_t am_volume_t; - - /** - * This is the volume presented on the command interface. It is in the duty of the Controller to change the volumes given here into meaningful values on the routing interface. - * The range of this type is customer specific. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef int16_t am_mainVolume_t; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_sourceClass_t; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_sinkClass_t; - - /** - * time in ms! - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef uint16_t am_time_t; - - /** - * offset time that is introduced in milli seconds. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - typedef int16_t am_timeSync_t; - - /** - * with the help of this enum, sinks and sources can report their availability state - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_Availablility_e - { - /** - * default - */ - A_UNKNOWN = 0, - /** - * The source / sink is available - */ - A_AVAILABLE = 1, - /** - * the source / sink is not available - */ - A_UNAVAILABLE = 2, - A_MAX - }; - - /** - * represents the connection state - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_ConnectionState_e - { - CS_UNKNOWN = 0, - /** - * This means the connection is just building up - */ - CS_CONNECTING = 1, - /** - * the connection is ready to be used - */ - CS_CONNECTED = 2, - /** - * the connection is in the course to be knocked down - */ - CS_DISCONNECTING = 3, - /** - * only relevant for connectionStatechanged. Is send after the connection was removed - */ - CS_DISCONNECTED = 4, - /** - * this means the connection is still build up but unused at the moment - */ - CS_SUSPENDED = 5, - CS_MAX - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_DomainState_e - { - /** - * default - */ - DS_UNKNOWN = 0, - /** - * the domain is controlled by the daemon - */ - DS_CONTROLLED = 1, - /** - * the domain is independent starting up - */ - DS_INDEPENDENT_STARTUP = 1, - /** - * the domain is independent running down - */ - DS_INDEPENDENT_RUNDOWN = 2, - DS_MAX - }; - - /** - * This enum characterizes the data of the EarlyData_t - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_EarlyDataType_e - { - /** - * default - */ - ES_UNKNOWN = 0, - /** - * the source volume - */ - ED_SOURCE_VOLUME = 1, - /** - * the sink volume - */ - ED_SINK_VOLUME = 2, - /** - * a source property - */ - ED_SOURCE_PROPERTY = 3, - /** - * a sink property - */ - ED_SINK_PROPERTY = 4, - ED_MAX - }; - - /** - * the errors of the audiomanager. All possible errors are in here. This enum is used widely as return parameter. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_Error_e - { - /** - * default - */ - E_UNKNOWN = 0, - /** - * no error - positive reply - */ - E_OK = 1, - /** - * value out of range - */ - E_OUT_OF_RANGE = 2, - /** - * not used - */ - E_NOT_USED = 3, - /** - * a database error occurred - */ - E_DATABASE_ERROR = 4, - /** - * the desired object already exists - */ - E_ALREADY_EXISTS = 5, - /** - * there is no change - */ - E_NO_CHANGE = 6, - /** - * the desired action is not possible - */ - E_NOT_POSSIBLE = 7, - /** - * the desired object is non existent - */ - E_NON_EXISTENT = 8, - /** - * the asynchronous action was aborted - */ - E_ABORTED = 9, - /** - * This error is returned in case a connect is issued with a connectionFormat that cannot be selected for the connection. This could be either due to the capabilities of a source or a sink or gateway compatibilities for example - */ - E_WRONG_FORMAT = 10, - E_MAX - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_MuteState_e - { - /** - * default - */ - MS_UNKNOWN = 0, - /** - * the source / sink is muted - */ - MS_MUTED = 1, - /** - * the source / sink is unmuted - */ - MS_UNMUTED = 2, - MS_MAX - }; - - /** - * The source state reflects the state of the source - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_SourceState_e - { - SS_UNKNNOWN = 0, - /** - * The source can be activly heared - */ - SS_ON = 1, - /** - * The source cannot be heared - */ - SS_OFF = 2, - /** - * The source is paused. Meaning it cannot be heared but should be prepared to play again soon. - */ - SS_PAUSED = 3, - SS_MAX - }; - - /** - * This enumeration is used to define the type of the action that is correlated to a handle. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_Handle_e - { - H_UNKNOWN = 0, - H_CONNECT = 1, - H_DISCONNECT = 2, - H_SETSOURCESTATE = 3, - H_SETSINKVOLUME = 4, - H_SETSOURCEVOLUME = 5, - H_SETSINKSOUNDPROPERTY = 6, - H_SETSOURCESOUNDPROPERTY = 7, - H_SETSINKSOUNDPROPERTIES = 8, - H_SETSOURCESOUNDPROPERTIES = 9, - H_CROSSFADE = 10, - H_MAX - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_InterruptState_e - { - /** - * default - */ - IS_UNKNOWN = 0, - /** - * the interrupt state is off - no interrupt - */ - IS_OFF = 1, - /** - * the interrupt state is interrupted - the interrupt is active - */ - IS_INTERRUPTED = 2, - IS_MAX - }; - - /** - * describes the active sink of a crossfader. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - enum am_HotSink_e - { - /** - * default - */ - HS_UNKNOWN = 0, - /** - * sinkA is active - */ - HS_SINKA = 1, - /** - * sinkB is active - */ - HS_SINKB = 2, - /** - * the crossfader is in the transition state - */ - HS_INTERMEDIATE = 3, - HS_MAX - }; - - /** - * this describes the availability of a sink or a source together with the latest change - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - struct am_Availability_s - { - - public: - /** - * the current availability state - */ - am_Availablility_e availability; - /** - * the reason for the last change. This can be used to trigger events that deal with state changes. - */ - am_AvailabilityReason_e availabilityReason; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:25 PM - */ - struct am_ClassProperty_s - { - - public: - am_ClassProperty_e classProperty; - int16_t value; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_Crossfader_s - { - - public: - am_crossfaderID_t crossfaderID; - std::string name; - am_sinkID_t sinkID_A; - am_sinkID_t sinkID_B; - am_sourceID_t sourceID; - am_HotSink_e hotSink; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_Gateway_s - { - - public: - am_gatewayID_t gatewayID; - std::string name; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - am_domainID_t domainSinkID; - am_domainID_t domainSourceID; - am_domainID_t controlDomainID; - std::vector listSourceFormats; - std::vector listSinkFormats; - /** - * This is matrix holding information about the conversion capability of the gateway, it's length is defined by the length(listSinkFormats) x length(listSourceFormats). - * If a SinkFormat can be converted into a SourceFormat, the vector will hold a 1, if no conversion is possible, a 0. - * The data is stored row orientated, where the rows are related to the sinksFormats and the columns to the sourceFormats. The first value will hold the conversion information from the first sourceFormat to the first sinkFormat for example and the seventh value the information about the 3rd sinkFormat to the 1st sourceFormat in case we would have 3 sourceFormats. - * - * This matrix - * 110 011 000 111 001 - * - * reads as this: - * Source - * ** 1 2 3 - * ********************* - * S 1* 1 1 0 - * i 2* 0 1 1 - * n 3* 0 0 0 - * k 4* 1 1 1 - * 5* 0 0 1 - */ - std::vector convertionMatrix; - - }; - - /** - * This represents one "hopp" in a route - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_RoutingElement_s - { - - public: - am_sourceID_t sourceID; - am_sinkID_t sinkID; - am_domainID_t domainID; - am_ConnectionFormat_e connectionFormat; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_Route_s - { - - public: - am_sourceID_t sourceID; - am_sinkID_t sinkID; - std::vector route; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_SoundProperty_s - { - - public: - am_SoundPropertyType_e type; - int16_t value; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_SystemProperty_s - { - - public: - /** - * the type that is set - */ - am_SystemPropertyType_e type; - /** - * the value - */ - int16_t value; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:26 PM - */ - struct am_SinkClass_s - { - - public: - am_sinkClass_t sinkClassID; - std::string name; - std::vector listClassProperties; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_SourceClass_s - { - - public: - /** - * the source ID - */ - am_sourceClass_t sourceClassID; - std::string name; - std::vector listClassProperties; - - }; - - /** - * this type holds all information of sources relevant to the HMI - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_SourceType_s - { - - public: - am_sourceID_t sourceID; - std::string name; - am_Availability_s availability; - am_sourceClass_t sourceClassID; - - }; - - /** - * this type holds all information of sinks relevant to the HMI - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_SinkType_s - { - - public: - am_sinkID_t sinkID; - std::string name; - am_Availability_s availability; - am_mainVolume_t volume; - am_MuteState_e muteState; - am_sinkClass_t sinkClassID; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_Handle_s - { - - public: - am_Handle_e handleType:4; - uint16_t handle:12; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_MainSoundProperty_s - { - - public: - am_MainSoundPropertyType_e type; - int16_t value; - - }; - - /** - * this type holds all information of connections relevant to the HMI - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_MainConnectionType_s - { - - public: - am_mainConnectionID_t mainConnectionID; - am_sourceID_t sourceID; - am_sinkID_t sinkID; - am_timeSync_t delay; - am_ConnectionState_e connectionState; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_MainConnection_s - { - - public: - am_mainConnectionID_t mainConnectionID; - am_ConnectionState_e connectionState; - /** - * the sinkID - */ - am_sinkID_t sinkID; - /** - * the sourceID - */ - am_sourceID_t sourceID; - am_timeSync_t delay; - std::vector listConnectionID; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:27 PM - */ - struct am_Sink_s - { - - public: - am_sinkID_t sinkID; - std::string name; - am_domainID_t domainID; - am_sinkClass_t sinkClassID; - am_volume_t volume; - bool visible; - am_Availability_s available; - am_MuteState_e muteState; - am_mainVolume_t mainVolume; - std::vector listSoundProperties; - std::vector listConnectionFormats; - std::vector listMainSoundProperties; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - struct am_Source_s - { - - public: - am_sourceID_t sourceID; - am_domainID_t domainID; - std::string name; - am_sourceClass_t sourceClassID; - am_SourceState_e sourceState; - am_volume_t volume; - bool visible; - am_Availability_s available; - am_InterruptState_e interruptState; - /** - * This list holds all soundProperties of the source - */ - std::vector listSoundProperties; - /** - * list of the supported ConnectionFormats - */ - std::vector listConnectionFormats; - /** - * This list holds all MainSoundProperties of the source (all the ones that can be set via the HMI) - */ - std::vector listMainSoundProperties; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - struct am_Domain_s - { - - public: - am_domainID_t domainID; - std::string name; - std::string busname; - std::string nodename; - bool early; - bool complete; - am_DomainState_e state; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - struct am_Connection_s - { - - public: - am_connectionID_t connectionID; - am_sourceID_t sourceID; - am_sinkID_t sinkID; - am_timeSync_t delay; - am_ConnectionFormat_e connectionFormat; - - }; - - /** - * data type depends of am_EarlyDataType_e: - * volume_t in case of ED_SOURCE_VOLUME, ED_SINK_VOLUME - * soundProperty_t in case of ED_SOURCE_PROPERTY, ED_SINK_PROPERTY - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - union am_EarlyData_u - { - - public: - am_volume_t volume; - am_SoundProperty_s soundProperty; - - }; - - /** - * data type depends of am_EarlyDataType_e: - * sourceID in case of ED_SOURCE_VOLUME, ED_SOURCE_PROPERTY - * sinkID in case of ED_SINK_VOLUME, ED_SINK_PROPERTY - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - union am_DataType_u - { - - public: - am_sinkID_t sink; - am_sourceID_t source; - - }; - - /** - * @author Christian Mueller - * @created 29-Feb-2012 12:54:28 PM - */ - struct am_EarlyData_s - { - - public: - am_EarlyDataType_e type; - am_DataType_u sinksource; - am_EarlyData_u data; - - }; -} -#endif // !defined(EA_20D4CA94_946F_4462_BD28_0ABEC8125573__INCLUDED_) diff --git a/includes/command/CommandReceiveInterface.h b/includes/command/CommandReceiveInterface.h deleted file mode 100644 index 4190fa8..0000000 --- a/includes/command/CommandReceiveInterface.h +++ /dev/null @@ -1,220 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_76AA566B_CDC8_4c91_A89E_BB68E32CC6D1__INCLUDED_) -#define EA_76AA566B_CDC8_4c91_A89E_BB68E32CC6D1__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" -namespace am { -class DBusWrapper; -class SocketHandler; -} - - -#define CommandReceiveVersion "1.0" -namespace am { - /** - * The interface towards the Controlling Instance (e.g HMI). It handles the communication towards the HMI and other system components who need to interact with the audiomanagement. - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - class CommandReceiveInterface - { - - public: - CommandReceiveInterface() { - - } - - virtual ~CommandReceiveInterface() { - - } - - /** - * connects a source to sink - * @return E_OK on success, E_NOT_POSSIBLE on failure, E_ALREADY_EXISTS if the connection does already exists - * - * @param sourceID - * @param sinkID - * @param mainConnectionID - */ - virtual am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) =0; - /** - * disconnects a mainConnection - * @return E_OK on successes, E_NON_EXISTENT if the connection does not exist, E_NOT_POSSIBLE on error. - * - * @param mainConnectionID - */ - virtual am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID) =0; - /** - * sets the volume for a sink - * @return E_OK on success, E_UNKOWN on error, E_OUT_OF_RANGE in case the value is out of range - * - * @param sinkID the sink - * @param volume the volume - */ - virtual am_Error_e setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume) =0; - /** - * This function is used to increment or decrement the current volume for a sink. - * @return E_OK on success, E_UNKNOWN on error and E_OUT_OF_RANGE if the value is not in the given volume range. - * - * @param sinkID - * @param volumeStep indicated the number of steps that should be incremented or decremented. Positive values here inkrement, negative values decrement - */ - virtual am_Error_e volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep) =0; - /** - * sets the mute state of a sink - * @return E_OK on success, E_UNKNOWN on error. If the mute state is already the desired one, the Daemon will return E_OK. - * - * @param sinkID - * @param muteState - */ - virtual am_Error_e setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; - /** - * This method is used to set sound properties, e.g. Equalizer Values. Since the capabilities of the system can differ, the exact key value pairs can be extended in each product - * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error - * - * @param soundProperty - * @param sinkID - */ - virtual am_Error_e setMainSinkSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) =0; - /** - * This method is used to set sound properties, e.g. Equalizer Values. Since the capabilities of the system can differ, the exact key value pairs can be extended in each product - * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error - * - * @param soundProperty - * @param sourceID - */ - virtual am_Error_e setMainSourceSoundProperty(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) =0; - /** - * is used to set a specific system property. - * @return E_OK on success, E_OUT_OF_RANGE if value exceeds range, E_UNKNOWN in case of an error - * - * @param property the property that shall be set - */ - virtual am_Error_e setSystemProperty(const am_SystemProperty_s& property) =0; - /** - * returns the actual list of MainConnections - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listConnections returns a list of all connections - */ - virtual am_Error_e getListMainConnections(std::vector& listConnections) const =0; - /** - * returns the actual list of Sinks - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listMainSinks the list of the sinks - */ - virtual am_Error_e getListMainSinks(std::vector& listMainSinks) const =0; - /** - * returns the actual list of Sources - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listMainSources the list of sources - */ - virtual am_Error_e getListMainSources(std::vector& listMainSources) const =0; - /** - * This is used to retrieve all source sound properties related to a source. Returns a vector of the sound properties and values as pair - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param sinkID - * @param listSoundProperties - */ - virtual am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const =0; - /** - * This is used to retrieve all source sound properties related to a source. - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param sourceID - * @param listSourceProperties - */ - virtual am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const =0; - /** - * This is used to retrieve SourceClass Information of all source classes - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSourceClasses - */ - virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const =0; - /** - * This is used to retrieve SinkClass Information of all sink classes - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSinkClasses - */ - virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const =0; - /** - * Retrieves a complete list of all systemProperties. - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSystemProperties - */ - virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const =0; - /** - * returns the delay in ms that the audiopath for the given mainConnection has - * @return E_OK on success, E_NOT_POSSIBLE if timing information is not yet retrieved, E_DATABASE_ERROR on read error on the database - * - * @param mainConnectionID - * @param delay - */ - virtual am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const =0; - /** - * this function is used to retrieve a pointer to the dBusConnectionWrapper - * @return E_OK if pointer is valid, E_UKNOWN if AudioManager was compiled without DBus Support - * - * @param dbusConnectionWrapper This is a wrapper class that is needed to keep dbus inclusions away from the interface. The DBusWrapperClass will return the pointer to the DbusConnection call (getDBusConnection) - */ - virtual am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const =0; - /** - * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. - * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, - * - * @param socketHandler - */ - virtual am_Error_e getSocketHandler(SocketHandler*& socketHandler) const =0; - /** - * This function returns the version of the interface. - * - * @param version - */ - virtual void getInterfaceVersion(std::string& version) const =0; - /** - * asynchronous confirmation of setCommandReady. - * - * @param handle the handle that was handed over by setCommandReady - */ - virtual void confirmCommandReady(const uint16_t handle) =0; - /** - * asynchronous confirmation of setCommandRundown - * - * @param handle the handle that was given via setCommandRundown - */ - virtual void confirmCommandRundown(const uint16_t handle) =0; - - }; -} -#endif // !defined(EA_76AA566B_CDC8_4c91_A89E_BB68E32CC6D1__INCLUDED_) diff --git a/includes/command/CommandSendInterface.h b/includes/command/CommandSendInterface.h deleted file mode 100644 index 70cf3cc..0000000 --- a/includes/command/CommandSendInterface.h +++ /dev/null @@ -1,194 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_AE49449C_9BE2_428f_82B5_7BD27DBBFCF2__INCLUDED_) -#define EA_AE49449C_9BE2_428f_82B5_7BD27DBBFCF2__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" - -namespace am { -class CommandReceiveInterface; -} - -#include "CommandReceiveInterface.h" - -#define CommandSendVersion "1.0" -namespace am { - /** - * This interface handles all communication from the AudioManagerDaemon towards the system. It is designed in such a way that only callbacks with no return types are implemented. So when the CommandInterfacePlugins are designed in such a way that they broadcast signals to any node who is interested in the particular information (like signals on Dbus for example), more information can be retrieved via the CommandReceiveInterface. - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - class CommandSendInterface - { - - public: - CommandSendInterface() { - - } - - virtual ~CommandSendInterface() { - - } - - /** - * This command starts the interface, the plugin itself. This is not meant to start communication with the HMI itself. It is a good idea to implement here everything that sets up the basic communication like DbusCommunication etc... - * Be aware of side effects with systemd and socketbased communication! - * @return E_OK on success, E_UNKNOWN on error - * - * @param commandreceiveinterface pointer to the receive interface. Is used to call the audiomanagerdaemon - */ - virtual am_Error_e startupInterface(CommandReceiveInterface* commandreceiveinterface) =0; - /** - * This function will indirectly be called by the Controller and is used to start the Communication. Before this command, all communication will be ignored by the AudioManager. - * After the Plugin is ready, it will asynchronously answer with condfirmCommandReady, the handle that is handed over must be returned. - * - * @param handle the handle uniquely idenfies the request - */ - virtual void setCommandReady(const uint16_t handle) =0; - /** - * This function will indirectly be called by the Controller and is used to stop the Communication. After this command, all communication will be ignored by the AudioManager. The plugin has to be prepared that either the power will be switched off or the Interface is started again with setCommandReady - * After the Plugin is ready to rundown, it will asynchronously answer with condfirmCommandRundown, the handle that is handed over must be returned. - * - * @param handle This handle uniquly idenfies the request - */ - virtual void setCommandRundown(const uint16_t handle) =0; - /** - * Callback that is called when the number of connections change - * - * @param mainConnection - */ - virtual void cbNewMainConnection(const am_MainConnectionType_s mainConnection) =0; - /** - * Callback that is called when the number of connections change - * - * @param mainConnection - */ - virtual void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) =0; - /** - * Callback that is called when the number of sinks change - * - * @param sink - */ - virtual void cbNewSink(const am_SinkType_s& sink) =0; - /** - * Callback that is called when the number of sinks change - * - * @param sinkID - */ - virtual void cbRemovedSink(const am_sinkID_t sinkID) =0; - /** - * Callback that is called when the number of sources change - * - * @param source - */ - virtual void cbNewSource(const am_SourceType_s& source) =0; - /** - * Callback that is called when the number of sources change - * - * @param source - */ - virtual void cbRemovedSource(const am_sourceID_t source) =0; - /** - * this callback is fired if the number of sink classes changed - */ - virtual void cbNumberOfSinkClassesChanged() =0; - /** - * this callback is fired if the number of source classes changed - */ - virtual void cbNumberOfSourceClassesChanged() =0; - /** - * This callback is called when the ConnectionState of a connection changed. - * - * @param connectionID - * @param connectionState - */ - virtual void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) =0; - /** - * this callback indicates that a sinkSoundProperty has changed. - * - * @param sinkID - * @param soundProperty - */ - virtual void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) =0; - /** - * this callback indicates that a sourceSoundProperty has changed. - * - * @param sourceID - * @param soundProperty - */ - virtual void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) =0; - /** - * this callback is called when the availability of a sink has changed - * - * @param sinkID - * @param availability - */ - virtual void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; - /** - * this callback is called when the availability of source has changed. - * - * @param sourceID - * @param availability - */ - virtual void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; - /** - * this callback indicates a volume change on the indicated sink - * - * @param sinkID - * @param volume - */ - virtual void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) =0; - /** - * this callback indicates a mute state change on a sink. - * - * @param sinkID - * @param muteState - */ - virtual void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; - /** - * is fired if a systemProperty changed - * - * @param systemProperty - */ - virtual void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty) =0; - /** - * This callback is fired if the timinginformation for a mainConnectionID changed - * - * @param mainConnectionID - * @param time - */ - virtual void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) =0; - /** - * returns the interface version as string. - * - * @param version - */ - virtual void getInterfaceVersion(std::string& version) const =0; - - }; -} -#endif // !defined(EA_AE49449C_9BE2_428f_82B5_7BD27DBBFCF2__INCLUDED_) diff --git a/includes/control/ControlReceiveInterface.h b/includes/control/ControlReceiveInterface.h deleted file mode 100644 index 94a0258..0000000 --- a/includes/control/ControlReceiveInterface.h +++ /dev/null @@ -1,614 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_CCBD8A91_5C9B_49d1_88D8_69215A0542F8__INCLUDED_) -#define EA_CCBD8A91_5C9B_49d1_88D8_69215A0542F8__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" -namespace am { -class SocketHandler; -} - - -#define ControlReceiveVersion "1.0" -namespace am { - /** - * This interface gives access to all important functions of the audiomanager that are used by the AudioManagerController to control the system. - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - class ControlReceiveInterface - { - - public: - ControlReceiveInterface() { - - } - - virtual ~ControlReceiveInterface() { - - } - - /** - * calculates a route from source to sink. - * @return E_OK on success, E_UNKNOWN on error - * - * @param onlyfree if true return only routes which use gateways that are not in use at the moment - * @param sourceID - * @param sinkID - * @param returnList this is a list of routes that are possible to take. unsorted! The longest could be first. - * In case not route can be found, the list will return empty. - */ - virtual am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList) =0; - /** - * With this function, elementary connects can be triggered by the controller. - * @return E_OK on success, E_UNKNOWN on error, E_WRONG_FORMAT of connectionFormats do not match, E_NO_CHANGE if the desired connection is already build up - * - * @param handle - * @param connectionID - * @param format - * @param sourceID - * @param sinkID - */ - virtual am_Error_e connect(am_Handle_s& handle, am_connectionID_t& connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID) =0; - /** - * is used to disconnect a connection - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if connection was not found, E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param connectionID - */ - virtual am_Error_e disconnect(am_Handle_s& handle, const am_connectionID_t connectionID) =0; - /** - * triggers a cross fade. - * @return E_OK on success, E_UNKNOWN on error E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param hotSource this is the source that is going to be the active one after the fading - * @param crossfaderID - * @param rampType - * @param rampTime rampTime 0 means default value - */ - virtual am_Error_e crossfade(am_Handle_s& handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime) =0; - /** - * with this method, all actions that have a handle assigned can be stopped. - * @return E_OK on success, E_UNKNOWN on error - * - * @param handle the handle of the action to be stopped - */ - virtual am_Error_e abortAction(const am_Handle_s handle) =0; - /** - * this method sets a source state for a source. This function will trigger the callback cbAckSetSourceState - * @return E_OK on success, E_NO_CHANGE if the desired value is already correct, E_UNKNOWN on error, E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param sourceID - * @param state - */ - virtual am_Error_e setSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state) =0; - /** - * with this function, setting of sinks volumes is done. The behavior of the volume set is depended on the given ramp and time information. - * This function is not only used to ramp volume, but also to mute and direct set the level. Exact behavior is depended on the selected mute ramps. - * @return E_OK on success, E_NO_CHANGE if the volume is already on the desired value, E_OUT_OF_RANGE is the volume is out of range, E_UNKNOWN on every other error. - * - * @param handle - * @param sinkID - * @param volume - * @param ramp - * @param time - */ - virtual am_Error_e setSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; - /** - * with this function, setting of source volumes is done. The behavior of the volume set is depended on the given ramp and time information. - * This function is not only used to ramp volume, but also to mute and direct set the level. Exact behavior is depended on the selected mute ramps. - * @return E_OK on success, E_NO_CHANGE if the volume is already on the desired value, E_OUT_OF_RANGE is the volume is out of range, E_UNKNOWN on every other error. - * - * @param handle - * @param sourceID - * @param volume - * @param rampType - * @param time - */ - virtual am_Error_e setSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time) =0; - /** - * is used to set several sinkSoundProperties at a time - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range, E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param sinkID - * @param soundProperty - */ - virtual am_Error_e setSinkSoundProperties(am_Handle_s& handle, const am_sinkID_t sinkID, const std::vector& soundProperty) =0; - /** - * is used to set sinkSoundProperties - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range, E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param sinkID - * @param soundProperty - */ - virtual am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) =0; - /** - * is used to set several SourceSoundProperties at a time - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range. E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param sourceID - * @param soundProperty - */ - virtual am_Error_e setSourceSoundProperties(am_Handle_s& handle, const am_sourceID_t sourceID, const std::vector& soundProperty) =0; - /** - * is used to set sourceSoundProperties - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if property is out of range. E_NO_CHANGE if no change is neccessary - * - * @param handle - * @param sourceID - * @param soundProperty - */ - virtual am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) =0; - /** - * sets the domain state of a domain - * @return E_OK on success, E_UNKNOWN on error, E_NO_CHANGE if no change is neccessary - * - * @param domainID - * @param domainState - */ - virtual am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) =0; - /** - * enters a domain in the database, creates and ID - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param domainData domainID in am_Domain_s must be 0 here - * @param domainID - */ - virtual am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID) =0; - /** - * enters a mainconnection in the database, creates and ID - * @return E_OK on success, E_DATABASE_ERROR if the database had an error - * - * @param mainConnectionData the MainConnectionID is omitted since it is created during the registration - * @param connectionID - */ - virtual am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID) =0; - /** - * enters a sink in the database. - * The sinkID in am_Sink_s shall be 0 in case of a dynamic added source A sinkID greater than 100 will be assigned. If a specific sinkID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param sinkData the sinkID will be omitted since it is created during the registration - * @param sinkID - */ - virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; - /** - * enters a crossfader in the database. - * The crossfaderID in am_Crossfader_s shall be 0 in case of a dynamic added source A crossfaderID greater than 100 will be assigned. If a specific crossfaderID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param crossfaderData the ID in the data will be ignored since it is created during the registration - * @param crossfaderID - */ - virtual am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; - /** - * enters a gateway in the database. - * The gatewayID in am_Gateway_s shall be 0 in case of a dynamic added source A gatewayID greater than 100 will be assigned. If a specific gatewayID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param gatewayData In a fixed setup, the gatewayID must be below 100. In a dynamic setup, the gatewayID shall be 0! listSourceFormats and listSinkFormats are empty at registration time. Values are taken over when sources and sinks are registered. - * @param gatewayID - */ - virtual am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; - /** - * enters a source in the database. - * The sourceID in am_Source_s shall be 0 in case of a dynamic added source A sourceID greater than 100 will be assigned. If a specific sourceID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param sourceData sourceID is omitted here since it is created during registration - * @param sourceID - */ - virtual am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; - /** - * Enters a sourceClass into the database. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param sinkClass IDs given with the SinkCLassID are valid below 100 (static). If given as 0, sinkClass will be enterd dynamic and ID above 100 will be created. - * @param sinkClassID - */ - virtual am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID) =0; - /** - * Enters a sourceClass into the database. - * The sourceClassID in am_sourceClass_s shall be 0 in case of a dynamic added source A sourceClassID greater than 100 will be assigned. If a specific sourceClassID with a value <100 is given, the given value will be used. This is for a static setup where the ID's are predefined. - * @return E_OK on success, E_ALREADY_EXISTENT if the ID or name is already in the database, E_DATABASE_ERROR if the database had an error - * - * @param sourceClassID - * @param sourceClass IDs given with the SourceCLassID are valid below 100 (static). If given as 0, sourceClass will be enterd dynamic and ID above 100 will be created. - */ - virtual am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass) =0; - /** - * changes class information of a sinkclass. - * The properties will overwrite the values of the sinkClassID given in the sinkClass. - * It is the duty of the controller to check if the property is valid. If it does not exist, the daemon will not return an error. - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sinkClassID was not found. - * - * @param sinkClass if a SourceClass ID other than 0 is given, the classInformation replaces the existing one. In case of ClassID 0, a new classID is created and returned - */ - virtual am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) =0; - /** - * changes class information of a sourceClass. - * The properties will overwrite the values of the sourceClassID given in the sourceClass. - * It is the duty of the controller to check if the property is valid. If it does not exist, the daemon will not return an error. - * @return E_OK on success, E_DATABASE_ERROR on error and E_NON_EXISTENT if the ClassID does not exist. - * - * @param sourceClass if a SourceClass ID other than 0 is given, the classInformation replaces the existing one. In case of ClassID 0, a new classID is created and returned - */ - virtual am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) =0; - /** - * This function is used to enter the system Properties into the database. - * All entries in the database will be erased before entering the new List. It should only be called once at system startup. - * @return E_OK on success, E_DATABASE_ERROR if the database had an error - * - * @param listSystemProperties - */ - virtual am_Error_e enterSystemPropertiesListDB(const std::vector& listSystemProperties) =0; - /** - * changes the mainConnectionState of MainConnection - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if mainconnection - * - * @param mainconnectionID - * @param listConnectionID - */ - virtual am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) =0; - /** - * changes the mainConnectionState of MainConnection - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if mainconnection - * - * @param mainconnectionID - * @param connectionState - */ - virtual am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) =0; - /** - * changes the sink volume of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param mainVolume - * @param sinkID - */ - virtual am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) =0; - /** - * changes the availablility of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param availability - * @param sinkID - */ - virtual am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID) =0; - /** - * changes the domainstate of a domain - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found - * - * @param domainState - * @param domainID - */ - virtual am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) =0; - /** - * changes the mute state of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param muteState - * @param sinkID - */ - virtual am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) =0; - /** - * changes the mainsinksoundproperty of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param soundProperty - * @param sinkID - */ - virtual am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) =0; - /** - * changes the mainsourcesoundproperty of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found - * - * @param soundProperty - * @param sourceID - */ - virtual am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) =0; - /** - * changes the availablility of a source - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found - * - * @param availability - * @param sourceID - */ - virtual am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID) =0; - /** - * changes a systemProperty - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if property was not found - * - * @param property - */ - virtual am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property) =0; - /** - * removes a mainconnection from the DB - * @return E_OK on success, E_NON_EXISTENT if main connection was not found, E_DATABASE_ERROR if the database had an error - * - * @param mainConnectionID - */ - virtual am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) =0; - /** - * removes a sink from the DB - * @return E_OK on success, E_NON_EXISTENT if sink was not found, E_DATABASE_ERROR if the database had an error - * - * @param sinkID - */ - virtual am_Error_e removeSinkDB(const am_sinkID_t sinkID) =0; - /** - * removes a source from the DB - * @return E_OK on success, E_NON_EXISTENT if source was not found, E_DATABASE_ERROR if the database had an error - * - * @param sourceID - */ - virtual am_Error_e removeSourceDB(const am_sourceID_t sourceID) =0; - /** - * removes a gateway from the DB - * @return E_OK on success, E_NON_EXISTENT if gateway was not found, E_DATABASE_ERROR if the database had an error - * - * @param gatewayID - */ - virtual am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID) =0; - /** - * removes a crossfader from the DB - * @return E_OK on success, E_NON_EXISTENT if crossfader was not found, E_DATABASE_ERROR if the database had an error - * - * @param crossfaderID - */ - virtual am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID) =0; - /** - * removes a domain from the DB - * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error - * - * @param domainID - */ - virtual am_Error_e removeDomainDB(const am_domainID_t domainID) =0; - /** - * removes a domain from the DB - * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error - * - * @param sinkClassID - */ - virtual am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID) =0; - /** - * removes a domain from the DB - * @return E_OK on success, E_NON_EXISTENT if domain was not found, E_DATABASE_ERROR if the database had an error - * - * @param sourceClassID - */ - virtual am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID) =0; - /** - * returns the ClassInformation of a source - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if source was not found - * - * @param sourceID - * @param classInfo - */ - virtual am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const =0; - /** - * returns the ClassInformation of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param sinkID - * @param sinkClass - */ - virtual am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const =0; - /** - * returns the sinkData of a sink - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param sinkID - * @param sinkData - */ - virtual am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const =0; - /** - * returns the sourcekData of a source - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if sink was not found - * - * @param sourceID - * @param sourceData - */ - virtual am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const =0; - /** - * return source and sink of a gateway - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if gateway was not found - * - * @param gatewayID - * @param gatewayData - */ - virtual am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const =0; - /** - * returns sources and the sink of a crossfader - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if crossfader was not found - * - * @param crossfaderID - * @param crossfaderData - */ - virtual am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const =0; - /** - * returns sources and the sink of a crossfader - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if crossfader was not found - * - * @param mainConnectionID - * @param mainConnectionData - */ - virtual am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const =0; - /** - * returns all sinks of a domain - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found - * - * @param domainID - * @param listSinkID - */ - virtual am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const =0; - /** - * returns all source of a domain - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found - * - * @param domainID - * @param listSourceID - */ - virtual am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const =0; - /** - * returns all crossfaders of a domain - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found - * - * @param domainID - * @param listCrossfadersID - */ - virtual am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listCrossfadersID) const =0; - /** - * returns all gateways of a domain - * @return E_OK on success, E_DATABASE_ERROR on error, E_NON_EXISTENT if domain was not found - * - * @param domainID - * @param listGatewaysID - */ - virtual am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const =0; - /** - * returns a complete list of all MainConnections - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listMainConnections - */ - virtual am_Error_e getListMainConnections(std::vector& listMainConnections) const =0; - /** - * returns a complete list of all domains - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listDomains - */ - virtual am_Error_e getListDomains(std::vector& listDomains) const =0; - /** - * returns a complete list of all Connections - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listConnections - */ - virtual am_Error_e getListConnections(std::vector& listConnections) const =0; - /** - * returns a list of all sinks - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSinks - */ - virtual am_Error_e getListSinks(std::vector& listSinks) const =0; - /** - * returns a list of all sources - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSources - */ - virtual am_Error_e getListSources(std::vector& listSources) const =0; - /** - * returns a list of all source classes - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSourceClasses - */ - virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const =0; - /** - * returns a list of all handles - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listHandles - */ - virtual am_Error_e getListHandles(std::vector& listHandles) const =0; - /** - * returns a list of all crossfaders - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listCrossfaders - */ - virtual am_Error_e getListCrossfaders(std::vector& listCrossfaders) const =0; - /** - * returns a list of gateways - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listGateways - */ - virtual am_Error_e getListGateways(std::vector& listGateways) const =0; - /** - * returns a list of all sink classes - * @return E_OK on success, E_DATABASE_ERROR on error - * - * @param listSinkClasses - */ - virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const =0; - /** - * returns the list of SystemProperties - * - * @param listSystemProperties - */ - virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const =0; - /** - * sets the command interface to ready. Will send setCommandReady to each of the plugins. The corresponding answer is confirmCommandReady. - */ - virtual void setCommandReady() =0; - /** - * sets the command interface into the rundown state. Will send setCommandRundown to each of the plugins. The corresponding answer is confirmCommandRundown. - */ - virtual void setCommandRundown() =0; - /** - * sets the routinginterface to ready. Will send the command setRoutingReady to each of the plugins. The related answer is confirmRoutingReady. - */ - virtual void setRoutingReady() =0; - /** - * sets the routinginterface to the rundown state. Will send the command setRoutingRundown to each of the plugins. The related answer is confirmRoutingRundown. - */ - virtual void setRoutingRundown() =0; - /** - * acknowledges the setControllerReady call. - */ - virtual void confirmControllerReady() =0; - /** - * acknowledges the setControllerRundown call. - */ - virtual void confirmControllerRundown() =0; - /** - * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. - * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, - * - * @param socketHandler - */ - virtual am_Error_e getSocketHandler(SocketHandler*& socketHandler) =0; - /** - * This function returns the version of the interface - * - * @param version - */ - virtual void getInterfaceVersion(std::string& version) const =0; - - }; -} -#endif // !defined(EA_CCBD8A91_5C9B_49d1_88D8_69215A0542F8__INCLUDED_) diff --git a/includes/control/ControlSendInterface.h b/includes/control/ControlSendInterface.h deleted file mode 100644 index 2d706a2..0000000 --- a/includes/control/ControlSendInterface.h +++ /dev/null @@ -1,388 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_3F77CFC8_1A30_4d2d_88FD_3E946AA5AB38__INCLUDED_) -#define EA_3F77CFC8_1A30_4d2d_88FD_3E946AA5AB38__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" - -namespace am { -class ControlReceiveInterface; -} - -#define ControlSendVersion "1.0" -namespace am { - /** - * This interface is presented by the AudioManager controller. - * All the hooks represent system events that need to be handled. The callback functions are used to handle for example answers to function calls on the AudioManagerCoreInterface. - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:30 PM - */ - class ControlSendInterface - { - - public: - ControlSendInterface() { - - } - - virtual ~ControlSendInterface() { - - } - - /** - * Starts up the controller. - * - * @param controlreceiveinterface This is a pointer to the ControlReceiveInterface so that the controller knows to whom to communicate. - */ - virtual am_Error_e startupController(ControlReceiveInterface* controlreceiveinterface) =0; - /** - * this message is used tell the controller that it should get ready. This message must be acknowledged via confirmControllerReady. - */ - virtual void setControllerReady() =0; - /** - * this message tells the controller that he should prepare everything for the power to be switched off. This message must be acknowledged via confirmControllerRundown. - */ - virtual void setControllerRundown() =0; - /** - * is called when a connection request comes in via the command interface - * @return E_OK on success, E_NOT_POSSIBLE on error, E_ALREADY_EXISTENT if already exists - * - * @param sourceID - * @param sinkID - * @param mainConnectionID - */ - virtual am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) =0; - /** - * is called when a disconnection request comes in via the command interface - * @return E_OK on success, E_NOT_POSSIBLE on error, E_NON_EXISTENT if connection does not exists - * - * @param connectionID - */ - virtual am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) =0; - /** - * sets a user MainSinkSoundProperty - * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error - * - * @param sinkID - * @param soundProperty - */ - virtual am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) =0; - /** - * sets a user MainSourceSoundProperty - * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error - * - * @param sourceID - * @param soundProperty - */ - virtual am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) =0; - /** - * sets a user SystemProperty - * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error - * - * @param property - */ - virtual am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property) =0; - /** - * sets a user volume - * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error - * - * @param SinkID - * @param newVolume - */ - virtual am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) =0; - /** - * sets a user volume as increment - * @return E_OK on success, E_OUT_OF_RANGE if out of range, E_UNKNOWN on error - * - * @param SinkID - * @param increment the steps - */ - virtual am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) =0; - /** - * sets the mute state of a sink - * @return E_OK on success, E_UNKNOWN on error - * - * @param sinkID - * @param muteState true=muted - */ - virtual am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) =0; - /** - * is called when a routing adaptor registers its domain - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists - * - * @param domainData ID is omitted here since it has not been created yet - * @param domainID - */ - virtual am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID) =0; - /** - * is called when a routing adaptor wants to derigister a domain - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found - * - * @param domainID - */ - virtual am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID) =0; - /** - * is called when a domain registered all the elements - * - * @param domainID - */ - virtual void hookSystemDomainRegistrationComplete(const am_domainID_t domainID) =0; - /** - * is called when a routing adaptor registers a sink - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists - * - * @param sinkData Id is omitted here, since it has not been created yet - * @param sinkID - */ - virtual am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; - /** - * is called when a routing adaptor deregisters a sink - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found - * - * @param sinkID - */ - virtual am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID) =0; - /** - * is called when a routing adaptor registers a source - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists - * - * @param sourceData ID is omitted here since it is not yet created - * @param sourceID - */ - virtual am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; - /** - * is called when a routing adaptor deregisters a source - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found - * - * @param sourceID - */ - virtual am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) =0; - /** - * is called when a routing adaptor registers a gateway - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists - * - * @param gatewayData gatewayID is not set here since it is not created at this point of time - * @param gatewayID - */ - virtual am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; - /** - * is called when a routing adaptor deregisters a gateway - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found - * - * @param gatewayID - */ - virtual am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) =0; - /** - * is called when a routing adaptor registers a crossfader - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXISTENT if already exists - * - * @param crossfaderData gatewayID is not set here since it is not created at this point of time - * @param crossfaderID - */ - virtual am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; - /** - * is called when a routing adaptor deregisters a crossfader - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if not found - * - * @param crossfaderID - */ - virtual am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) =0; - /** - * volumeticks. therse are used to indicate volumechanges during a ramp - * - * @param handle - * @param sinkID - * @param volume - */ - virtual void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) =0; - /** - * volumeticks. therse are used to indicate volumechanges during a ramp - * - * @param handle - * @param sourceID - * @param volume - */ - virtual void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) =0; - /** - * is called when an low level interrupt changed its state - * - * @param sourceID - * @param interruptState - */ - virtual void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) =0; - /** - * id called when a sink changed its availability - * - * @param sinkID - * @param availability - */ - virtual void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; - /** - * id called when a source changed its availability - * - * @param sourceID - * @param availability - */ - virtual void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; - /** - * id called when domainstate was changed - * - * @param domainID - * @param state - */ - virtual void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) =0; - /** - * when early data was received - * - * @param data - */ - virtual void hookSystemReceiveEarlyData(const std::vector& data) =0; - /** - * this hook provides information about speed changes. - * The quantization and sampling rate of the speed can be adjusted at compile time of the AudioManagerDaemon. - * - * @param speed - */ - virtual void hookSystemSpeedChange(const am_speed_t speed) =0; - /** - * this hook is fired whenever the timing information of a mainconnection has changed. - * - * @param mainConnectionID - * @param time - */ - virtual void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) =0; - /** - * ack for connect - * - * @param handle - * @param errorID - */ - virtual void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) =0; - /** - * ack for disconnect - * - * @param handle - * @param errorID - */ - virtual void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) =0; - /** - * ack for crossfading - * - * @param handle - * @param hostsink - * @param error - */ - virtual void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) =0; - /** - * ack for sink volume changes - * - * @param handle - * @param volume - * @param error - */ - virtual void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; - /** - * ack for source volume changes - * - * @param handle the handle that is connected to the volume change - * @param voulme the volume after the action ended (the desired volume if everything went right, the actual one in case of abortion) - * @param error - */ - virtual void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) =0; - /** - * ack for setting of source states - * - * @param handle - * @param error - */ - virtual void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) =0; - /** - * ack for setting of sourcesoundproperties - * - * @param handle - * @param error - */ - virtual void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; - /** - * ack for setting of sourcesoundproperties - * - * @param handle - * @param error - */ - virtual void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; - /** - * ack for setting of sinksoundproperties - * - * @param handle - * @param error - */ - virtual void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; - /** - * ack for setting of sinksoundproperties - * - * @param handle - * @param error - */ - virtual void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; - /** - * This function is used by the routing algorithm to retrieve a priorized list of connectionFormats from the Controller. - * @return E_OK in case of successfull priorisation. - * - * @param sourceID sourceID of source that shall be connected - * @param sinkID sinkID of sink that shall be connected - * @param listRoute This route is the one the priorized connectionFormats is for. - * @param listPossibleConnectionFormats list of possible connectionformats - * @param listPrioConnectionFormats the list return with prioos from the controller. Best choice on first position. - */ - virtual am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector listPossibleConnectionFormats, std::vector& listPrioConnectionFormats) =0; - /** - * This function returns the version of the interface - * returns E_OK, E_UNKOWN if version is unknown. - * - * @param version - */ - virtual void getInterfaceVersion(std::string& version) const =0; - /** - * confirms the setCommandReady call - */ - virtual void confirmCommandReady() =0; - /** - * confirms the setRoutingReady call - */ - virtual void confirmRoutingReady() =0; - /** - * confirms the setCommandRundown call - */ - virtual void confirmCommandRundown() =0; - /** - * confirms the setRoutingRundown command - */ - virtual void confirmRoutingRundown() =0; - - }; -} -#endif // !defined(EA_3F77CFC8_1A30_4d2d_88FD_3E946AA5AB38__INCLUDED_) diff --git a/includes/dbus/CommandInterface.xml b/includes/dbus/CommandInterface.xml deleted file mode 100644 index f6f07a0..0000000 --- a/includes/dbus/CommandInterface.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/includes/dbus/DBusWrapper.h b/includes/dbus/DBusWrapper.h deleted file mode 100644 index 76fd2c1..0000000 --- a/includes/dbus/DBusWrapper.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (C) 2011, BMW AG - * - * GeniviAudioMananger AudioManagerDaemon - * - * \file DBusWrapper.h - * - * \date 20-Oct-2011 3:42:04 PM - * \author Christian Mueller (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 Mueller 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 . - * 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. - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ - -#ifndef DBUSWRAPPER_H_ -#define DBUSWRAPPER_H_ - -#include -#include -#include -#include -#include - -namespace am -{ -/** - * This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins) - */ -class DBusWrapper -{ -public: - DBusWrapper(SocketHandler* socketHandler); - virtual ~DBusWrapper(); - - /** - * registers a callback that is entered as path below the main path. - * The configuration of the mainpath is done via DBusConfiguration.h - * @param vtable the vtable that holds a pointer to the callback that is called when the path is called from the dbus - * @param path the name of the path - * @param userdata pointer to the class that will handle the callback - */ - void registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata); - - /** - * returns the dbus connection - * @param connection pointer to the connection - */ - void getDBusConnection(DBusConnection*& connection) const; - - static dbus_bool_t addWatch(DBusWatch *watch, void *userData); - static void removeWatch(DBusWatch *watch, void *userData); - static void toogleWatch(DBusWatch *watch, void *userData); - - static dbus_bool_t addTimeout(DBusTimeout *timeout, void* userData); - static void removeTimeout(DBusTimeout *timeout, void* userData); - static void toggleTimeout(DBusTimeout *timeout, void* userData); - - bool dbusDispatchCallback(const sh_pollHandle_t handle, void* userData); - shPollDispatch_T pDbusDispatchCallback; - - void dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - shPollFired_T pDbusFireCallback; - - bool dbusCheckCallback(const sh_pollHandle_t handle, void* userData); - shPollCheck_T pDbusCheckCallback; - - void dbusTimerCallback(sh_timerHandle_t handle, void* userData); - shTimerCallBack_T pDbusTimerCallback; - -private: - static DBusWrapper* mReference; - static DBusHandlerResult cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference); - dbus_bool_t addWatchDelegate(DBusWatch * watch, void* userData); - void removeWatchDelegate(DBusWatch *watch, void *userData); - void toogleWatchDelegate(DBusWatch *watch, void *userData); - dbus_bool_t addTimeoutDelegate(DBusTimeout *timeout, void* userData); - void removeTimeoutDelegate(DBusTimeout *timeout, void* userData); - void toggleTimeoutDelegate(DBusTimeout *timeout, void* userData); - DBusObjectPathVTable mObjectPathVTable; - DBusConnection* mDbusConnection; - DBusError mDBusError; - std::list mNodesList; - std::vector mListTimerhandlePointer; - SocketHandler *mSocketHandler; - std::map mMapHandleWatch; -}; - -} - -#endif /* DBUSWRAPPER_H_ */ diff --git a/includes/projecttypes.h b/includes/projecttypes.h deleted file mode 100644 index a8f48a7..0000000 --- a/includes/projecttypes.h +++ /dev/null @@ -1,203 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_D85F87B8_62E9_4a72_9BF7_3DCA2B6559EA__INCLUDED_) -#define EA_D85F87B8_62E9_4a72_9BF7_3DCA2B6559EA__INCLUDED_ - -namespace am { - /** - * This enum classifies the format in which data is exchanged within a connection. The enum itself is project specific although there are some Genivi standard formats defined. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_ConnectionFormat_e - { - /** - * default - */ - CF_UNKNOWN = 0, - /** - * plain mono - */ - CF_GENIVI_MONO = 1, - /** - * stereo connection - */ - CF_GENIVI_STEREO = 2, - /** - * analog connection - */ - CF_GENIVI_ANALOG = 3, - /** - * automatic connection. - */ - CF_GENIVI_AUTO = 4, - CF_MAX - }; - - /** - * This enum gives the information about reason for reason for Source/Sink change - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_AvailabilityReason_e - { - /** - * default - */ - AR_UNKNOWN = 0, - /** - * the availability changed because an new media was entered - */ - AR_GENIVI_NEWMEDIA = 1, - /** - * the availability changed because the same media was entered - */ - AR_GENIVI_SAMEMEDIA = 2, - /** - * the availability changed because there is no media - */ - AR_GENIVI_NOMEDIA = 3, - /** - * the availability changed because of a temperature event - */ - AR_GENIVI_TEMPERATURE = 4, - /** - * the availability changed because of a voltage event - */ - AR_GENIVI_VOLTAGE = 5, - /** - * the availability changed because of fatal errors reading or accessing media - */ - AR_GENIVI_ERRORMEDIA = 6, - AR_MAX - }; - - /** - * product specific identifier of property - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_ClassProperty_e - { - /** - * default - */ - CP_UNKNOWN = 0, - /** - * defines the source type of a source. Project specific, could be for example differentiation between interrupt source and main source. - */ - CP_GENIVI_SOURCE_TYPE = 1, - /** - * defines the SINK_TYPE. Project specific - */ - CP_GENIVI_SINK_TYPE = 2, - CP_MAX - }; - - /** - * The given ramp types here are just a possiblity. for products, different ramp types can be defined here. - * It is in the responsibility of the product to make sure that the routing plugins are aware of the ramp types used. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_RampType_e - { - RAMP_UNKNOWN = 0, - /** - * this ramp type triggers a direct setting of the value without a ramp - */ - RAMP_GENIVI_DIRECT = 1, - /** - * This ramp type will set the volume as fast as possible. - */ - RAMP_GENIVI_NO_PLOB = 2, - RAMP_GENIVI_EXP_INV = 3, - RAMP_GENIVI_LINEAR = 4, - RAMP_GENIVI_EXP = 5, - RAMP_MAX - }; - - /** - * sound properties. Within genivi only the standard properties are defined, for products these need to be extended. - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_SoundPropertyType_e - { - /** - * default - */ - SP_UNKNOWN = 0, - /** - * example treble value min =-10 max =10 - */ - SP_EXAMPLE_TREBLE = 1, - /** - * example mid value min =-10 max =10 - */ - SP_EXAMPLE_MID = 2, - /** - * example bass value min =-10 max =10 - */ - SP_EXAMPLE_BASS = 3, - SP_MAX - }; - - /** - * Here are all SoundProperties that can be set via the CommandInterface. Product specific - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_MainSoundPropertyType_e - { - /** - * default - */ - MSP_UNKNOWN = 0, - /** - * example value between -10 and +10 - */ - MSP_EXAMPLE_TREBLE = 1, - /** - * example value between -10 and +10 - */ - MSP_EXAMPLE_MID = 2, - /** - * example value between -10 and +10 - */ - MSP_EXAMPLE_BASS = 3, - MSP_MAX - }; - - /** - * describes the different system properties. Project specific - * @author Christian Mueller - * @created 29-Feb-2012 12:54:29 PM - */ - enum am_SystemPropertyType_e - { - /** - * default - */ - SYP_UNKNOWN = 0, - SYP_MAX - }; -} -#endif // !defined(EA_D85F87B8_62E9_4a72_9BF7_3DCA2B6559EA__INCLUDED_) diff --git a/includes/routing/RoutingReceiveInterface.h b/includes/routing/RoutingReceiveInterface.h deleted file mode 100644 index f614fb3..0000000 --- a/includes/routing/RoutingReceiveInterface.h +++ /dev/null @@ -1,348 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_ACBA7B56_BAFE_481f_8DF3_0B1AB9AE1E8C__INCLUDED_) -#define EA_ACBA7B56_BAFE_481f_8DF3_0B1AB9AE1E8C__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" - -namespace am { -class DBusWrapper; -class SocketHandler; -} - - -#define RoutingReceiveVersion "1.0" -namespace am { - /** - * Routing Receive sendInterface description. This class implements everything from RoutingAdapter -> Audiomanager - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:30 PM - */ - class RoutingReceiveInterface - { - - public: - RoutingReceiveInterface() { - - } - - virtual ~RoutingReceiveInterface() { - - } - - /** - * acknowledges a asyncConnect - * - * @param handle - * @param connectionID - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) =0; - /** - * acknowledges a asyncDisconnect - * - * @param handle - * @param connectionID - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) =0; - /** - * acknowledges a asyncsetSinkVolume - * - * @param handle - * @param volume The current actual value that is set - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; - /** - * acknowledges a asyncsetSourceVolume - * - * @param handle handle that belongs to the change - * @param volume the current volume - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) =0; - /** - * acknowlegde for asyncSetSourceState - * - * @param handle - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSourceState(const am_Handle_s handle, const am_Error_e error) =0; - /** - * acknowledges asyncSetSinkSoundProperties - * - * @param handle - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; - /** - * acknowledges asyncSetSinkSoundProperty - * - * @param handle - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; - /** - * acknowledges asyncSetSourceSoundProperties - * - * @param handle - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) =0; - /** - * acknowledges asyncSetSourceSoundProperty - * - * @param handle - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) =0; - /** - * acknowledges asyncCrossFade - * - * @param handle - * @param hotSink this is the current hot sink, HS_INTERMEDIATE is here when a crossfading action did not reach the end - * @param error E_OK on success, E_ABORTED if action was aborted, E_UNKNOWN on error - */ - virtual void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) =0; - /** - * acknowledges a volume tick. This can be used to display volumechanges during ramps - * - * @param handle - * @param sourceID - * @param volume - */ - virtual void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) =0; - /** - * acknowledges a volume tick. This can be used to display volumechanges during ramps - * - * @param handle - * @param sinkID - * @param volume - */ - virtual void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) =0; - /** - * This function returns the ID to the given domainName. If already a domain is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the domain. The other parameters of the domain will be overwritten when the domain is registered. - * @return E_OK on success, E_UNKNOWN on error - * - * @param name - * @param domainID - */ - virtual am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID) =0; - /** - * registers a domain - * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error - * - * @param domainData domainID in am_Domain_s must be 0! - * @param domainID - */ - virtual am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID) =0; - /** - * deregisters a domain. All sources, sinks, gateways and crossfaders from that domain will be removed as well. - * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error - * - * @param domainID < the nonde of the bus - */ - virtual am_Error_e deregisterDomain(const am_domainID_t domainID) =0; - /** - * registers a gateway. @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error - * - * @param gatewayData In a fixed setup, the gatewayID must be below 100. In a dynamic setup, the gatewayID shall be 0. listSourceFormats and listSinkFormats are empty at registration time. Values are taken over when sources and sinks are registered. - * - * - * @param gatewayID - */ - virtual am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) =0; - /** - * deregisters a gateway. Also removes all sinks and sources of the controlling domain. - * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error - * - * @param gatewayID domainID of the control domain - */ - virtual am_Error_e deregisterGateway(const am_gatewayID_t gatewayID) =0; - /** - * This function returns the ID to the given sinkName. If already a sink is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the sink. The other parameters of the sink will be overwritten when the sink is registered. - * @return E_OK on success, E_UNKNOWN on error - * - * @param name ID is not valid since not created yet - * @param sinkID - */ - virtual am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID) =0; - /** - * Registers a sink. If the sink is part of a gateway, the listconnectionFormats is copied to the gatewayInformation - * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error - * - * @param sinkData In a fixed setup, the sinkID within am_Sink_s must be below 100. In a dynamic setup the sinkID must be 0 in am_Sink_s. - * @param sinkID - */ - virtual am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) =0; - /** - * deregisters a sink. - * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error - * - * @param sinkID - */ - virtual am_Error_e deregisterSink(const am_sinkID_t sinkID) =0; - /** - * This function returns the ID to the given sourceName. If already a source is registered with this name, it will return the corresponding ID, if not it will reserve an ID but not register the source. The other parameters of the source will be overwritten when the source is registered. - * @return E_OK on success, E_UNKNOWN on error - * - * @param name - * @param sourceID - */ - virtual am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID) =0; - /** - * registers a source. If the source is part of a gateway, the listconnectionFormats is copied to the gatewayInformation - * @return E_OK on success, E_UNKNOWN on error, E_ALREADY_EXIST if either name or sourceID already exists - * - * @param sourceData In a fixed setup, the sourceID within am_Source_s must be below 100. In a dynamic setup the sourceID must be 0 in am_Source_s - * @param sourceID - */ - virtual am_Error_e registerSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) =0; - /** - * deregisters a source - * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error - * - * @param sourceID - */ - virtual am_Error_e deregisterSource(const am_sourceID_t sourceID) =0; - /** - * this function registers a crossfader. - * @return E_OK on succes, E_ALREADY_EXISTENT if already registered E_UNKOWN on error - * - * @param crossfaderData in a fixed setup, the crossfaderID must be below 100. In a dynamic setup the crossfasderID shall be 0 - * @param crossfaderID - */ - virtual am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) =0; - /** - * this function deregisters a crossfader. removes all sources and sinks assiated as well. - * @return E_OK on succes, E_NON_EXISTENT if not found E_UNKOWN on error - * - * @param crossfaderID - */ - virtual am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID) =0; - /** - * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. - * @return E_OK on succes, E_DATABASE_ERROR on error - * - * @param name - * @param sourceClassID - */ - virtual am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) =0; - /** - * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. - * @return E_OK on succes, E_DATABASE_ERROR on error - * - * @param name - * @param sinkClassID - */ - virtual am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) =0; - /** - * is called when a low level interrupt changes it status. - * - * @param sourceID - * @param interruptState - */ - virtual void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) =0; - /** - * This hook is called when all elements from a domain are registered. - * Is used by the Controller to know when all expected domains are finally registered - * - * @param domainID - */ - virtual void hookDomainRegistrationComplete(const am_domainID_t domainID) =0; - /** - * is called when a sink changes its availability - * - * @param sinkID - * @param availability - */ - virtual void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability) =0; - /** - * is called when a source changes its availability - * - * @param sourceID - * @param availability - */ - virtual void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability) =0; - /** - * is called when a domain changes its status. This used for early domains only - * - * @param domainID - * @param domainState - */ - virtual void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) =0; - /** - * is called when the timinginformation (delay) changed for a connection. - * - * @param connectionID - * @param delay - */ - virtual void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) =0; - /** - * this function is used to send out all data that has been changed in an early state. - * @return E_OK on success, E_UNKNOWN on error - * - * @param earlyData - */ - virtual void sendChangedData(const std::vector& earlyData) =0; - /** - * this function is used to retrieve a pointer to the dBusConnectionWrapper - * @return E_OK if pointer is valid, E_UKNOWN if AudioManager was compiled without DBus Support - * - * @param dbusConnectionWrapper This is a wrapper class that is needed to keep dbus inclusions away from the interface. The DBusWrapperClass will return the pointer to the DbusConnection call (getDBusConnection) - */ - virtual am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const =0; - /** - * This function returns the pointer to the socketHandler. This can be used to integrate socket-based activites like communication with the mainloop of the AudioManager. - * returns E_OK if pointer is valid, E_UNKNOWN in case AudioManager was compiled without socketHandler support, - * - * @param socketHandler - */ - virtual am_Error_e getSocketHandler(SocketHandler*& socketHandler) const =0; - /** - * This function returns the version of the interface - * - * @param version retrieves the verison of the interface - */ - virtual void getInterfaceVersion(std::string& version) const =0; - /** - * confirms the setRoutingReady Command - * - * @param handle the handle that was given via setRoutingReady - */ - virtual void confirmRoutingReady(const uint16_t handle) =0; - /** - * confirms the setRoutingRundown Command - * - * @param handle handle that was given via setRoutingRundown - */ - virtual void confirmRoutingRundown(const uint16_t handle) =0; - - }; -} -#endif // !defined(EA_ACBA7B56_BAFE_481f_8DF3_0B1AB9AE1E8C__INCLUDED_) diff --git a/includes/routing/RoutingSendInterface.h b/includes/routing/RoutingSendInterface.h deleted file mode 100644 index e2bd5c4..0000000 --- a/includes/routing/RoutingSendInterface.h +++ /dev/null @@ -1,204 +0,0 @@ -/** Copyright (c) 2012 GENIVI Alliance - * Copyright (c) 2012 BMW - * - * @author Christian Mueller, BMW - * - * @copyright - * { - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * } - * - * - * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN - */ -#if !defined(EA_337B4D34_644D_4faf_8A72_3253A0B4F5A0__INCLUDED_) -#define EA_337B4D34_644D_4faf_8A72_3253A0B4F5A0__INCLUDED_ - -#include -#include -#include "audiomanagertypes.h" - -namespace am { -class RoutingReceiveInterface; -} - -#include "RoutingReceiveInterface.h" - -#define RoutingSendVersion "1.0" -namespace am { - /** - * This class implements everything from Audiomanager -> RoutingAdapter - * There are two rules that have to be kept in mind when implementing against this interface:\n - * 1. CALLS TO THIS INTERFACE ARE NOT THREAD SAFE !!!! \n - * 2. YOU MAY NOT THE CALLING INTERFACE DURING AN SYNCHRONOUS OR ASYNCHRONOUS CALL THAT EXPECTS A RETURN VALUE.\n - * Violation these rules may lead to unexpected behavior! Nevertheless you can implement thread safe by using the deferred-call pattern described on the wiki which also helps to implement calls that are forbidden.\n - * For more information, please check CAmSerializer - * @author Christian Mueller - * @created 29-Feb-2012 12:54:31 PM - */ - class RoutingSendInterface - { - - public: - RoutingSendInterface() { - - } - - virtual ~RoutingSendInterface() { - - } - - /** - * starts up the interface. In the implementations, here is the best place for init routines. - * - * @param routingreceiveinterface pointer to the receive interface - */ - virtual am_Error_e startupInterface(RoutingReceiveInterface* routingreceiveinterface) =0; - /** - * indicates that the routing now ready to be used. Should be used as trigger to register all sinks, sources, etc... - * - * @param handle handle that uniquely identifies the request - */ - virtual void setRoutingReady(const uint16_t handle) =0; - /** - * indicates that the routing plugins need to be prepared to switch the power off or be ready again. - * - * @param handle the handle that uniquely identifies the request - */ - virtual void setRoutingRundown(const uint16_t handle) =0; - /** - * aborts an asynchronous action. - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if handle was not found - * - * @param handle - */ - virtual am_Error_e asyncAbort(const am_Handle_s handle) =0; - /** - * connects a source to a sink - * @return E_OK on success, E_UNKNOWN on error, E_WRONG_FORMAT in case am_ConnectionFormat_e does not match - * - * @param handle - * @param connectionID - * @param sourceID - * @param sinkID - * @param connectionFormat - */ - virtual am_Error_e asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat) =0; - /** - * disconnect a connection with given connectionID - * @return E_OK on success, E_UNKNOWN on error, E_NON_EXISTENT if connection was not found - * - * @param handle - * @param connectionID - */ - virtual am_Error_e asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID) =0; - /** - * this method is used to set the volume of a sink. This function is used to drive ramps, to mute or unmute or directly set the value. The difference is made through the ramptype. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if new volume is out of range - * - * @param handle - * @param sinkID - * @param volume - * @param ramp - * @param time - */ - virtual am_Error_e asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; - /** - * sets the volume of a source. This method is used to set the volume of a sink. This function is used to drive ramps, to mute or unmute or directly set the value. The difference is made through the ramptype. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE if volume is out of range. - * triggers the acknowledge ackSourceVolumeChange - * - * @param handle - * @param sourceID - * @param volume - * @param ramp - * @param time - */ - virtual am_Error_e asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time) =0; - /** - * This function is used to set the source state of a particular source. - * @return E_OK on success, E_UNKNOWN on error - * - * @param handle - * @param sourceID - * @param state - */ - virtual am_Error_e asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state) =0; - /** - * this function sets the sinksoundproperty. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range - * - * @param handle - * @param sinkID - * @param listSoundProperties - */ - virtual am_Error_e asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector& listSoundProperties) =0; - /** - * this function sets the sinksoundproperty. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range - * - * @param handle - * @param sinkID - * @param soundProperty - */ - virtual am_Error_e asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty) =0; - /** - * this function sets the sourcesoundproperty. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range - * - * @param handle - * @param sourceID - * @param listSoundProperties - */ - virtual am_Error_e asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector& listSoundProperties) =0; - /** - * this function sets the sourcesoundproperty. - * @return E_OK on success, E_UNKNOWN on error, E_OUT_OF_RANGE in case the propery value is out of range - * - * @param handle - * @param sourceID - * @param soundProperty - */ - virtual am_Error_e asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty) =0; - /** - * this function triggers crossfading. - * @return E_OK on success, E_UNKNOWN on error - * - * @param handle - * @param crossfaderID - * @param hotSink - * @param rampType - * @param time - */ - virtual am_Error_e asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time) =0; - /** - * this function is used for early and late audio functions to set the domain state - * @return E_OK on success, E_UNKNOWN on error - * - * @param domainID - * @param domainState - */ - virtual am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState) =0; - /** - * this method is used to retrieve the busname during startup of the plugin. Needs to be implemented - * @return E_OK on success, E_UNKNOWN on error - * - * @param BusName - */ - virtual am_Error_e returnBusName(std::string& BusName) const =0; - /** - * This function returns the version of the interface - * - * @param version - */ - virtual void getInterfaceVersion(std::string& version) const =0; - - }; -} -#endif // !defined(EA_337B4D34_644D_4faf_8A72_3253A0B4F5A0__INCLUDED_) -- cgit v1.2.1