From 5bcd206b9270d9a79e212f91723ea1a08a4d4859 Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Thu, 11 Feb 2016 07:28:47 +0100 Subject: * rework of the build structure, adopt to standard cmake package structure * check versions when loading the libs * introduction of the AudioManagerCore * give control plugin as file or directory * remove SQLITE * either find and use gmock or build and install it * fixed [Bug 411] * compile flag gnu11 is now used Signed-off-by: Christian Linke Signed-off-by: Christian Linke --- AudioManagerCore/CMakeLists.txt | 109 + AudioManagerCore/include/CAmCommandReceiver.h | 97 + AudioManagerCore/include/CAmCommandSender.h | 91 + AudioManagerCore/include/CAmControlReceiver.h | 156 + AudioManagerCore/include/CAmControlSender.h | 154 + AudioManagerCore/include/CAmDatabaseHandlerMap.h | 495 ++ AudioManagerCore/include/CAmDatabaseObserver.h | 87 + AudioManagerCore/include/CAmGraph.h | 630 +++ AudioManagerCore/include/CAmLog.h | 129 + AudioManagerCore/include/CAmRouter.h | 317 ++ AudioManagerCore/include/CAmRoutingReceiver.h | 127 + AudioManagerCore/include/CAmRoutingSender.h | 155 + AudioManagerCore/include/CAmTelnetMenuHelper.h | 204 + AudioManagerCore/include/CAmTelnetServer.h | 100 + AudioManagerCore/include/IAmDatabaseHandler.h | 200 + AudioManagerCore/include/TAmPluginTemplate.h | 91 + AudioManagerCore/src/CAmCommandReceiver.cpp | 264 + AudioManagerCore/src/CAmCommandSender.cpp | 367 ++ AudioManagerCore/src/CAmControlReceiver.cpp | 606 +++ AudioManagerCore/src/CAmControlSender.cpp | 571 ++ AudioManagerCore/src/CAmDatabaseHandlerMap.cpp | 3079 +++++++++++ AudioManagerCore/src/CAmDatabaseObserver.cpp | 242 + AudioManagerCore/src/CAmLog.cpp | 101 + AudioManagerCore/src/CAmRouter.cpp | 884 +++ AudioManagerCore/src/CAmRoutingReceiver.cpp | 620 +++ AudioManagerCore/src/CAmRoutingSender.cpp | 838 +++ AudioManagerCore/src/CAmTelnetMenuHelper.cpp | 1438 +++++ AudioManagerCore/src/CAmTelnetServer.cpp | 257 + .../CAmControlInterfaceTest.cpp | 673 +++ .../CAmControlInterfaceTest.h | 76 + .../test/AmControlInterfaceTest/CMakeLists.txt | 52 + .../test/AmControlInterfaceTest/CMakeLists.txt~ | 50 + .../test/AmMapHandlerTest/CAmMapHandlerTest.cpp | 3276 ++++++++++++ .../test/AmMapHandlerTest/CAmMapHandlerTest.h | 92 + .../AmMapHandlerTest/CAmTestDatabaseObserver.cpp | 98 + .../test/AmMapHandlerTest/CMakeLists.txt | 49 + .../test/AmMapHandlerTest/CMakeLists.txt~ | 54 + .../test/AmMapHandlerTest/MockDatabaseObserver.h | 120 + .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 3183 +++++++++++ .../test/AmRouterMapTest/CAmRouterMapTest.h | 108 + .../test/AmRouterMapTest/CMakeLists.txt | 47 + .../test/AmRouterMapTest/CMakeLists.txt~ | 47 + .../test/AmRouterTest/CAmRouterTest.cpp | 1967 +++++++ AudioManagerCore/test/AmRouterTest/CAmRouterTest.h | 81 + AudioManagerCore/test/AmRouterTest/CMakeLists.txt | 48 + AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ | 47 + .../CAmRoutingInterfaceTest.cpp | 383 ++ .../CAmRoutingInterfaceTest.h | 71 + .../test/AmRoutingInterfaceTest/CMakeLists.txt | 49 + .../test/AmRoutingInterfaceTest/CMakeLists.txt~ | 48 + .../AmTelnetServerTest/CAmTelnetServerTest.cpp | 209 + .../test/AmTelnetServerTest/CAmTelnetServerTest.h | 107 + .../test/AmTelnetServerTest/CMakeLists.txt | 48 + .../test/AmTelnetServerTest/CMakeLists.txt~ | 46 + AudioManagerCore/test/CAmCommonFunctions.cpp | 383 ++ AudioManagerCore/test/CAmCommonFunctions.h | 96 + AudioManagerCore/test/CMakeLists.txt | 35 + AudioManagerCore/test/IAmCommandBackdoor.h | 47 + AudioManagerCore/test/IAmControlBackdoor.h | 44 + AudioManagerCore/test/IAmRoutingBackdoor.h | 46 + AudioManagerCore/test/MockIAmCommandSend.h | 94 + AudioManagerCore/test/MockIAmControlSend.h | 160 + AudioManagerCore/test/MockIAmRoutingSend.h | 83 + AudioManagerDaemon/CMakeLists.txt | 112 +- AudioManagerDaemon/docx/01_mainpage.dox | 30 - AudioManagerDaemon/docx/02_license.dox | 38 - AudioManagerDaemon/docx/02_x_dependecies.dox | 26 - AudioManagerDaemon/docx/02_y_versioning.dox | 31 - .../docx/03_architecture_overview.dox | 85 - AudioManagerDaemon/docx/03_x_uml_model.dox | 49 - AudioManagerDaemon/docx/04_components.dox | 99 - AudioManagerDaemon/docx/04_d_commonAPI.dox | 30 - AudioManagerDaemon/docx/04_x_elements.dox | 63 - .../docx/04_y_audiomanager_and_sources.dox | 92 - AudioManagerDaemon/docx/05_unique.dox | 36 - AudioManagerDaemon/docx/06_classification.dox | 32 - AudioManagerDaemon/docx/07_interrupts.dox | 36 - AudioManagerDaemon/docx/08_connections.dox | 33 - AudioManagerDaemon/docx/09_lipsync.dox | 37 - AudioManagerDaemon/docx/10_early_audio.dox | 31 - AudioManagerDaemon/docx/11_views.dox | 33 - AudioManagerDaemon/docx/12_volumes.dox | 29 - AudioManagerDaemon/docx/13_properties.dox | 33 - AudioManagerDaemon/docx/13_x_notifications.dox | 64 - AudioManagerDaemon/docx/14_misc.dox | 39 - AudioManagerDaemon/docx/14_u_last_user_mode.dox | 37 - AudioManagerDaemon/docx/14_x_mainloop.dox | 49 - AudioManagerDaemon/docx/14_y_watchdog.dox | 44 - AudioManagerDaemon/docx/14_zz_Startup_Rundown.dox | 30 - .../docx/15_a_CommandLineParsing.dox | 45 - AudioManagerDaemon/docx/15_dlt_support.dox | 23 - AudioManagerDaemon/docx/15_x_eclipse.dox | 91 - AudioManagerDaemon/docx/16_readme.dox | 20 - AudioManagerDaemon/docx/Doxyfile.in | 268 - AudioManagerDaemon/docx/images/AudioDomains.gif | Bin 18948 -> 0 bytes AudioManagerDaemon/docx/images/AudioManagement.png | Bin 34386 -> 0 bytes .../docx/images/AvailabilityofSinks.png | Bin 37630 -> 0 bytes .../docx/images/AvailabilityofSources.png | Bin 37577 -> 0 bytes AudioManagerDaemon/docx/images/CancelRundown.png | Bin 61007 -> 0 bytes .../images/ChangeofAudioformatduringplaytime.png | Bin 46422 -> 0 bytes AudioManagerDaemon/docx/images/ClassDiagramm.png | Bin 220221 -> 0 bytes .../docx/images/Deferred_Call_async.png | Bin 27008 -> 0 bytes .../docx/images/Deferred_Call_sync.png | Bin 39301 -> 0 bytes AudioManagerDaemon/docx/images/Gateway.gif | Bin 14829 -> 0 bytes AudioManagerDaemon/docx/images/GatewayMatrix.png | Bin 12269 -> 0 bytes .../docx/images/Interaction_with_sourcessinks.png | Bin 19385 -> 0 bytes .../docx/images/Interacton_Overview.png | Bin 62617 -> 0 bytes .../docx/images/InterruptStatusChange.png | Bin 22021 -> 0 bytes .../docx/images/LastUserModeHandlingExample.png | Bin 49412 -> 0 bytes AudioManagerDaemon/docx/images/Levels.png | Bin 52975 -> 0 bytes AudioManagerDaemon/docx/images/Lifecylerequest.png | Bin 48509 -> 0 bytes AudioManagerDaemon/docx/images/Mainloop.png | Bin 46228 -> 0 bytes .../docx/images/NodeStateManagementRelations.png | Bin 19326 -> 0 bytes AudioManagerDaemon/docx/images/Notifications.png | Bin 23940 -> 0 bytes .../docx/images/PluginCommandInterfaceCAPI.png | Bin 114519 -> 0 bytes .../docx/images/PluginRoutingInterfaceCAPI.png | Bin 167624 -> 0 bytes AudioManagerDaemon/docx/images/Register_Domain.png | Bin 17905 -> 0 bytes AudioManagerDaemon/docx/images/Registrations.png | Bin 38991 -> 0 bytes AudioManagerDaemon/docx/images/Rundown.png | Bin 75612 -> 0 bytes .../docx/images/SettingConnectionFormats.png | Bin 26690 -> 0 bytes .../docx/images/SoundPropertyChangeofSink.png | Bin 34583 -> 0 bytes .../docx/images/SoundPropertyChangeofSource.png | Bin 32592 -> 0 bytes AudioManagerDaemon/docx/images/SourceStates.png | Bin 32217 -> 0 bytes AudioManagerDaemon/docx/images/Startup.png | Bin 86887 -> 0 bytes .../docx/images/StartupWithLastUserMode.png | Bin 22247 -> 0 bytes .../docx/images/VolumeChangesofSinks.png | Bin 47122 -> 0 bytes .../docx/images/VolumeChangesofSources.png | Bin 41243 -> 0 bytes AudioManagerDaemon/docx/images/bus_topology.png | Bin 21535 -> 0 bytes AudioManagerDaemon/docx/images/daemon_insight.png | Bin 64057 -> 0 bytes AudioManagerDaemon/docx/images/delay.jpg | Bin 17066 -> 0 bytes AudioManagerDaemon/docx/images/dependencies.png | Bin 38376 -> 0 bytes .../docx/images/dependencies_test.png | Bin 59908 -> 0 bytes .../docx/images/dependency_created.png | Bin 119569 -> 0 bytes AudioManagerDaemon/docx/images/early.png | Bin 18557 -> 0 bytes AudioManagerDaemon/docx/images/example_system.png | Bin 10379 -> 0 bytes AudioManagerDaemon/docx/images/genivilogo.png | Bin 9537 -> 0 bytes AudioManagerDaemon/docx/images/late.png | Bin 15928 -> 0 bytes .../docx/images/routing_hierarchy.png | Bin 11645 -> 0 bytes AudioManagerDaemon/docx/images/unique.svg | 209 - AudioManagerDaemon/docx/images/versioning.png | Bin 23647 -> 0 bytes AudioManagerDaemon/docx/images/versioning_new.png | Bin 18298 -> 0 bytes AudioManagerDaemon/docx/images/views.png | Bin 65262 -> 0 bytes AudioManagerDaemon/include/CAmCommandReceiver.h | 97 - AudioManagerDaemon/include/CAmCommandSender.h | 91 - AudioManagerDaemon/include/CAmControlReceiver.h | 156 - AudioManagerDaemon/include/CAmControlSender.h | 154 - AudioManagerDaemon/include/CAmDatabaseHandlerMap.h | 495 -- .../include/CAmDatabaseHandlerSQLite.h | 208 - AudioManagerDaemon/include/CAmDatabaseObserver.h | 87 - AudioManagerDaemon/include/CAmGraph.h | 630 --- AudioManagerDaemon/include/CAmLog.h | 129 - AudioManagerDaemon/include/CAmRouter.h | 317 -- AudioManagerDaemon/include/CAmRoutingReceiver.h | 127 - AudioManagerDaemon/include/CAmRoutingSender.h | 155 - AudioManagerDaemon/include/CAmTelnetMenuHelper.h | 204 - AudioManagerDaemon/include/CAmTelnetServer.h | 100 - AudioManagerDaemon/include/IAmDatabaseHandler.h | 200 - AudioManagerDaemon/include/TAmPluginTemplate.h | 91 - AudioManagerDaemon/src/CAmCommandReceiver.cpp | 264 - AudioManagerDaemon/src/CAmCommandSender.cpp | 364 -- AudioManagerDaemon/src/CAmControlReceiver.cpp | 606 --- AudioManagerDaemon/src/CAmControlSender.cpp | 513 -- AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp | 3079 ----------- .../src/CAmDatabaseHandlerSQLite.cpp | 5651 -------------------- AudioManagerDaemon/src/CAmDatabaseObserver.cpp | 242 - AudioManagerDaemon/src/CAmLog.cpp | 101 - AudioManagerDaemon/src/CAmRouter.cpp | 884 --- AudioManagerDaemon/src/CAmRoutingReceiver.cpp | 620 --- AudioManagerDaemon/src/CAmRoutingSender.cpp | 833 --- AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp | 1438 ----- AudioManagerDaemon/src/CAmTelnetServer.cpp | 257 - AudioManagerDaemon/src/main.cpp | 14 +- .../CAmControlInterfaceTest.cpp | 662 --- .../CAmControlInterfaceTest.h | 76 - .../test/AmControlInterfaceTest/CMakeLists.txt | 95 - .../CAmDatabaseHandlerTest.cpp | 2585 --------- .../AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h | 75 - .../test/AmDatabaseHandlerTest/CMakeLists.txt | 92 - .../test/AmMapHandlerTest/CAmMapHandlerTest.cpp | 3265 ----------- .../test/AmMapHandlerTest/CAmMapHandlerTest.h | 92 - .../AmMapHandlerTest/CAmTestDatabaseObserver.cpp | 98 - .../test/AmMapHandlerTest/CMakeLists.txt | 90 - .../test/AmMapHandlerTest/MockDatabaseObserver.h | 120 - .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 3178 ----------- .../test/AmRouterMapTest/CAmRouterMapTest.h | 108 - .../test/AmRouterMapTest/CMakeLists.txt | 81 - .../test/AmRouterTest/CAmRouterTest.cpp | 1960 ------- .../test/AmRouterTest/CAmRouterTest.h | 81 - .../test/AmRouterTest/CMakeLists.txt | 81 - .../CAmRoutingInterfaceTest.cpp | 371 -- .../CAmRoutingInterfaceTest.h | 71 - .../test/AmRoutingInterfaceTest/CMakeLists.txt | 90 - .../AmSocketHandlerTest/CAmSocketHandlerTest.cpp | 357 -- .../AmSocketHandlerTest/CAmSocketHandlerTest.h | 87 - .../test/AmSocketHandlerTest/CMakeLists.txt | 80 - .../AmTelnetServerTest/CAmTelnetServerTest.cpp | 209 - .../test/AmTelnetServerTest/CAmTelnetServerTest.h | 107 - .../test/AmTelnetServerTest/CMakeLists.txt | 90 - AudioManagerDaemon/test/CAmCommonFunctions.cpp | 383 -- AudioManagerDaemon/test/CAmCommonFunctions.h | 96 - AudioManagerDaemon/test/CMakeLists.txt | 42 - AudioManagerDaemon/test/IAmCommandBackdoor.h | 47 - AudioManagerDaemon/test/IAmControlBackdoor.h | 44 - AudioManagerDaemon/test/IAmRoutingBackdoor.h | 46 - AudioManagerDaemon/test/MockIAmCommandSend.h | 94 - AudioManagerDaemon/test/MockIAmControlSend.h | 160 - AudioManagerDaemon/test/MockIAmRoutingSend.h | 83 - AudioManagerUtilities/CMakeLists.txt | 151 +- .../include/CAmCommonAPIWrapper.h | 4 - AudioManagerUtilities/include/CAmDltWrapper.h | 10 +- AudioManagerUtilities/include/CAmSocketHandler.h | 43 +- AudioManagerUtilities/include/sd-daemon.h | 286 - AudioManagerUtilities/src/CAmDltWrapper.cpp | 108 +- AudioManagerUtilities/src/CAmSocketHandler.cpp | 3 +- AudioManagerUtilities/src/CAmWatchdog.cpp | 9 +- AudioManagerUtilities/src/sd-daemon.c | 534 -- .../AmSocketHandlerTest/CAmSocketHandlerTest.cpp | 357 ++ .../AmSocketHandlerTest/CAmSocketHandlerTest.h | 87 + .../test/AmSocketHandlerTest/CMakeLists.txt | 50 + AudioManagerUtilities/test/CMakeLists.txt | 4 + CMakeLists.txt | 211 +- README | 138 +- README.html | 273 +- cmake/AudioManagerConfig.cmake.in | 35 + cmake/AudioManagerCoreConfig.cmake.in | 17 + cmake/AudioManagerUtilitiesConfig.cmake.in | 17 + cmake/MacroVersionFromGit.cmake | 1 - cmake/audiomanagerConfig.cmake.in | 44 - cmake/audiomanagercore.pc.in | 10 + cmake/audiomanagerutilities.pc.in | 4 +- cmake/config.cmake.in | 7 +- cmake/gmock.pc.in | 9 + cmake/gtest.pc.in | 9 + docx/01_mainpage.dox | 30 + docx/02_license.dox | 38 + docx/02_x_dependecies.dox | 26 + docx/02_y_versioning.dox | 31 + docx/03_architecture_overview.dox | 85 + docx/03_x_uml_model.dox | 49 + docx/04_components.dox | 99 + docx/04_d_commonAPI.dox | 30 + docx/04_x_elements.dox | 63 + docx/04_y_audiomanager_and_sources.dox | 92 + docx/05_unique.dox | 36 + docx/06_classification.dox | 32 + docx/07_interrupts.dox | 36 + docx/08_connections.dox | 33 + docx/09_lipsync.dox | 37 + docx/10_early_audio.dox | 31 + docx/11_views.dox | 33 + docx/12_volumes.dox | 29 + docx/13_properties.dox | 33 + docx/13_x_notifications.dox | 64 + docx/14_misc.dox | 39 + docx/14_u_last_user_mode.dox | 37 + docx/14_x_mainloop.dox | 49 + docx/14_y_watchdog.dox | 44 + docx/14_zz_Startup_Rundown.dox | 30 + docx/15_a_CommandLineParsing.dox | 45 + docx/15_dlt_support.dox | 23 + docx/15_x_eclipse.dox | 91 + docx/16_readme.dox | 20 + docx/Doxyfile.in | 2326 ++++++++ docx/images/AudioDomains.gif | Bin 0 -> 18948 bytes docx/images/AudioManagement.png | Bin 0 -> 34386 bytes docx/images/AvailabilityofSinks.png | Bin 0 -> 37630 bytes docx/images/AvailabilityofSources.png | Bin 0 -> 37577 bytes docx/images/CancelRundown.png | Bin 0 -> 61007 bytes docx/images/ChangeofAudioformatduringplaytime.png | Bin 0 -> 46422 bytes docx/images/ClassDiagramm.png | Bin 0 -> 220221 bytes docx/images/Deferred_Call_async.png | Bin 0 -> 27008 bytes docx/images/Deferred_Call_sync.png | Bin 0 -> 39301 bytes docx/images/Gateway.gif | Bin 0 -> 14829 bytes docx/images/GatewayMatrix.png | Bin 0 -> 12269 bytes docx/images/Interaction_with_sourcessinks.png | Bin 0 -> 19385 bytes docx/images/Interacton_Overview.png | Bin 0 -> 62617 bytes docx/images/InterruptStatusChange.png | Bin 0 -> 22021 bytes docx/images/LastUserModeHandlingExample.png | Bin 0 -> 49412 bytes docx/images/Levels.png | Bin 0 -> 52975 bytes docx/images/Lifecylerequest.png | Bin 0 -> 48509 bytes docx/images/Mainloop.png | Bin 0 -> 46228 bytes docx/images/NodeStateManagementRelations.png | Bin 0 -> 19326 bytes docx/images/Notifications.png | Bin 0 -> 23940 bytes docx/images/PluginCommandInterfaceCAPI.png | Bin 0 -> 114519 bytes docx/images/PluginRoutingInterfaceCAPI.png | Bin 0 -> 167624 bytes docx/images/Register_Domain.png | Bin 0 -> 17905 bytes docx/images/Registrations.png | Bin 0 -> 38991 bytes docx/images/Rundown.png | Bin 0 -> 75612 bytes docx/images/SettingConnectionFormats.png | Bin 0 -> 26690 bytes docx/images/SoundPropertyChangeofSink.png | Bin 0 -> 34583 bytes docx/images/SoundPropertyChangeofSource.png | Bin 0 -> 32592 bytes docx/images/SourceStates.png | Bin 0 -> 32217 bytes docx/images/Startup.png | Bin 0 -> 86887 bytes docx/images/StartupWithLastUserMode.png | Bin 0 -> 22247 bytes docx/images/VolumeChangesofSinks.png | Bin 0 -> 47122 bytes docx/images/VolumeChangesofSources.png | Bin 0 -> 41243 bytes docx/images/bus_topology.png | Bin 0 -> 21535 bytes docx/images/daemon_insight.png | Bin 0 -> 64057 bytes docx/images/delay.jpg | Bin 0 -> 17066 bytes docx/images/dependencies.png | Bin 0 -> 38376 bytes docx/images/dependencies_test.png | Bin 0 -> 59908 bytes docx/images/dependency_created.png | Bin 0 -> 119569 bytes docx/images/early.png | Bin 0 -> 18557 bytes docx/images/example_system.png | Bin 0 -> 10379 bytes docx/images/genivilogo.png | Bin 0 -> 9537 bytes docx/images/late.png | Bin 0 -> 15928 bytes docx/images/routing_hierarchy.png | Bin 0 -> 11645 bytes docx/images/unique.svg | 209 + docx/images/versioning.png | Bin 0 -> 23647 bytes docx/images/versioning_new.png | Bin 0 -> 18298 bytes docx/images/views.png | Bin 0 -> 65262 bytes googleMock/CMakeLists.txt | 7 + googleMock/gtest/CMakeLists.txt | 7 + 313 files changed, 29349 insertions(+), 36509 deletions(-) create mode 100644 AudioManagerCore/CMakeLists.txt create mode 100644 AudioManagerCore/include/CAmCommandReceiver.h create mode 100644 AudioManagerCore/include/CAmCommandSender.h create mode 100644 AudioManagerCore/include/CAmControlReceiver.h create mode 100644 AudioManagerCore/include/CAmControlSender.h create mode 100644 AudioManagerCore/include/CAmDatabaseHandlerMap.h create mode 100644 AudioManagerCore/include/CAmDatabaseObserver.h create mode 100644 AudioManagerCore/include/CAmGraph.h create mode 100644 AudioManagerCore/include/CAmLog.h create mode 100644 AudioManagerCore/include/CAmRouter.h create mode 100644 AudioManagerCore/include/CAmRoutingReceiver.h create mode 100644 AudioManagerCore/include/CAmRoutingSender.h create mode 100644 AudioManagerCore/include/CAmTelnetMenuHelper.h create mode 100644 AudioManagerCore/include/CAmTelnetServer.h create mode 100644 AudioManagerCore/include/IAmDatabaseHandler.h create mode 100644 AudioManagerCore/include/TAmPluginTemplate.h create mode 100644 AudioManagerCore/src/CAmCommandReceiver.cpp create mode 100644 AudioManagerCore/src/CAmCommandSender.cpp create mode 100644 AudioManagerCore/src/CAmControlReceiver.cpp create mode 100644 AudioManagerCore/src/CAmControlSender.cpp create mode 100644 AudioManagerCore/src/CAmDatabaseHandlerMap.cpp create mode 100644 AudioManagerCore/src/CAmDatabaseObserver.cpp create mode 100644 AudioManagerCore/src/CAmLog.cpp create mode 100644 AudioManagerCore/src/CAmRouter.cpp create mode 100644 AudioManagerCore/src/CAmRoutingReceiver.cpp create mode 100644 AudioManagerCore/src/CAmRoutingSender.cpp create mode 100644 AudioManagerCore/src/CAmTelnetMenuHelper.cpp create mode 100755 AudioManagerCore/src/CAmTelnetServer.cpp create mode 100644 AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp create mode 100644 AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h create mode 100644 AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h create mode 100644 AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp create mode 100644 AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h create mode 100644 AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp create mode 100644 AudioManagerCore/test/AmRouterTest/CAmRouterTest.h create mode 100644 AudioManagerCore/test/AmRouterTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp create mode 100644 AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h create mode 100644 AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp create mode 100644 AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h create mode 100644 AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt create mode 100644 AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ create mode 100644 AudioManagerCore/test/CAmCommonFunctions.cpp create mode 100644 AudioManagerCore/test/CAmCommonFunctions.h create mode 100644 AudioManagerCore/test/CMakeLists.txt create mode 100644 AudioManagerCore/test/IAmCommandBackdoor.h create mode 100644 AudioManagerCore/test/IAmControlBackdoor.h create mode 100644 AudioManagerCore/test/IAmRoutingBackdoor.h create mode 100644 AudioManagerCore/test/MockIAmCommandSend.h create mode 100644 AudioManagerCore/test/MockIAmControlSend.h create mode 100644 AudioManagerCore/test/MockIAmRoutingSend.h delete mode 100644 AudioManagerDaemon/docx/01_mainpage.dox delete mode 100644 AudioManagerDaemon/docx/02_license.dox delete mode 100644 AudioManagerDaemon/docx/02_x_dependecies.dox delete mode 100644 AudioManagerDaemon/docx/02_y_versioning.dox delete mode 100644 AudioManagerDaemon/docx/03_architecture_overview.dox delete mode 100644 AudioManagerDaemon/docx/03_x_uml_model.dox delete mode 100644 AudioManagerDaemon/docx/04_components.dox delete mode 100644 AudioManagerDaemon/docx/04_d_commonAPI.dox delete mode 100644 AudioManagerDaemon/docx/04_x_elements.dox delete mode 100644 AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox delete mode 100644 AudioManagerDaemon/docx/05_unique.dox delete mode 100644 AudioManagerDaemon/docx/06_classification.dox delete mode 100644 AudioManagerDaemon/docx/07_interrupts.dox delete mode 100644 AudioManagerDaemon/docx/08_connections.dox delete mode 100644 AudioManagerDaemon/docx/09_lipsync.dox delete mode 100644 AudioManagerDaemon/docx/10_early_audio.dox delete mode 100644 AudioManagerDaemon/docx/11_views.dox delete mode 100644 AudioManagerDaemon/docx/12_volumes.dox delete mode 100644 AudioManagerDaemon/docx/13_properties.dox delete mode 100644 AudioManagerDaemon/docx/13_x_notifications.dox delete mode 100644 AudioManagerDaemon/docx/14_misc.dox delete mode 100644 AudioManagerDaemon/docx/14_u_last_user_mode.dox delete mode 100644 AudioManagerDaemon/docx/14_x_mainloop.dox delete mode 100644 AudioManagerDaemon/docx/14_y_watchdog.dox delete mode 100644 AudioManagerDaemon/docx/14_zz_Startup_Rundown.dox delete mode 100644 AudioManagerDaemon/docx/15_a_CommandLineParsing.dox delete mode 100644 AudioManagerDaemon/docx/15_dlt_support.dox delete mode 100644 AudioManagerDaemon/docx/15_x_eclipse.dox delete mode 100644 AudioManagerDaemon/docx/16_readme.dox delete mode 100644 AudioManagerDaemon/docx/Doxyfile.in delete mode 100644 AudioManagerDaemon/docx/images/AudioDomains.gif delete mode 100755 AudioManagerDaemon/docx/images/AudioManagement.png delete mode 100644 AudioManagerDaemon/docx/images/AvailabilityofSinks.png delete mode 100644 AudioManagerDaemon/docx/images/AvailabilityofSources.png delete mode 100755 AudioManagerDaemon/docx/images/CancelRundown.png delete mode 100755 AudioManagerDaemon/docx/images/ChangeofAudioformatduringplaytime.png delete mode 100755 AudioManagerDaemon/docx/images/ClassDiagramm.png delete mode 100644 AudioManagerDaemon/docx/images/Deferred_Call_async.png delete mode 100644 AudioManagerDaemon/docx/images/Deferred_Call_sync.png delete mode 100644 AudioManagerDaemon/docx/images/Gateway.gif delete mode 100644 AudioManagerDaemon/docx/images/GatewayMatrix.png delete mode 100644 AudioManagerDaemon/docx/images/Interaction_with_sourcessinks.png delete mode 100644 AudioManagerDaemon/docx/images/Interacton_Overview.png delete mode 100755 AudioManagerDaemon/docx/images/InterruptStatusChange.png delete mode 100755 AudioManagerDaemon/docx/images/LastUserModeHandlingExample.png delete mode 100644 AudioManagerDaemon/docx/images/Levels.png delete mode 100755 AudioManagerDaemon/docx/images/Lifecylerequest.png delete mode 100644 AudioManagerDaemon/docx/images/Mainloop.png delete mode 100755 AudioManagerDaemon/docx/images/NodeStateManagementRelations.png delete mode 100755 AudioManagerDaemon/docx/images/Notifications.png delete mode 100644 AudioManagerDaemon/docx/images/PluginCommandInterfaceCAPI.png delete mode 100644 AudioManagerDaemon/docx/images/PluginRoutingInterfaceCAPI.png delete mode 100644 AudioManagerDaemon/docx/images/Register_Domain.png delete mode 100755 AudioManagerDaemon/docx/images/Registrations.png delete mode 100755 AudioManagerDaemon/docx/images/Rundown.png delete mode 100755 AudioManagerDaemon/docx/images/SettingConnectionFormats.png delete mode 100644 AudioManagerDaemon/docx/images/SoundPropertyChangeofSink.png delete mode 100644 AudioManagerDaemon/docx/images/SoundPropertyChangeofSource.png delete mode 100755 AudioManagerDaemon/docx/images/SourceStates.png delete mode 100755 AudioManagerDaemon/docx/images/Startup.png delete mode 100755 AudioManagerDaemon/docx/images/StartupWithLastUserMode.png delete mode 100755 AudioManagerDaemon/docx/images/VolumeChangesofSinks.png delete mode 100644 AudioManagerDaemon/docx/images/VolumeChangesofSources.png delete mode 100644 AudioManagerDaemon/docx/images/bus_topology.png delete mode 100755 AudioManagerDaemon/docx/images/daemon_insight.png delete mode 100644 AudioManagerDaemon/docx/images/delay.jpg delete mode 100644 AudioManagerDaemon/docx/images/dependencies.png delete mode 100644 AudioManagerDaemon/docx/images/dependencies_test.png delete mode 100644 AudioManagerDaemon/docx/images/dependency_created.png delete mode 100644 AudioManagerDaemon/docx/images/early.png delete mode 100644 AudioManagerDaemon/docx/images/example_system.png delete mode 100644 AudioManagerDaemon/docx/images/genivilogo.png delete mode 100644 AudioManagerDaemon/docx/images/late.png delete mode 100644 AudioManagerDaemon/docx/images/routing_hierarchy.png delete mode 100644 AudioManagerDaemon/docx/images/unique.svg delete mode 100644 AudioManagerDaemon/docx/images/versioning.png delete mode 100755 AudioManagerDaemon/docx/images/versioning_new.png delete mode 100644 AudioManagerDaemon/docx/images/views.png delete mode 100644 AudioManagerDaemon/include/CAmCommandReceiver.h delete mode 100644 AudioManagerDaemon/include/CAmCommandSender.h delete mode 100644 AudioManagerDaemon/include/CAmControlReceiver.h delete mode 100644 AudioManagerDaemon/include/CAmControlSender.h delete mode 100644 AudioManagerDaemon/include/CAmDatabaseHandlerMap.h delete mode 100644 AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h delete mode 100644 AudioManagerDaemon/include/CAmDatabaseObserver.h delete mode 100644 AudioManagerDaemon/include/CAmGraph.h delete mode 100644 AudioManagerDaemon/include/CAmLog.h delete mode 100644 AudioManagerDaemon/include/CAmRouter.h delete mode 100644 AudioManagerDaemon/include/CAmRoutingReceiver.h delete mode 100644 AudioManagerDaemon/include/CAmRoutingSender.h delete mode 100644 AudioManagerDaemon/include/CAmTelnetMenuHelper.h delete mode 100644 AudioManagerDaemon/include/CAmTelnetServer.h delete mode 100644 AudioManagerDaemon/include/IAmDatabaseHandler.h delete mode 100644 AudioManagerDaemon/include/TAmPluginTemplate.h delete mode 100644 AudioManagerDaemon/src/CAmCommandReceiver.cpp delete mode 100644 AudioManagerDaemon/src/CAmCommandSender.cpp delete mode 100644 AudioManagerDaemon/src/CAmControlReceiver.cpp delete mode 100644 AudioManagerDaemon/src/CAmControlSender.cpp delete mode 100644 AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp delete mode 100644 AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp delete mode 100644 AudioManagerDaemon/src/CAmDatabaseObserver.cpp delete mode 100644 AudioManagerDaemon/src/CAmLog.cpp delete mode 100644 AudioManagerDaemon/src/CAmRouter.cpp delete mode 100644 AudioManagerDaemon/src/CAmRoutingReceiver.cpp delete mode 100644 AudioManagerDaemon/src/CAmRoutingSender.cpp delete mode 100644 AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp delete mode 100755 AudioManagerDaemon/src/CAmTelnetServer.cpp delete mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp delete mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h delete mode 100644 AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp delete mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h delete mode 100644 AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp delete mode 100644 AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h delete mode 100644 AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp delete mode 100644 AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h delete mode 100644 AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp delete mode 100644 AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h delete mode 100644 AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp delete mode 100644 AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h delete mode 100644 AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp delete mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h delete mode 100644 AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp delete mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h delete mode 100644 AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp delete mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h delete mode 100644 AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/CAmCommonFunctions.cpp delete mode 100644 AudioManagerDaemon/test/CAmCommonFunctions.h delete mode 100644 AudioManagerDaemon/test/CMakeLists.txt delete mode 100644 AudioManagerDaemon/test/IAmCommandBackdoor.h delete mode 100644 AudioManagerDaemon/test/IAmControlBackdoor.h delete mode 100644 AudioManagerDaemon/test/IAmRoutingBackdoor.h delete mode 100644 AudioManagerDaemon/test/MockIAmCommandSend.h delete mode 100644 AudioManagerDaemon/test/MockIAmControlSend.h delete mode 100644 AudioManagerDaemon/test/MockIAmRoutingSend.h delete mode 100644 AudioManagerUtilities/include/sd-daemon.h delete mode 100644 AudioManagerUtilities/src/sd-daemon.c create mode 100644 AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp create mode 100644 AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h create mode 100644 AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt create mode 100644 AudioManagerUtilities/test/CMakeLists.txt create mode 100644 cmake/AudioManagerConfig.cmake.in create mode 100644 cmake/AudioManagerCoreConfig.cmake.in create mode 100644 cmake/AudioManagerUtilitiesConfig.cmake.in delete mode 100644 cmake/audiomanagerConfig.cmake.in create mode 100644 cmake/audiomanagercore.pc.in create mode 100644 cmake/gmock.pc.in create mode 100644 cmake/gtest.pc.in create mode 100644 docx/01_mainpage.dox create mode 100644 docx/02_license.dox create mode 100644 docx/02_x_dependecies.dox create mode 100644 docx/02_y_versioning.dox create mode 100644 docx/03_architecture_overview.dox create mode 100644 docx/03_x_uml_model.dox create mode 100644 docx/04_components.dox create mode 100644 docx/04_d_commonAPI.dox create mode 100644 docx/04_x_elements.dox create mode 100644 docx/04_y_audiomanager_and_sources.dox create mode 100644 docx/05_unique.dox create mode 100644 docx/06_classification.dox create mode 100644 docx/07_interrupts.dox create mode 100644 docx/08_connections.dox create mode 100644 docx/09_lipsync.dox create mode 100644 docx/10_early_audio.dox create mode 100644 docx/11_views.dox create mode 100644 docx/12_volumes.dox create mode 100644 docx/13_properties.dox create mode 100644 docx/13_x_notifications.dox create mode 100644 docx/14_misc.dox create mode 100644 docx/14_u_last_user_mode.dox create mode 100644 docx/14_x_mainloop.dox create mode 100644 docx/14_y_watchdog.dox create mode 100644 docx/14_zz_Startup_Rundown.dox create mode 100644 docx/15_a_CommandLineParsing.dox create mode 100644 docx/15_dlt_support.dox create mode 100644 docx/15_x_eclipse.dox create mode 100644 docx/16_readme.dox create mode 100644 docx/Doxyfile.in create mode 100644 docx/images/AudioDomains.gif create mode 100755 docx/images/AudioManagement.png create mode 100644 docx/images/AvailabilityofSinks.png create mode 100644 docx/images/AvailabilityofSources.png create mode 100755 docx/images/CancelRundown.png create mode 100755 docx/images/ChangeofAudioformatduringplaytime.png create mode 100755 docx/images/ClassDiagramm.png create mode 100644 docx/images/Deferred_Call_async.png create mode 100644 docx/images/Deferred_Call_sync.png create mode 100644 docx/images/Gateway.gif create mode 100644 docx/images/GatewayMatrix.png create mode 100644 docx/images/Interaction_with_sourcessinks.png create mode 100644 docx/images/Interacton_Overview.png create mode 100755 docx/images/InterruptStatusChange.png create mode 100755 docx/images/LastUserModeHandlingExample.png create mode 100644 docx/images/Levels.png create mode 100755 docx/images/Lifecylerequest.png create mode 100644 docx/images/Mainloop.png create mode 100755 docx/images/NodeStateManagementRelations.png create mode 100755 docx/images/Notifications.png create mode 100644 docx/images/PluginCommandInterfaceCAPI.png create mode 100644 docx/images/PluginRoutingInterfaceCAPI.png create mode 100644 docx/images/Register_Domain.png create mode 100755 docx/images/Registrations.png create mode 100755 docx/images/Rundown.png create mode 100755 docx/images/SettingConnectionFormats.png create mode 100644 docx/images/SoundPropertyChangeofSink.png create mode 100644 docx/images/SoundPropertyChangeofSource.png create mode 100755 docx/images/SourceStates.png create mode 100755 docx/images/Startup.png create mode 100755 docx/images/StartupWithLastUserMode.png create mode 100755 docx/images/VolumeChangesofSinks.png create mode 100644 docx/images/VolumeChangesofSources.png create mode 100644 docx/images/bus_topology.png create mode 100755 docx/images/daemon_insight.png create mode 100644 docx/images/delay.jpg create mode 100644 docx/images/dependencies.png create mode 100644 docx/images/dependencies_test.png create mode 100644 docx/images/dependency_created.png create mode 100644 docx/images/early.png create mode 100644 docx/images/example_system.png create mode 100644 docx/images/genivilogo.png create mode 100644 docx/images/late.png create mode 100644 docx/images/routing_hierarchy.png create mode 100644 docx/images/unique.svg create mode 100644 docx/images/versioning.png create mode 100755 docx/images/versioning_new.png create mode 100644 docx/images/views.png diff --git a/AudioManagerCore/CMakeLists.txt b/AudioManagerCore/CMakeLists.txt new file mode 100644 index 0000000..2a553ba --- /dev/null +++ b/AudioManagerCore/CMakeLists.txt @@ -0,0 +1,109 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AudioManagerCore LANGUAGES CXX VERSION ${DAEMONVERSION}) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +SET(AUDIOMANAGER_CORE_INCLUDE + ${AUDIOMANAGER_CORE}/include + ${AUDIOMANAGER_UTILITIES_INCLUDE} + CACHE INTERNAL "AUDIOMANAGER_CORE_INCLUDE directories" FORCE) + +SET(AUDIO_MANAGER_CORE_LIBS + ${AUDIO_MANAGER_UTILITIES_LIBS} + AudioManagerUtilities + CACHE INTERNAL "AUDIO_MANAGER_CORE_LIBS libs" FORCE) + +IF (WITH_SHARED_CORE) + SET(LIBRARY_TYPE SHARED) +ELSE (WITH_SHARED_CORE) + SET(LIBRARY_TYPE STATIC) +ENDIF (WITH_SHARED_CORE) + +set(AUDIOMAN_CORE_SRCS_CXX + src/CAmCommandReceiver.cpp + src/CAmCommandSender.cpp + src/CAmControlReceiver.cpp + src/CAmControlSender.cpp + src/CAmDatabaseObserver.cpp + src/CAmRoutingReceiver.cpp + src/CAmRoutingSender.cpp + src/CAmRouter.cpp + src/CAmLog.cpp + src/CAmDatabaseHandlerMap.cpp +) + +if(WITH_TELNET) + set (AUDIOMAN_CORE_SRCS_CXX + ${AUDIOMAN_CORE_SRCS_CXX} + src/CAmTelnetServer.cpp + src/CAmTelnetMenuHelper.cpp) +endif(WITH_TELNET) + +INCLUDE_DIRECTORIES(${AUDIOMANAGER_CORE_INCLUDE}) + +ADD_LIBRARY(AudioManagerCore ${LIBRARY_TYPE} ${AUDIOMAN_CORE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AudioManagerCore ${AUDIO_MANAGER_CORE_LIBS} ) + +ADD_DEPENDENCIES(AudioManagerCore AudioManagerUtilities) + +set_target_properties(AudioManagerCore PROPERTIES VERSION ${AudioManagerCore_VERSION} SOVERSION ${AudioManagerCore_VERSION_MAJOR}) + + +IF (WITH_SHARED_CORE) + INSTALL(TARGETS AudioManagerCore + LIBRARY DESTINATION lib + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT bin) +ELSE (WITH_SHARED_CORE) + INSTALL(TARGETS AudioManagerCore + ARCHIVE DESTINATION lib + COMPONENT dev) +ENDIF (WITH_SHARED_CORE) + +configure_file( ${CMAKE_SOURCE_DIR}/cmake/audiomanagercore.pc.in ${CMAKE_BINARY_DIR}/audiomanagercore.pc @ONLY ) +install(FILES ${CMAKE_BINARY_DIR}/audiomanagercore.pc DESTINATION lib/pkgconfig COMPONENT devel) + +configure_package_config_file ( + ${CMAKE_SOURCE_DIR}/cmake/AudioManagerCoreConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerCoreConfig.cmake + INSTALL_DESTINATION lib/${LIB_INSTALL_SUFFIX}/cmake + PATH_VARS AUDIO_INCLUDE_FOLDER ) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerCoreConfigVersion.cmake + VERSION ${DAEMONVERSION} + COMPATIBILITY SameMajorVersion ) + +install( +FILES ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerCoreConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerCoreConfigVersion.cmake +DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/AudioManagerCore-${DAEMONVERSION}) + +INSTALL(DIRECTORY "${AUDIOMANAGER_CORE}/include/" + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${LIB_INSTALL_SUFFIX}/AudioManagerCore + COMPONENT dev) + +if(WITH_TESTS) + add_subdirectory (test) +endif(WITH_TESTS) + + + diff --git a/AudioManagerCore/include/CAmCommandReceiver.h b/AudioManagerCore/include/CAmCommandReceiver.h new file mode 100644 index 0000000..0f30d81 --- /dev/null +++ b/AudioManagerCore/include/CAmCommandReceiver.h @@ -0,0 +1,97 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmCommandReceiver.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef COMMANDRECEIVER_H_ +#define COMMANDRECEIVER_H_ + +#include "IAmCommand.h" + +namespace am +{ + +class IAmDatabaseHandler; +class CAmControlSender; +class CAmDbusWrapper; +class CAmSocketHandler; + +/** + * This class realizes the command Interface + */ +class CAmCommandReceiver: public IAmCommandReceive +{ +public: + CAmCommandReceiver(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iControlSender, CAmSocketHandler* iSocketHandler); + CAmCommandReceiver(IAmDatabaseHandler* 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 getVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const; + 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 confirmCommandReady(const uint16_t handle, const am_Error_e error); + void confirmCommandRundown(const uint16_t handle, const am_Error_e error); + void getInterfaceVersion(std::string& version) const; + am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) const ; + am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) const ; + am_Error_e setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; + am_Error_e setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; + + 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: + IAmDatabaseHandler* 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 + am_Error_e mLastErrorStartup; + am_Error_e mLastErrorRundown; +}; + +} + +#endif /* COMMANDRECEIVER_H_ */ diff --git a/AudioManagerCore/include/CAmCommandSender.h b/AudioManagerCore/include/CAmCommandSender.h new file mode 100644 index 0000000..82363de --- /dev/null +++ b/AudioManagerCore/include/CAmCommandSender.h @@ -0,0 +1,91 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmCommandSender.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef COMMANDSENDER_H_ +#define COMMANDSENDER_H_ + +#ifdef UNIT_TEST +#include "../test/IAmCommandBackdoor.h" //we need this for the unit test +#endif + +#include "IAmCommand.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; + void cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties); + void cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties); + void cbSinkNotification(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification); + void cbSourceNotification(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification); + void cbSinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration); + void cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration); + +#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/AudioManagerCore/include/CAmControlReceiver.h b/AudioManagerCore/include/CAmControlReceiver.h new file mode 100644 index 0000000..3f39189 --- /dev/null +++ b/AudioManagerCore/include/CAmControlReceiver.h @@ -0,0 +1,156 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmControlReceiver.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CONTRONLRECEIVER_H_ +#define CONTRONLRECEIVER_H_ + +#include "IAmControl.h" + +namespace am +{ + +class CAmSocketHandler; +class IAmDatabaseHandler; +class CAmRoutingSender; +class CAmCommandSender; +class CAmRouter; +class CAmNodeStateCommunicator; + +/** + * This class is used to receive all commands from the control interface + */ +class CAmControlReceiver: public IAmControlReceive +{ +public: + CAmControlReceiver(IAmDatabaseHandler *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_CustomConnectionFormat_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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 enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID); + 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 removeConverterDB(const am_converterID_t converterID); + 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 getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) 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 getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConverterID) 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 getListConverters(std::vector& listConverters) 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(const am_Error_e error); + void confirmControllerRundown(const am_Error_e error); + am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler); + void getInterfaceVersion(std::string& version) const; + am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) ; + am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); + am_Error_e setVolumes(am_Handle_s& handle, const std::vector& listVolumes) ; + am_Error_e setSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) ; + am_Error_e setSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) ; + void sendMainSinkNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s& notificationPayload) ; + void sendMainSourceNotificationPayload(const am_sourceID_t sourceID, const am_NotificationPayload_s& notificationPayload) ; + am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; + am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; + am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; + am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const; + am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; + am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const; + am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e resyncConnectionState(const am_domainID_t domainID, std::vector& listOfExistingConnections); + +private: + IAmDatabaseHandler* 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 + CAmNodeStateCommunicator* mNodeStateCommunicator; +}; + +} + +#endif /* CONTRONLRECEIVER_H_ */ diff --git a/AudioManagerCore/include/CAmControlSender.h b/AudioManagerCore/include/CAmControlSender.h new file mode 100644 index 0000000..40ab379 --- /dev/null +++ b/AudioManagerCore/include/CAmControlSender.h @@ -0,0 +1,154 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmControlSender.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CONTROLSENDER_H_ +#define CONTROLSENDER_H_ + +#ifdef UNIT_TEST +#include "../test/IAmControlBackdoor.h" +#endif + +#include "IAmControl.h" +#include "CAmSocketHandler.h" +#include "unistd.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,CAmSocketHandler* sockethandler); + CAmControlSender(); + ~CAmControlSender(); + am_Error_e startupController(IAmControlReceive* controlreceiveinterface) ; + void setControllerReady() ; + void setControllerRundown(const int16_t signal) ; + 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 hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID); + am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ; + am_Error_e hookSystemDeregisterConverter(const am_converterID_t converterID) ; + 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 confirmCommandReady(const am_Error_e error) ; + void confirmRoutingReady(const am_Error_e error) ; + void confirmCommandRundown(const am_Error_e error) ; + void confirmRoutingRundown(const am_Error_e error) ; + void getInterfaceVersion(std::string& version) const ; + am_Error_e hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + am_Error_e hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + am_Error_e hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) ; + am_Error_e hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix); + void cbAckSetVolume(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error) ; + void cbAckSetSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; + void hookSinkNotificationDataChanged(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) ; + void hookSourceNotificationDataChanged(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) ; + am_Error_e hookUserSetMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) ; + am_Error_e hookUserSetMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) ; + void hookSystemSingleTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t time); + + void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); + bool checkerCallback(const sh_pollHandle_t handle, void* userData); + bool dispatcherCallback(const sh_pollHandle_t handle, void* userData); + + void setControllerRundownSafe(int16_t signal) + { + int16_t p(signal); + ssize_t result(-1); + result = write(mPipe[1], &p, sizeof(p)); + } + + TAmShPollFired receiverCallbackT; + TAmShPollCheck checkerCallbackT; + TAmShPollDispatch dispatcherCallbackT; + + + //we need this here to call the rundown from the signal handler. In case everything screwed up + static void CallsetControllerRundown(int16_t signal) + { + if (mInstance) + mInstance->setControllerRundown(signal); + } + + //this static callback is used from the signal handler. It is used when a normal rundown is assumed and the mainloop is used to call rundown. + static void CallsetControllerRundownSafe(int16_t signal) + { + if (mInstance) + { + mInstance->setControllerRundownSafe(signal); + } + } + +#ifdef UNIT_TEST + friend class IAmControlBackdoor; +#endif +private: + int mPipe[2]; + void* mlibHandle; //!< pointer to the loaded control plugin interface + IAmControlSend* mController; //!< pointer to the ControlSend interface + static CAmControlSender* mInstance; + int16_t mSignal; +}; + +} + +#endif /* CONTROLSENDER_H_ */ diff --git a/AudioManagerCore/include/CAmDatabaseHandlerMap.h b/AudioManagerCore/include/CAmDatabaseHandlerMap.h new file mode 100644 index 0000000..cf319f7 --- /dev/null +++ b/AudioManagerCore/include/CAmDatabaseHandlerMap.h @@ -0,0 +1,495 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmDatabaseHandlerMap.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MAPHANDLER_H_ +#define MAPHANDLER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "IAmDatabaseHandler.h" + +namespace am +{ +#ifndef AM_MAP_CAPACITY + #define AM_MAP_CAPACITY 0 +#endif + +#ifndef AM_MAX_CONNECTIONS + #define AM_MAX_CONNECTIONS 0x1000 +#endif + +#ifndef AM_MAX_MAIN_CONNECTIONS + #define AM_MAX_MAIN_CONNECTIONS SHRT_MAX +#endif + + + +//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 CAmDatabaseHandlerMap : public IAmDatabaseHandler +{ + bool mFirstStaticSink; //!< bool for dynamic range handling + bool mFirstStaticSource; //!< bool for dynamic range handling + bool mFirstStaticGateway; //!< bool for dynamic range handling + bool mFirstStaticConverter; //!< bool for dynamic range handling + bool mFirstStaticSinkClass; //!< bool for dynamic range handling + bool mFirstStaticSourceClass; //!< bool for dynamic range handling + bool mFirstStaticCrossfader; //!< bool for dynamic range handling + +public: + CAmDatabaseHandlerMap(); + virtual ~CAmDatabaseHandlerMap(); + 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 enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID); + 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 removeConverterDB(const am_converterID_t converterID); + 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 getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) 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 getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) 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_CustomSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; + am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; + am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) 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 getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) 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 getListConverters(std::vector & listConverters) 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 getDomainOfCrossfader(const am_converterID_t crossfader, 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 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); + am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); + am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); + am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations); + am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations); + am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); + am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); + am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); + am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); + am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration); + am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration); + + bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const; + bool existCrossFader(const am_crossfaderID_t crossfaderID) const; + bool existConnection(const am_Connection_s & connection) const; + bool existConnectionID(const am_connectionID_t connectionID) const; + bool existSource(const am_sourceID_t sourceID) const; + bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const; + bool existSourceName(const std::string& name) const; + bool existSink(const am_sinkID_t sinkID) const; + bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const; + bool existSinkName(const std::string& name) const; + bool existDomain(const am_domainID_t domainID) const; + bool existGateway(const am_gatewayID_t gatewayID) const; + bool existConverter(const am_converterID_t converterID) const; + bool existSinkClass(const am_sinkClass_t sinkClassID) const; + bool existSourceClass(const am_sourceClass_t sourceClassID) const; + void registerObserver(CAmDatabaseObserver *iObserver); + bool sourceVisible(const am_sourceID_t sourceID) const; + bool sinkVisible(const am_sinkID_t sinkID) const; + bool isComponentConnected(const am_Gateway_s & gateway) const; + bool isComponentConnected(const am_Converter_s & converter) const; + void dump( std::ostream & output ) const; + am_Error_e enumerateSources(std::function cb) const; + am_Error_e enumerateSinks(std::function cb) const; + am_Error_e enumerateGateways(std::function cb) const; + am_Error_e enumerateConverters(std::function cb) const; + /** + * The following structures extend the base structures with the field 'reserved'. + */ + +#define AM_SUBCLASS_BEGIN(Subclass, Class) \ + typedef struct Subclass : public Class\ + { + +#define AM_SUBCLASS_CONSTR(Subclass, Class) \ + Subclass():Class() + +#define AM_SUBCLASS_CONSTR_BODY()\ + {}; + +#define AM_SUBCLASS_COPY_OP_START(Subclass, Class) \ + Subclass & operator=(const Subclass & anObject)\ + {\ + if (this != &anObject)\ + {\ + Class::operator=(anObject); + +#define AM_SUBCLASS_COPY_OP_END()\ + }\ + return *this;\ + }; + +#define AM_SUBCLASS_OP(Subclass, Class) \ + Subclass & operator=(const Class & anObject)\ + {\ + if (this != &anObject)\ + Class::operator=(anObject);\ + return *this;\ + }; + +#define AM_SUBCLASS_END(Typedef) \ + void getDescription (std::string & outString) const;\ + } Typedef; + +#define AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(Subclass, Class)\ + AM_SUBCLASS_BEGIN(Subclass, Class)\ + bool reserved;\ + AM_SUBCLASS_CONSTR(Subclass, Class)\ + ,reserved(false)\ + AM_SUBCLASS_CONSTR_BODY()\ + AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ + reserved = anObject.reserved;\ + AM_SUBCLASS_COPY_OP_END()\ + AM_SUBCLASS_OP(Subclass, Class)\ + +#define AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(Subclass, Class)\ + AM_SUBCLASS_BEGIN(Subclass, Class)\ + bool reserved;\ + std::unordered_map cacheSoundProperties;\ + std::unordered_map cacheMainSoundProperties;\ + AM_SUBCLASS_CONSTR(Subclass, Class)\ + ,reserved(false), cacheSoundProperties(), cacheMainSoundProperties()\ + AM_SUBCLASS_CONSTR_BODY()\ + AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ + reserved = anObject.reserved;\ + cacheSoundProperties = anObject.cacheSoundProperties;\ + cacheMainSoundProperties = anObject.cacheMainSoundProperties;\ + AM_SUBCLASS_COPY_OP_END()\ + AM_SUBCLASS_OP(Subclass, Class)\ + +#define AM_TYPEDEF_SUBCLASS_BEGIN(Subclass, Class)\ + AM_SUBCLASS_BEGIN(Subclass, Class)\ + AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ + AM_SUBCLASS_COPY_OP_END()\ + AM_SUBCLASS_OP(Subclass, Class)\ + + + AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Domain_Database_s,am_Domain_s) + AM_SUBCLASS_END(CAmDomain) + + AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Sink_Database_s,am_Sink_s) + void getSinkType(am_SinkType_s & sinkType) const;\ + AM_SUBCLASS_END(CAmSink) + + AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Source_Database_s,am_Source_s) + void getSourceType(am_SourceType_s & sourceType) const;\ + AM_SUBCLASS_END(CAmSource) + + AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Connection_Database_s,am_Connection_s) + AM_SUBCLASS_END(CAmConnection) + + /** + * The following structures extend the base structures with print capabilities. + */ + AM_TYPEDEF_SUBCLASS_BEGIN(am_MainConnection_Database_s, am_MainConnection_s) + void getMainConnectionType(am_MainConnectionType_s & connectionType) const;\ + AM_SUBCLASS_END(CAmMainConnection) + + AM_TYPEDEF_SUBCLASS_BEGIN(am_SourceClass_Database_s, am_SourceClass_s) + AM_SUBCLASS_END(CAmSourceClass) + + AM_TYPEDEF_SUBCLASS_BEGIN(am_SinkClass_Database_s, am_SinkClass_s) + AM_SUBCLASS_END(CAmSinkClass) + + AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s) + AM_SUBCLASS_END(CAmGateway) + + AM_TYPEDEF_SUBCLASS_BEGIN(am_Converter_Database_s, am_Converter_s) + AM_SUBCLASS_END(CAmConverter) + + AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s) + AM_SUBCLASS_END(CAmCrossfader) + + private: + typedef std::unordered_map CAmMapDomain; + typedef std::unordered_map CAmMapSourceClass; + typedef std::unordered_map CAmMapSinkClass; + typedef std::unordered_map CAmMapSink; + typedef std::unordered_map CAmMapSource; + typedef std::unordered_map CAmMapGateway; + typedef std::unordered_map CAmMapConverter; + typedef std::unordered_map CAmMapCrossfader; + typedef std::unordered_map CAmMapConnection; + typedef std::unordered_map CAmMapMainConnection; + typedef std::vector CAmVectorSystemProperties; + /** + * The following structure groups the map objects needed for the implementation. + * Every map object is coupled with an identifier, which hold the current value. + * DYNAMIC_ID_BOUNDARY is used as initial value everywhere a dynamic id is considered . + * The IDs can be increased through the method increaseID(...), which follows the AudioManager logic. + * For more information about the static and dynamic IDs, please see the documentation. + */ + typedef struct CAmMappedData + { + /** + * The structure encapsulates the id boundary and the current id value. + * It defines a range within the id can vary. + */ + struct am_Identifier_s + { + int16_t mMin; //!< min possible value + int16_t mMax; //!< max possible value + int16_t mCurrentValue; //!< current value + + am_Identifier_s():mMin(DYNAMIC_ID_BOUNDARY), mMax(SHRT_MAX), mCurrentValue(mMin){}; + am_Identifier_s(const int16_t & min, const int16_t & max):mMin(min), mMax(max), mCurrentValue(mMin){assert(min static void print (const TPrintObject & t, std::ostream & output) + { + std::string description; + t.getDescription( description ); + output << description; + } + template static void printMap (const std::unordered_map & t, std::ostream & output) + { + typename std::unordered_map::const_iterator iter = t.begin(); + for(; iter!=t.end(); iter++) + CAmMappedData::print(iter->second, output); + } + private: + template bool getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, + const std::unordered_map & map); + } CAmMappedData; + /* + * Helper methods. + */ + am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; //!< calculates a new main connection delay + int16_t calculateDelayForRoute(const std::vector& listConnectionID); + bool insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID); + bool insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID); + bool insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID); + bool insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID); + bool insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID); + bool insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID); + bool insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass); + const am_Sink_Database_s * sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const; + const am_Source_Database_s * sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const; + template bool isConnected(const Component & comp) const + { + return std::find_if(mMappedData.mConnectionMap.begin(), mMappedData.mConnectionMap.end(),[&](const std::pair& rConnection){ + return (rConnection.second.sinkID == comp.sinkID ||rConnection.second.sourceID ==comp.sourceID);})!=mMappedData.mConnectionMap.end(); + } + void filterDuplicateNotificationConfigurationTypes(std::vector & list) + { + std::vector oldList(list); + list.clear(); + std::for_each(oldList.begin(), oldList.end(), [&](am_NotificationConfiguration_s & provided) { + std::vector::iterator found = + std::find_if(list.begin(), list.end(), [&](am_NotificationConfiguration_s & stored) { + if (provided.type == stored.type) { + stored = provided; + return true; + } + return false; + } ); + if (found == list.end()) + list.push_back(provided); + } ); + } + + CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer + ListConnectionFormat mListConnectionFormat; //!< list of connection formats + CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class +#ifdef UNIT_TEST + public: + void setConnectionIDRange(const int16_t & min, const int16_t & max) + { + mMappedData.mCurrentConnectionID.mMin = min; + mMappedData.mCurrentConnectionID.mMax = max; + } + void setMainConnectionIDRange(const int16_t & min, const int16_t & max) + { + mMappedData.mCurrentMainConnectionID.mMin = min; + mMappedData.mCurrentMainConnectionID.mMax = max; + } + void setSinkIDRange(const int16_t & min, const int16_t & max) + { + mMappedData.mCurrentSinkID.mMin = min; + mMappedData.mCurrentSinkID.mMax = max; + } +#endif +}; + +} + +#endif /* MAPHANDLER_H_ */ diff --git a/AudioManagerCore/include/CAmDatabaseObserver.h b/AudioManagerCore/include/CAmDatabaseObserver.h new file mode 100644 index 0000000..7d18be4 --- /dev/null +++ b/AudioManagerCore/include/CAmDatabaseObserver.h @@ -0,0 +1,87 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmDatabaseObserver.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef DATABASEOBSERVER_H_ +#define DATABASEOBSERVER_H_ + +#include "audiomanagertypes.h" +#include +#include "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 newConverter(const am_Converter_s& coverter); + 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 removeConverter(const am_converterID_t converterID); + 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); + void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible); + void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible); + void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); + void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); + +private: + CAmCommandSender *mCommandSender; //!< pointer to the comandSender + CAmRoutingSender* mRoutingSender; //!< pointer to the routingSender + CAmTelnetServer* mTelnetServer; //!< pointer to the telnetserver + CAmSerializer mSerializer; //!< serializer to handle the CommandInterface via the mainloop +}; + +} + +#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerCore/include/CAmGraph.h b/AudioManagerCore/include/CAmGraph.h new file mode 100644 index 0000000..ff4a09c --- /dev/null +++ b/AudioManagerCore/include/CAmGraph.h @@ -0,0 +1,630 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2014 + * + * \file CAmGraph.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef GRAPH_H +#define GRAPH_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace am +{ + /** + * Graph element status. + */ + typedef enum:uint8_t + { + GES_NOT_VISITED, + GES_IN_PROGRESS, + GES_VISITED + }am_GraphElementStatus_e; + + /** + * Callback parameter telling on which position in the path we are. + */ + typedef enum:uint8_t + { + GRAPH_PATH_START, //at the beginning of the path + GRAPH_PATH_MIDDLE, //in middle of the path + GRAPH_PATH_END //at the end of the path + }am_GraphPathPosition_e; + + + /** + * This class is base class for nodes and vertices. + */ + class CAmGraphElement + { + am_GraphElementStatus_e mStatus; //!< item status + public: + CAmGraphElement(): mStatus(GES_NOT_VISITED) { }; + ~CAmGraphElement() { }; + /** + * Setter and getter. + */ + void setStatus(const am_GraphElementStatus_e s) { mStatus = s; }; + am_GraphElementStatus_e getStatus() const { return mStatus; }; + }; + + template class CAmNode : public CAmGraphElement + { + uint16_t mIndex; //!< uint16_t index used for direct access + NodeData mData; //!< NodeData user data + public: + CAmNode(const NodeData & in):CAmGraphElement(), mIndex(0), mData(in) { }; + CAmNode(const NodeData & in, const uint16_t index):CAmGraphElement(), mIndex(index), mData(in) { }; + ~CAmNode() { }; + /** + * Setters and getters. + */ + NodeData & getData() { return mData; } + uint16_t getIndex() const { return mIndex; } + void setIndex(uint16_t index) { mIndex = index; } + }; + + template class CAmVertex : public CAmGraphElement + { + CAmNode* mpNode; //!< CAmNode* pointer to a node + VertexData mVertexData; //!< VertexData vertex user data + uint16_t mWeight; //!< uint16_t a positive value used in the shortest path algorithms + public: + CAmVertex(CAmNode *aNode, const VertexData & vertexData, const uint16_t weight):CAmGraphElement(), + mpNode(aNode), mVertexData(vertexData), mWeight(weight) { }; + ~CAmVertex() { }; + /** + * Setters and getters. + */ + CAmNode* getNode() const { return mpNode; } + VertexData & getData() { return mVertexData; } + uint16_t getWeight() const { return mWeight; } + void setWeight(const uint16_t weight) { mWeight=weight; } + }; + + /** + * Class representing a directed or undirected graph. It contains nodes and connections. + * T, V are types for custom user data. + */ + template class CAmGraph + { + typedef typename std::vector*> CAmListNodePtrs; + typedef typename std::list> CAmListVertices; + typedef typename std::list>::iterator CAmListVerticesItr; + typedef typename std::list>::const_iterator CAmListVerticesItrConst; + typedef typename std::list CAmNodesAdjList; + typedef typename std::list::iterator CAmNodesAdjListItr; + typedef typename std::list::const_iterator CAmNodesAdjListItrConst; + typedef typename std::list> CAmListNodes; + typedef typename std::list>::iterator CAmListNodesItr; + typedef typename std::list>::const_iterator CAmListNodesItrConst; + typedef typename std::vector*> CAmNodeReferenceList; + typedef typename std::vector CAmVertexReferenceList; + + CAmListNodes mStoreNodes; //!< CAmListNodes list with all nodes + CAmNodesAdjList mStoreAdjList; //!< CAmNodesAdjList adjacency list + CAmNodeReferenceList mPointersNodes; //!< CAmNodeReferenceList vector with pointers to nodes for direct access + CAmVertexReferenceList mPointersAdjList; //!< CAmVertexReferenceList vector with pointers to vertices for direct access + bool mIsCyclic; //!< bool the graph has cycles or not + + /** + * Updates the node indexes after adding or removing nodes. + * + * @param fromIndex updates all nodes from given index. + */ + void updateIndexes(const int16_t fromIndex) + { + if( fromIndexsetIndex(iter-mPointersNodes.begin()); + } + } + + + /** + * Finds the shortest path and the minimal weights from given node. + * + * @param node start node. + * @param minDistance vector with all result distances. + * @param previous vector with previous nodes. + */ + + typedef uint16_t vertex_t; + typedef uint16_t weight_t; + + void findShortestsPathsFromNode(const CAmNode & node, std::vector &minDistance, std::vector *> &previous) + { + typename CAmListVertices::const_iterator nIter; + CAmListVertices * neighbors; + weight_t dist, weight, v, distanceThroughU; + CAmNode* pU; + CAmVertex * pVertex; + CAmNode *pDstNode; + + size_t n = mPointersAdjList.size(); + std::set*> > vertexQueue; + + minDistance.clear(); + minDistance.resize(n, std::numeric_limits::max()); + minDistance[node.getIndex()] = 0; + previous.clear(); + previous.resize(n, NULL); + + vertexQueue.insert(std::make_pair(minDistance[node.getIndex()], (CAmNode*)&node)); + + while (!vertexQueue.empty()) + { + dist = vertexQueue.begin()->first; + pU = vertexQueue.begin()->second; + vertexQueue.erase(vertexQueue.begin()); + //todo: terminate the search at this position if you want the path to a target node ( if(pU==target)break; ) + + // Visit each edge exiting u + neighbors = mPointersAdjList[pU->getIndex()]; + nIter = neighbors->begin(); + for (; nIter != neighbors->end(); nIter++) + { + pVertex = (CAmVertex *)&(*nIter); + pDstNode = pVertex->getNode(); + + v = pDstNode->getIndex(); + weight = pVertex->getWeight(); + distanceThroughU = dist + weight; + if (distanceThroughU < minDistance[pDstNode->getIndex()]) + { + vertexQueue.erase(std::make_pair(minDistance[v], pDstNode)); + minDistance[v] = distanceThroughU; + previous[v] = pU; + vertexQueue.insert(std::make_pair(minDistance[v], pDstNode)); + } + } + } + } + + /** + * Constructs a path to given node after findShortestsPathsFromNode has been called. + * + * @param node end node. + * @param previous vector with previous nodes. + * @param result result path. + */ + void constructShortestPathTo(const CAmNode & node, const std::vector *> &previous, CAmListNodePtrs & result) + { + CAmNode * vertex = (CAmNode *)&node; + + int i=0; + while ( (vertex = previous[vertex->getIndex()])!=NULL ) + { + result.insert(result.begin(), vertex); + i++; + } + if(i) + result.push_back((CAmNode *)&node); + } + + /** + * Calls a function with every node from this path after findShortestsPathsFromNode has been called. + * The construction of the path is delegated to the caller. + * + * @param node end node. + * @param previous vector with previous nodes. + * @param cb callback which is mostly used for constructing. + */ + void constructShortestPathTo(const CAmNode & node, const std::vector *> &previous, std::function &)> cb) + { + CAmNode * vertex = (CAmNode *)&node; + CAmNode * prev = vertex; + int i=0; + while ( (vertex = previous[vertex->getIndex()])!=NULL ) + { + cb(i==0?GRAPH_PATH_START:GRAPH_PATH_MIDDLE, *prev); + prev = vertex; + i++; + } + if(i) + cb(GRAPH_PATH_END, *prev); + } + + /** + * Generates list with all possible paths to given destination node after findShortestsPathsFromNode has been called. + * Finding paths is observed through the callback. The caller is informed after a new path has been found. + * + * @param dst end node. + * @param visited vector with current path. + * @param cb callback which is mostly used for constructing. + */ + void goThroughAllPaths(const CAmNode & dst, std::vector*> & visited, std::function cb) + { + CAmListVertices * nodes = mPointersAdjList[visited.back()->getIndex()]; + CAmListVerticesItrConst vItr(nodes->begin()); + for (; vItr != nodes->end(); ++vItr) + { + const CAmVertex & vertex = (*vItr); + if(vertex.getNode()->getStatus()!=GES_NOT_VISITED) + continue; + if (vertex.getNode()==&dst) + { + vertex.getNode()->setStatus(GES_IN_PROGRESS); + visited.push_back(vertex.getNode()); + //notify observer + cb(visited); + //remove last node from the list + auto last = visited.end()-1; + visited.erase(last); + vertex.getNode()->setStatus(GES_NOT_VISITED); + break; + } + } + vItr = nodes->begin(); + //bfs like loop + for (; vItr != nodes->end(); ++vItr) + { + const CAmVertex & vertex = (*vItr); + if(vertex.getNode()->getStatus()!=GES_NOT_VISITED||vertex.getNode()==&dst) + continue; + vertex.getNode()->setStatus(GES_IN_PROGRESS); + visited.push_back(vertex.getNode()); + goThroughAllPaths(dst, visited, cb); + //remove last node from the list + auto last = visited.end()-1; + visited.erase(last); + vertex.getNode()->setStatus(GES_NOT_VISITED); + } + } + + public: + explicit CAmGraph(const std::vector &v):mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList() + { + typedef typename std::vector::const_iterator inItr; + inItr itr(v.begin()); + + for (; itr != v.end(); ++itr) + { + addNode(*itr); + } + + mIsCyclic = false; + }; + CAmGraph():mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList(), mIsCyclic(false){}; + ~CAmGraph(){} + + const CAmListNodes & getNodes() const + { + return mStoreNodes; + } + + const CAmVertexReferenceList & getVertexList() const + { + return mPointersAdjList; + } + + /** + * Returns pointer to a node which data is equal to the given. + * @return pointer to a node or NULL. + */ + const CAmNode* findNode(const T & in) + { + typename CAmNodeReferenceList::const_iterator itr (mPointersNodes.begin()); + + for (; itr != mPointersNodes.end(); ++itr) + { + if ((*itr)->getData() == in) { + return (*itr); + } + } + return NULL; + } + + /** + * Returns pointer to a vertex which two ends are equal to the given nodes. + * @return pointer to a vertex or NULL. + */ + const CAmVertex* findVertex(const CAmNode & edge1, const CAmNode & edge2) const + { + const CAmNode * pEdge2 = (CAmNode *)&edge2; + const CAmListVertices * list = mPointersAdjList[edge1.getIndex()]; + CAmListVerticesItrConst result = std::find_if(list->begin(), list->end(), [&](const CAmVertex & refObject){ + return refObject.getNode()==pEdge2; + }); + if(result!=list->end()) + return (CAmVertex*)&(*result); + + return NULL; + } + + bool hasCycles() const + { + return mIsCyclic; + } + + + /** + * Adds a new node to the graph with given user data. + * @return reference to the newly inserted node. + */ + CAmNode & addNode(const T & in) + { + size_t index = mStoreNodes.size(); + mStoreNodes.emplace_back(in, index); + mStoreAdjList.emplace_back(); + mPointersNodes.push_back(&mStoreNodes.back()); + mPointersAdjList.push_back(&mStoreAdjList.back()); + return mStoreNodes.back(); + } + + /** + * Removes a vertex with two ends equal to the given nodes . + */ + void removeVertex(const CAmNode & edge1, const CAmNode & edge2) + { + const CAmListVertices * list = mPointersAdjList[edge1.getIndex()]; + CAmListVerticesItr iter = std::find_if(list->begin(), list->end(), [&edge2](const CAmVertex & refVertex){ + return (refVertex.getNode()==&edge2); + }); + if(iter!=list->end()) + list->erase(iter); + } + + /** + * Removes all vertices to given node . + */ + void removeAllVerticesToNode(const CAmNode & node) + { + auto comparator = [&node](const CAmVertex & refVertex){ + return (refVertex.getNode()==&node); + }; + auto itr = mPointersAdjList.begin(); + for(;itr!=mPointersAdjList.end();itr++) + { + CAmListVertices * vertices = *itr; + auto iterVert = std::find_if(vertices->begin(), vertices->end(), comparator); + if(iterVert!=vertices->end()) + vertices->erase(iterVert); + } + } + + /** + * Removes a node with given user data . + */ + void removeNode(const T & in) + { + CAmNode * node = findNode(in); + if(node!=NULL) + removeNode(*node); + } + + /** + * Removes the given node from the graph . + */ + void removeNode(const CAmNode & node) + { + uint16_t index = node.getIndex(); + removeAllVerticesToNode(node); + mPointersAdjList.erase(mPointersAdjList.begin()+index); + mPointersNodes.erase(mPointersNodes.begin()+index); + auto iter = std::find_if(mStoreNodes.begin(), mStoreNodes.end(), [&node](const CAmNode & otherNode){ + return &otherNode==&node; + }); + if(iter!=mStoreNodes.end()) + mStoreNodes.erase(iter); + updateIndexes(index); + } + + /** + * Connect first with last node and set user data and weight to the vertex. + */ + void connectNodes(const CAmNode & first, const CAmNode & last, const V & vertexData, const int16_t weight = 1) + { + CAmListVertices * list = mPointersAdjList[first.getIndex()]; + CAmNode * node = mPointersNodes[last.getIndex()]; + list->emplace_back(node, vertexData, weight); + } + + /** + * Exists any vertex with two given ends. + * @return TRUE on successfully changed ID. + */ + bool isAnyVertex(const CAmNode & edge1, const CAmNode & edge2) const + { + return findVertex(edge1, edge2)!=NULL; + } + + /** + * Sets the status of all nodes and vertices to GES_NOT_VISITED. + */ + void reset() + { + // set all nodes to GES_NOT_VISITED + std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [](CAmNode * refNode){ + if(refNode->getStatus()!= GES_NOT_VISITED) + refNode->setStatus(GES_NOT_VISITED); + }); + // set all vertices to GES_NOT_VISITED + auto action = [](CAmVertex & refVertex){ + if(refVertex.getStatus()!= GES_NOT_VISITED) + refVertex.setStatus(GES_NOT_VISITED); + }; + auto itr1(mPointersAdjList.begin()); + for (; itr1 != mPointersAdjList.end(); ++itr1) + { + CAmListVertices * vertices = *itr1; + std::for_each(vertices->begin(), vertices->end(), action); + } + } + + /** + * Clears all nodes and vertices. + */ + void clear() + { + mStoreNodes.clear(); + mStoreAdjList.clear(); + mPointersAdjList.clear(); + mPointersNodes.clear(); + mPointersAdjList.clear(); + } + + /** + * Goes through all nodes and vertices and calls the callback. + */ + void trace(std::function &, const std::vector*> &)> cb) + { + std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [&](CAmNode * refNode){ + CAmListVertices * vertices = this->mPointersAdjList[refNode->getIndex()]; + std::vector*> list; + std::for_each(vertices->begin(), vertices->end(), [&list](CAmVertex & refVertex){ + list.push_back(&refVertex); + }); + cb(*refNode, list); + }); + } + + /** + * Finds the shortest path from given node to all nodes in listTargets. + * + * @param source start node. + * @param listTargets destination nodes. + * @param resultPath list with all shortest paths. + */ + void getShortestPath(const CAmNode & source, const CAmListNodePtrs & listTargets, std::vector & resultPath ) + { + const size_t numberOfNodes = mPointersNodes.size(); + if(numberOfNodes==0) + return; + + std::vector min_distance; + std::vector*> previous; + findShortestsPathsFromNode(source, min_distance, previous); + + for(auto it=listTargets.begin(); it!=listTargets.end(); it++) + { + CAmNode *node = *it; + resultPath.emplace_back(); + CAmListNodePtrs & path = resultPath.back(); + constructShortestPathTo(*node, previous, path); + if(path.empty()) + { + typename std::vector::iterator iter = resultPath.end(); + resultPath.erase(--iter); + } + } + } + + /** + * Finds the shortest path between two nodes. + * + * @param source start node. + * @param destination destination node. + * @param resultPath list with the found shortest paths. + */ + void getShortestPath(const CAmNode & source, const CAmNode & destination, CAmListNodePtrs & resultPath ) + { + const size_t numberOfNodes = mPointersNodes.size(); + if(numberOfNodes==0) + return; + std::vector min_distance; + std::vector*> previous; + findShortestsPathsFromNode(source, min_distance, previous); + constructShortestPathTo(destination, previous, resultPath); + } + + /** + * Finds the shortest path from given node to all nodes in listTargets. + * Delegates the construction of the path to the caller. + * + * @param source start node. + * @param listTargets destination nodes. + * @param cb callabck. + */ + void getShortestPath(const CAmNode & source, + const CAmListNodePtrs & listTargets, + std::function &)> cb ) + { + const size_t numberOfNodes = mPointersNodes.size(); + if(numberOfNodes==0) + return; + + std::vector min_distance; + std::vector*> previous; + findShortestsPathsFromNode(source, min_distance, previous); + + for(auto it=listTargets.begin(); it!=listTargets.end(); it++) + { + CAmNode* node = *it; + constructShortestPathTo(*node, previous, cb); + } + } + + /** + * Finds the shortest path between two given nodes. + * Delegates the construction of the path to the caller. + * + * @param source start node. + * @param destination destination node. + * @param cb callabck. + */ + void getShortestPath(const CAmNode & source, + const CAmNode & destination, + std::function &)> cb ) + { + const size_t numberOfNodes = mPointersNodes.size(); + if(numberOfNodes==0) + return; + + std::vector min_distance; + std::vector*> previous; + findShortestsPathsFromNode(source, min_distance, previous); + constructShortestPathTo(destination, previous, cb); + } + + /** + * Finds all possible paths between two given nodes. + * Delegates the construction of the path to the caller. + * + * @param src start node. + * @param dst destination node. + * @param cb callabck. + */ + void getAllPaths(const CAmNode & src, const CAmNode & dst, std::function cb) + { + CAmNodeReferenceList visited; + visited.push_back((CAmNode*)&src); + ((CAmNode*)&src)->setStatus(GES_VISITED); + goThroughAllPaths(dst, visited, cb); + reset(); + } + }; + +} + +#endif diff --git a/AudioManagerCore/include/CAmLog.h b/AudioManagerCore/include/CAmLog.h new file mode 100644 index 0000000..35c6a41 --- /dev/null +++ b/AudioManagerCore/include/CAmLog.h @@ -0,0 +1,129 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmLog.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CAMLOG_H_ +#define CAMLOG_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * Implements a basic logging mechanism that can be used to print debug information into a file or to the console. + * It can be used either as singleton through the appropriate method getDefaultLog() or as independent instantiated object. + * The default initializer sets the console as output for newly created objects. + * Example: CAmLogger << "Text"; //to print out through the singleton object directly to the console + */ + +#define DEFAULT_LOG_FOLDER "/tmp/" +#define DEFAULT_LOGFILE_PREFIX "am_dump_" +#define DEFAULT_LOGFILE_EXT ".log" + +#define DEL( aPointer ) delete aPointer, aPointer = NULL; + +/* */ +typedef enum { eCAmLogNone = 0, eCAmLogStdout = 1, eCAmLogFile = 2 } eCAmLogType; + +class CAmLog +{ +private: + /** + * Private classes which usually own (wrap) a stream object. They are responsible for creating and deleting it. + */ + class CAmLogger + { + protected: + std::ostream* mOutputStream; + public: + CAmLogger ():mOutputStream(NULL) {}; + virtual ~CAmLogger () { }; + virtual void log(const std::string& _s) + { + (*mOutputStream) << _s; + mOutputStream->flush(); + } + template + CAmLogger & operator << (const T & t) + { + (*mOutputStream) << t; + return (*this); + } + }; + + class CAmFileLogger : public CAmLogger + { + std::string mFilename; + public: + static void generateLogFilename(std::string &result); + explicit CAmFileLogger(const std::string& _s) : CAmLogger() + { + mFilename = _s; + mOutputStream = new std::ofstream(mFilename.c_str()); + } + ~CAmFileLogger(); + }; + + class CAmStdOutLogger : public CAmLogger + { + public: + CAmStdOutLogger() + { + mOutputStream = &std::cout; + } + }; + +private: + eCAmLogType mLogType; + CAmLogger* mLogger; + +protected: + void releaseLogger(); + void instantiateLogger( const eCAmLogType type); +public: + CAmLog(const eCAmLogType type ); + CAmLog(); + ~CAmLog(); + + static CAmLog *getDefaultLog(); + + void setLogType( const eCAmLogType type); + eCAmLogType getLogType() const; + + template + CAmLog & operator << (const T & t) + { + assert(mLogger!=NULL); + (*mLogger) << t; + return (*this); + } + }; + +#define CAmLogger (*CAmLog::getDefaultLog()) + + +#endif /* CAMLOG_H_ */ diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h new file mode 100644 index 0000000..fe41049 --- /dev/null +++ b/AudioManagerCore/include/CAmRouter.h @@ -0,0 +1,317 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014 + * + * \file CAmRouter.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTER_H_ +#define ROUTER_H_ + +#include +#include +#include +#include "audiomanagertypes.h" +#include "CAmGraph.h" +#include "IAmDatabaseHandler.h" + + +namespace am +{ +/** + * Optimal path search between a source and a sink is implemented with a graph which contains nodes - sinks, sources, gateways, converters. + * The nodes are identified by sinkID, sourceID, gatewayID, converterID. + * A possible connection between two nodes represents the facts that the nodes can be connected with one or more connectionFormats (Node[id=1] ---> Node[id=2]). + * It is assumption that the two nodes can be connected. The controller itself decides later whether the connection is possible or not. + * + */ + +/** + * Trace on/off. + */ +#if !defined(ROUTING_BUILD_CONNECTIONS) + #undef TRACE_GRAPH +#endif + +/** + * Default behavior is to do the search in one step without connections, which are identified during the search. + * Alternatively the search can be done in two steps. + */ +#if !defined(ROUTING_BUILD_CONNECTIONS) + #undef ROUTING_BUILD_CONNECTIONS +#endif + +#if defined(TRACE_GRAPH) +#if !defined(ROUTING_BUILD_CONNECTIONS) +#warning "You should define ROUTING_BUILD_CONNECTIONS in order to be able to see the connections in the trace." +#endif +#endif + +class CAmRouter; + +/** + * A structure used as user data in the graph nodes. + */ +struct am_RoutingNodeData_s +{ + typedef enum:uint8_t {SINK, SOURCE, GATEWAY, CONVERTER} am_NodeDataType_e; + am_NodeDataType_e type; //!< data type:sink, source, gateway or converter + union + { + am_Source_s *source; + am_Sink_s *sink; + am_Gateway_s *gateway; + am_Converter_s *converter; + } data; //!< union pointer to sink, source, gateway or converter + + am_RoutingNodeData_s():type(SINK) + {} + + bool operator==(const am_RoutingNodeData_s & anotherObject) const + { + bool result = false; + if(type==anotherObject.type) + { + result = true; + if(type==SINK) + result &= (data.sink->sinkID==anotherObject.data.sink->sinkID); + else if(type==SOURCE) + result &= (data.source->sourceID==anotherObject.data.source->sourceID); + else if(type==GATEWAY) + result &= (data.gateway->gatewayID==anotherObject.data.gateway->gatewayID); + else if(type==CONVERTER) + result &= (data.converter->converterID==anotherObject.data.converter->converterID); + } + return result; + }; + +#ifdef TRACE_GRAPH + void trace() const + { + if(type==SINK) + std::cout << "[SINK:" << data.sink->sinkID << ":" << data.sink->name << "(" << data.sink->domainID << ")" + << "]"; + else if(type==SOURCE) + std::cout << "[SOUR:" << data.source->sourceID << ":" << data.source->name << "(" << data.source->domainID << ")" + << "]"; + else if(type==GATEWAY) + std::cout << "[GATE:" << data.gateway->gatewayID << ":" << data.gateway->name << "(" << data.gateway->controlDomainID << ")" + << "]"; + else if(type==CONVERTER) + std::cout << "[CONV:" << data.converter->converterID << ":" << data.converter->name << "(" << data.converter->domainID << ")" + << "]"; + }; +#endif + + am_domainID_t domainID() const + { + if(type==SINK) + return data.sink->domainID; + else if(type==SOURCE) + return data.source->domainID; + else if(type==GATEWAY) + return data.gateway->controlDomainID; + else if(type==CONVERTER) + return data.converter->domainID; + return 0; + }; +}; + +typedef am_RoutingNodeData_s::am_NodeDataType_e CAmNodeDataType; +typedef CAmNode CAmRoutingNode; +typedef CAmGraph CAmRoutingGraph; +typedef CAmVertex CAmRoutingVertex; +typedef std::list CAmRoutingListVertices; +typedef std::vector CAmRoutingVertexReferenceList; + +class CAmControlSender; + + +/** + * Implements an autorouting algorithm for connecting sinks and sources via different audio domains. + */ +class CAmRouter +{ + IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler + CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route + bool mOnlyFreeConversionNodes; //!< bool flag whether only disconnected elements should be considered or not + CAmRoutingGraph mRoutingGraph; //!< graph object + std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access + std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access + std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access + std::map> mNodeListConverters;//!< map with pointers to nodes with converters, used for quick access + + am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes); + am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, + std::vector & route, + std::vector::iterator routingElementIterator, + std::vector::iterator routeIterator); + + + /** + * Check whether given converter or gateway has been connected. + * + * @param comp converter or gateway . + */ + template bool isComponentConnected(const Component & comp) + { + return mpDatabaseHandler->isComponentConnected(comp); + } + void generateAllPaths(const CAmRoutingNode & src, + const CAmRoutingNode & dst, + const bool includeCycles, + std::function & path)> cb); + void goThroughAllPaths(const CAmRoutingNode & dst, + std::vector & visited, + std::vector & visitedDomains, + std::function & path)> cb); + +#ifdef ROUTING_BUILD_CONNECTIONS + /** + * Connects all converters to its sink and sources if possible. + * + */ + void constructConverterConnections(); + + /** + * Connects all gateways to its sink and sources if possible. + * + */ + void constructGatewayConnections(); + + /** + * Connects all sources to the sinks if possible. + * + */ + void constructSourceSinkConnections(); +#else + /** + * Construct a list with all vertices + */ + void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct a list with all vertices from given source. + */ + void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct a list with all vertices from given sink. + */ + void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct a list with all vertices from given converter. + */ + void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct a list with all vertices from given gateway. + */ + void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list); +#endif + +public: + CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); + ~CAmRouter(); + + /** + * Finds all possible paths between given source and sink. + * + * @param onlyfree only disconnected elements should be included or not. + * @param sourceID starting point. + * @param sinkID ending point. + * @param returnList list with all possible paths + * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + */ + am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); + am_Error_e getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); + + am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, + std::vector & resultPath, std::vector> & resultNodesPath, +#if !defined(ROUTING_BUILD_CONNECTIONS) + __attribute__((unused)) +#endif + const bool includeCycles = false); +#ifdef ROUTING_BUILD_CONNECTIONS + void getShortestPath(const CAmRoutingNode & source, const CAmRoutingNode & destination, std::vector & resultPath); + void getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & resultPath, std::vector & resultNodesPath); +#endif + + static bool getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, + const std::vector & listSourceFormats, + const std::vector & listSinkFormats, + std::vector & sourceFormats, + std::vector & sinkFormats); + static void listPossibleConnectionFormats(std::vector & inListSourceFormats, + std::vector & inListSinkFormats, + std::vector & outListFormats); + static bool getRestrictedOutputFormats(const std::vector & convertionMatrix, + const std::vector & listSourceFormats, + const std::vector & listSinkFormats, + const am_CustomConnectionFormat_t connectionFormat, + std::vector & listFormats); + static void getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, + std::vector::iterator iteratorSink, + std::vector & outConnectionFormats); + + static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); + + /** + * Returns a sink node with given sinkID. + * + * @param sinkID sink id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID); + CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID); + + /** + * Returns a source node with given sourceID. + * + * @param sourceID source id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID); + CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID); + + /** + * Returns a converter node for given sinkID. + * + * @param sinkID sink id. + * @param domainID domain id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID); + + /** + * Returns a gateway node for given sinkID. + * + * @param sinkID sink id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* gatewayNodeWithSinkID(const am_sinkID_t sinkID); + + void load(const bool onlyFree); + void clear(); +}; +} /* namespace am */ +#endif /* ROUTER_H_ */ + diff --git a/AudioManagerCore/include/CAmRoutingReceiver.h b/AudioManagerCore/include/CAmRoutingReceiver.h new file mode 100644 index 0000000..82626c6 --- /dev/null +++ b/AudioManagerCore/include/CAmRoutingReceiver.h @@ -0,0 +1,127 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmRoutingReceiver.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGRECEIVER_H_ +#define ROUTINGRECEIVER_H_ + +#include "IAmRouting.h" + +namespace am +{ + +class CAmSocketHandler; +class CAmDbusWrapper; +class IAmDatabaseHandler; +class CAmRoutingSender; +class CAmControlSender; + +/** + * Implements the Receiving side of the RoutingPlugins. + */ +class CAmRoutingReceiver: public IAmRoutingReceive +{ +public: + CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler); + CAmRoutingReceiver(IAmDatabaseHandler *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 registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID); + am_Error_e deregisterGateway(const am_gatewayID_t gatewayID); + am_Error_e deregisterConverter(const am_converterID_t converterID); + 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, const am_Error_e error); + void confirmRoutingRundown(const uint16_t handle, const am_Error_e error); + am_Error_e updateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) ; + am_Error_e updateConverter(const am_converterID_t converterID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix); + am_Error_e updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + am_Error_e updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; + void ackSetVolumes(const am_Handle_s handle, const std::vector& listvolumes, const am_Error_e error) ; + void ackSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; + void ackSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; + void hookSinkNotificationDataChange(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) ; + void hookSourceNotificationDataChange(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) ; + am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const; + am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const; + am_Error_e getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const; + + 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: + IAmDatabaseHandler *mpDatabaseHandler; //!< pointer to the databaseHandler + CAmRoutingSender *mpRoutingSender; //!< pointer to the routingSender + CAmControlSender *mpControlSender; //!< pointer to the controlSender + CAmSocketHandler *mpSocketHandler; //!< pointer to sockethandler + CAmDbusWrapper *mpDBusWrapper; //!< pointer to dbuswrapper + + std::vector mListStartupHandles; //!< list of handles that wait for a confirm + std::vector mListRundownHandles; //!< list of handles that wait for a confirm + uint16_t handleCount; //!< counts all handles + 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 + + am_Error_e mLastStartupError; + am_Error_e mLastRundownError; + +}; + +} + +#endif /* ROUTINGRECEIVER_H_ */ diff --git a/AudioManagerCore/include/CAmRoutingSender.h b/AudioManagerCore/include/CAmRoutingSender.h new file mode 100644 index 0000000..4a23428 --- /dev/null +++ b/AudioManagerCore/include/CAmRoutingSender.h @@ -0,0 +1,155 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmRoutingSender.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGSENDER_H_ +#define ROUTINGSENDER_H_ + +#include "IAmRouting.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(); + + am_Error_e removeHandle(const am_Handle_s& handle); + am_Error_e addDomainLookup(const am_Domain_s& domainData); + am_Error_e addSourceLookup(const am_Source_s& sourceData); + am_Error_e addSinkLookup(const am_Sink_s& sinkData); + am_Error_e addCrossfaderLookup(const am_Crossfader_s& crossfaderData); + am_Error_e removeDomainLookup(const am_domainID_t domainID); + am_Error_e removeSourceLookup(const am_sourceID_t sourceID); + am_Error_e removeSinkLookup(const am_sinkID_t sinkID); + am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID); + am_Error_e removeConnectionLookup(const am_connectionID_t connectionID); + + 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_CustomConnectionFormat_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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; + am_Error_e asyncSetVolumes(am_Handle_s& handle, const std::vector& listVolumes); + am_Error_e asyncSetSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration); + am_Error_e asyncSetSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration); + am_Error_e resyncConnectionState(const am_domainID_t domainID, std::vector& listOfExistingConnections); + + struct InterfaceNamePairs //!< is used to pair interfaces with busnames + { + IAmRoutingSend* routingInterface; //!< pointer to the routingInterface + std::string busName; //!< the busname + }; + + class am_handleData_c //!< is used to store data related to handles + { + public: + union + { + am_sinkID_t sinkID; + am_sourceID_t sourceID; + am_crossfaderID_t crossfaderID; + am_connectionID_t connectionID; + am_DataType_u volumeID; + }; + + union + { + am_SoundProperty_s soundPropery; + am_SourceState_e sourceState; + am_volume_t volume; + am_HotSink_e hotSink; + std::vector* soundProperties; + std::vector* listVolumes; + am_NotificationConfiguration_s* notificationConfiguration; + }; + + }; + + am_Error_e returnHandleData(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) const; //!< returns the handle data associated with a handle + am_Error_e returnHandleDataAndRemove(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData); //!< returns the handle data associated with a handle and removes the handle + +#ifdef UNIT_TEST //this is needed to test RoutingSender + friend class IAmRoutingBackdoor; +#endif + +private: + struct comparator //!< is needed to sort the handles in the map + { + bool operator()(const am_Handle_s& a, const am_Handle_s& b) const + { + return (a.handle 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 *mpRoutingReceiver; //!< pointer to routing receiver +}; + +} + +#endif /* ROUTINGSENDER_H_ */ diff --git a/AudioManagerCore/include/CAmTelnetMenuHelper.h b/AudioManagerCore/include/CAmTelnetMenuHelper.h new file mode 100644 index 0000000..7038cb3 --- /dev/null +++ b/AudioManagerCore/include/CAmTelnetMenuHelper.h @@ -0,0 +1,204 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * \file CAmTelnetMenuHelper.h + * For further information see http://www.genivi.org/. + * + */ + +// Local header +#ifndef CAMTELNETMENUHELPER_H_ +#define CAMTELNETMENUHELPER_H_ + +// Standard header +#include +#include +#include +#include +#include +#include +#include +#include "audiomanagertypes.h" + +namespace am +{ + +class CAmTelnetServer; +class IAmDatabaseHandler; +class CAmCommandSender; +class CAmRoutingSender; +class CAmControlSender; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; + +class CAmRouter; +class CAmSocketHandler; + +/** + * helper class for CAmTelnetServer + */ +class CAmTelnetMenuHelper +{ +public: + + enum EMainState + { + eRootState = 0, eListState, eInfoState, eGetState, eSetState + }; + + CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer); + + ~CAmTelnetMenuHelper(); + + void newSocketConnection(int filedescriptor); + + void socketConnectionsClosed(int filedescriptor); + + void enterCmdQueue(std::queue &CmdQueue, int &filedescriptor); + +private: + + void createCommandMaps(); + void sendError(int & filedescriptor, std::string error_string); + void sendTelnetLine(int & filedescriptor, std::stringstream &line); + void sendCurrentCmdPrompt(int &filedescriptor); + + // COMMON commands + static void oneStepBackCommand(std::queue & CmdQueue, int & filedescriptor); + void oneStepBackCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void exitCommand(std::queue & CmdQueue, int & filedescriptor); + void exitCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void helpCommand(std::queue & CmdQueue, int & filedescriptor); + void helpCommandExec(std::queue & CmdQueue, int & filedescriptor); + + // ROOT commands + static void rootGetCommand(std::queue & CmdQueue, int & filedescriptor); + void rootGetCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void rootSetCommand(std::queue & CmdQueue, int & filedescriptor); + void rootSetCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void rootListCommand(std::queue & CmdQueue, int & filedescriptor); + void rootListCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void rootInfoCommand(std::queue & CmdQueue, int & filedescriptor); + void rootInfoCommandExec(std::queue & CmdQueue, int & filedescriptor); + + // LIST commands + static void listConnectionsCommand(std::queue & CmdQueue, int & filedescriptor); + void listConnectionsCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listSourcesCommand(std::queue & CmdQueue, int & filedescriptor); + void listSourcesCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listSinksCommands(std::queue & CmdQueue, int & filedescriptor); + void listSinksCommandsExec(std::queue & CmdQueue, int & filedescriptor); + static void listCrossfaders(std::queue & CmdQueue, int & filedescriptor); + void listCrossfadersExec(std::queue & CmdQueue, int & filedescriptor); + static void listDomainsCommand(std::queue & CmdQueue, int & filedescriptor); + void listDomainsCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listGatewaysCommand(std::queue & CmdQueue, int & filedescriptor); + void listGatewaysCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listPluginsCommand(std::queue & CmdQueue, int & filedescriptor); + void listPluginsCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listMainConnectionsCommand(std::queue & CmdQueue, int & filedescriptor); + void listMainConnectionsCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listMainSourcesCommand(std::queue & CmdQueue, int & filedescriptor); + void listMainSourcesCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void listMainSinksCommand(std::queue & CmdQueue, int & filedescriptor); + void listMainSinksCommandExec(std::queue & CmdQueue, int & filedescriptor); + + // SET commands + static void setRoutingCommand(std::queue & CmdQueue, int & filedescriptor); + void setRoutingCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void setConnection(std::queue & CmdQueue, int & filedescriptor); + void setConnectionExec(std::queue & CmdQueue, int & filedescriptor); + static void setDisconnectConnId(std::queue & CmdQueue, int & filedescriptor); + void setDisconnectConnIdExec(std::queue & CmdQueue, int & filedescriptor); + static void setSourceSoundProperties(std::queue & CmdQueue, int & filedescriptor); + void setSourceSoundPropertiesExec(std::queue & CmdQueue, int & filedescriptor); + static void setSinkSoundProperty(std::queue & CmdQueue, int & filedescriptor); + void setSinkSoundPropertyExec(std::queue & CmdQueue, int & filedescriptor); + static void setSinkVolume(std::queue & CmdQueue, int & filedescriptor); + void setSinkVolumeExec(std::queue & CmdQueue, int & filedescriptor); + static void setVolumeStep(std::queue & CmdQueue, int & filedescriptor); + void setVolumeStepExec(std::queue & CmdQueue, int & filedescriptor); + static void setSinkMuteState(std::queue & CmdQueue, int & filedescriptor); + void setSinkMuteStateExec(std::queue & CmdQueue, int & filedescriptor); + static void setSourceSoundProperty(std::queue & CmdQueue, int & filedescriptor); + void setSourceSoundPropertyExec(std::queue & CmdQueue, int & filedescriptor); + + // GET commands + static void getRoutingCommand(std::queue & CmdQueue, int & filedescriptor); + void getRoutingCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void getSenderversionCommand(std::queue & CmdQueue, int & filedescriptor); + void getSenderversionCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void getReceiverversionCommand(std::queue & CmdQueue, int & filedescriptor); + void getReceiverversionCommandExec(std::queue & CmdQueue, int & filedescriptor); + + // INFO commands + static void infoSystempropertiesCommand(std::queue & CmdQueue, int & filedescriptor); + void infoSystempropertiesCommandExec(std::queue & CmdQueue, int & filedescriptor); + static void infoDumpCommand(std::queue& CmdQueue, int& filedescriptor); + void infoDumpCommandExec(std::queue& CmdQueue, int& filedescriptor); + +private: + + typedef void (*pCommandPrototype)(std::queue& msg, int & filedescriptor); + + struct sCommandPrototypeInfo + { + std::string info; + pCommandPrototype CommandPrototype; + + // default contructor to set NULL + sCommandPrototypeInfo() : + info(""), CommandPrototype(NULL) + { + } + + // a small contructor + sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) : + info(MyInfo), CommandPrototype(MyCommandPrototype) + { + } + }; + + typedef std::map tCommandMap; + std::map mCurrentMainStateMap; //!< int filedescriptor of socket connection; EMainState state of current telnet session + + static CAmTelnetMenuHelper* instance; + CAmTelnetServer *mpTelenetServer; + CAmSocketHandler *mpSocketHandler; + CAmCommandSender *mpCommandSender; + CAmCommandReceiver *mpCommandReceiver; + CAmRoutingSender *mpRoutingSender; + CAmRoutingReceiver *mpRoutingReceiver; + CAmControlSender *mpControlSender; + CAmControlReceiver *mpControlReceiver; + IAmDatabaseHandler *mpDatabasehandler; + CAmRouter *mpRouter; + + tCommandMap mRootCommands; + tCommandMap mListCommands; + tCommandMap mGetCommands; + tCommandMap mSetCommands; + tCommandMap mInfoCommands; + +}; +// class CAmTelnetMenuHelper +}// namespace am + +#endif // CAMTELNETMENUHELPER_H_ diff --git a/AudioManagerCore/include/CAmTelnetServer.h b/AudioManagerCore/include/CAmTelnetServer.h new file mode 100644 index 0000000..0e4c510 --- /dev/null +++ b/AudioManagerCore/include/CAmTelnetServer.h @@ -0,0 +1,100 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * \file CAmTelnetServer.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef TELNETSERVER_H_ +#define TELNETSERVER_H_ + +#include +#include +#include "CAmSocketHandler.h" +#include "CAmTelnetMenuHelper.h" + +namespace am +{ + +class IAmDatabaseHandler; +class CAmCommandSender; +class CAmRoutingSender; +class CAmControlSender; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; +class CAmRouter; +class CAmTelnetMenuHelper; + +/** + * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugging purposes. + * For example, launch a telnet session on port 6060: + * \code telnet localhost 6060 \endcode + * more details can be found at the README + */ +class CAmTelnetServer +{ +public: + CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *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* mpInstance; + CAmSocketHandler *mpSocketHandler; + CAmCommandSender *mpCommandSender; + CAmCommandReceiver *mpCommandReceiver; + CAmRoutingSender *mpRoutingSender; + CAmRoutingReceiver *mpRoutingReceiver; + CAmControlSender *mpControlSender; + CAmControlReceiver *mpControlReceiver; + IAmDatabaseHandler *mpDatabasehandler; + CAmRouter *mpRouter; + sh_pollHandle_t mConnecthandle; + std::queue mListMessages; + std::vector mListConnections; + int mConnectFD; + unsigned int mServerPort; + unsigned int mMaxConnections; + CAmTelnetMenuHelper mTelnetMenuHelper; + +}; + +} /* namespace am */ +#endif /* TELNETSERVER_H_ */ diff --git a/AudioManagerCore/include/IAmDatabaseHandler.h b/AudioManagerCore/include/IAmDatabaseHandler.h new file mode 100644 index 0000000..30c1aaf --- /dev/null +++ b/AudioManagerCore/include/IAmDatabaseHandler.h @@ -0,0 +1,200 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file IAmDatabaseHandler.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef DATABASEHANDLERINTERFACE_H_ +#define DATABASEHANDLERINTERFACE_H_ + +#include "audiomanagertypes.h" +#include +#include +#include +#include +#include +#include "audiomanagerconfig.h" + +namespace am +{ + +class CAmDatabaseObserver; +class CAmRoutingTree; +class CAmRoutingTreeItem; + + +//enum { 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 + +typedef std::map > ListConnectionFormat; //!< type for list of connection formats + +/** + * This class handles and abstracts the database + */ + +class IAmDatabaseHandler +{ +public: + IAmDatabaseHandler () {}; + virtual ~IAmDatabaseHandler () {}; + virtual am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID) = 0; + virtual am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID) = 0; + virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) = 0; + virtual am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) = 0; + virtual am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) = 0; + virtual am_Error_e enterConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID) = 0; + virtual am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID) = 0; + virtual am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID) = 0; + virtual am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID) = 0; + virtual am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass) = 0; + virtual am_Error_e enterSystemProperties(const std::vector& listSystemProperties) = 0; + virtual am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) = 0; + virtual am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) = 0; + virtual am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) = 0; + virtual am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID) = 0; + virtual am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) = 0; + virtual am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) = 0; + virtual am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) = 0; + virtual am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) = 0; + virtual am_Error_e changeSourceSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sourceID_t sourceID) = 0; + virtual am_Error_e changeSinkSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sinkID_t sinkID) = 0; + virtual am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID) = 0; + virtual am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property) = 0; + virtual am_Error_e changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) = 0; + virtual am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) = 0; + virtual am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) = 0; + virtual am_Error_e changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) = 0; + virtual am_Error_e changeConnectionFinal(const am_connectionID_t connectionID) = 0; + virtual am_Error_e changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) = 0; + virtual am_Error_e changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) = 0; + virtual am_Error_e changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) = 0; + virtual am_Error_e changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) = 0; + virtual am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) = 0; + virtual am_Error_e removeSinkDB(const am_sinkID_t sinkID) = 0; + virtual am_Error_e removeSourceDB(const am_sourceID_t sourceID) = 0; + virtual am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID) = 0; + virtual am_Error_e removeConverterDB(const am_converterID_t converterID) = 0; + virtual am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID) = 0; + virtual am_Error_e removeDomainDB(const am_domainID_t domainID) = 0; + virtual am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID) = 0; + virtual am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID) = 0; + virtual am_Error_e removeConnection(const am_connectionID_t connectionID) = 0; + virtual am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const = 0; + virtual am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const = 0; + virtual am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const = 0; + virtual am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const = 0; + virtual am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const = 0; + virtual am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const = 0; + virtual am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const = 0; + virtual am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const = 0; + virtual am_Error_e getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const = 0; + virtual am_Error_e getSinkVolume(const am_sinkID_t sinkID, am_volume_t& volume) const = 0; + virtual am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const = 0; + virtual am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; + virtual am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; + virtual am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const =0; + virtual am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const =0; + virtual am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; + virtual am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; + virtual am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const = 0; + virtual am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const = 0; + virtual am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const = 0; + virtual am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const = 0; + virtual am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) const = 0; + virtual am_Error_e getListMainConnections(std::vector& listMainConnections) const = 0; + virtual am_Error_e getListDomains(std::vector& listDomains) const = 0; + virtual am_Error_e getListConnections(std::vector& listConnections) const = 0; + virtual am_Error_e getListSinks(std::vector& listSinks) const = 0; + virtual am_Error_e getListSources(std::vector& lisSources) const = 0; + virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const = 0; + virtual am_Error_e getListCrossfaders(std::vector& listCrossfaders) const = 0; + virtual am_Error_e getListGateways(std::vector& listGateways) const = 0; + virtual am_Error_e getListConverters(std::vector & listConverters) const = 0; + virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const = 0; + virtual am_Error_e getListVisibleMainConnections(std::vector& listConnections) const = 0; + virtual am_Error_e getListMainSinks(std::vector& listMainSinks) const = 0; + virtual am_Error_e getListMainSources(std::vector& listMainSources) const = 0; + virtual am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const = 0; + virtual am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const = 0; + virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const = 0; + virtual am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const = 0; + virtual am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const = 0; + virtual am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const = 0; + virtual am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const = 0; + virtual am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const = 0; + virtual am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const = 0; + virtual am_Error_e getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const = 0; + virtual am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const = 0; + virtual am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const = 0; + virtual am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID) = 0; + virtual am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID) = 0; + virtual am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID) = 0; + virtual am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) = 0; + virtual am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) = 0; + virtual am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) = 0; + virtual am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) = 0; + virtual am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) = 0; + virtual am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) = 0; + virtual am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + virtual am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + virtual am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) = 0; + virtual am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) = 0; + virtual am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration) = 0; + virtual am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration) = 0; + + virtual bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const = 0; + virtual bool existCrossFader(const am_crossfaderID_t crossfaderID) const = 0; + virtual bool existConnection(const am_Connection_s & connection) const = 0; + virtual bool existConnectionID(const am_connectionID_t connectionID) const = 0; + virtual bool existSource(const am_sourceID_t sourceID) const = 0; + virtual bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const = 0; + virtual bool existSourceName(const std::string& name) const = 0; + virtual bool existSink(const am_sinkID_t sinkID) const = 0; + virtual bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const = 0; + virtual bool existSinkName(const std::string& name) const = 0; + virtual bool existDomain(const am_domainID_t domainID) const = 0; + virtual bool existGateway(const am_gatewayID_t gatewayID) const = 0; + virtual bool existSinkClass(const am_sinkClass_t sinkClassID) const = 0; + virtual bool existSourceClass(const am_sourceClass_t sourceClassID) const = 0; + virtual void registerObserver(CAmDatabaseObserver *iObserver) = 0; + virtual bool sourceVisible(const am_sourceID_t sourceID) const = 0; + virtual bool sinkVisible(const am_sinkID_t sinkID) const = 0; + virtual bool isComponentConnected(const am_Gateway_s & gateway) const = 0; + virtual bool isComponentConnected(const am_Converter_s & converter) const = 0; + virtual am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const = 0; //!< calculates a new main connection delay + virtual void dump( std::ostream & output) const = 0 ; + virtual am_Error_e enumerateSources(std::function cb) const = 0 ; + virtual am_Error_e enumerateSinks(std::function cb) const = 0 ; + virtual am_Error_e enumerateGateways(std::function cb) const = 0 ; + virtual am_Error_e enumerateConverters(std::function cb) const = 0 ; + +}; + + +} + +#endif /* DATABASEHANDLERINTERFACE_H_ */ diff --git a/AudioManagerCore/include/TAmPluginTemplate.h b/AudioManagerCore/include/TAmPluginTemplate.h new file mode 100644 index 0000000..f000fbe --- /dev/null +++ b/AudioManagerCore/include/TAmPluginTemplate.h @@ -0,0 +1,91 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file TAmPluginTemplate.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef PLUGINTEMPLATE_H_ +#define PLUGINTEMPLATE_H_ + +#include +#include +#include "CAmDltWrapper.h" + +namespace am +{ + +/** + * * This template tries to load a library and cast to a class + * @param libname the full path to the library to be loaded + * @param libraryHandle the handle to the library that gets returned + * @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/AudioManagerCore/src/CAmCommandReceiver.cpp b/AudioManagerCore/src/CAmCommandReceiver.cpp new file mode 100644 index 0000000..d903384 --- /dev/null +++ b/AudioManagerCore/src/CAmCommandReceiver.cpp @@ -0,0 +1,264 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmCommandReceiver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmCommandReceiver.h" +#include +#include +#include "IAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" + +namespace am +{ + +CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : + mDatabaseHandler(iDatabaseHandler), // + mControlSender(iControlSender), // + mDBusWrapper(NULL), // + mSocketHandler(iSocketHandler), // + handleCount(0),// + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false), + mLastErrorStartup(E_OK), // + mLastErrorRundown(E_OK) // + +{ + assert(mDatabaseHandler!=NULL); + assert(mSocketHandler!=NULL); + assert(mControlSender!=NULL); +} + +CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : + mDatabaseHandler(iDatabaseHandler), // + mControlSender(iControlSender), // + mDBusWrapper(iDBusWrapper), // + mSocketHandler(iSocketHandler), // + handleCount(0),// + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false), // + mLastErrorStartup(E_UNKNOWN), // + mLastErrorRundown(E_UNKNOWN) +{ + 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::getVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const +{ + return (mDatabaseHandler->getSinkMainVolume(sinkID, mainVolume)); +} + +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 + dbusConnectionWrapper = NULL; + 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 = CommandVersion; +} + +void CAmCommandReceiver::confirmCommandReady(const uint16_t handle, const am_Error_e error) +{ + if (error !=E_OK) + mLastErrorStartup=error; + mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); + if (mWaitStartup && mListStartupHandles.empty()) + mControlSender->confirmCommandReady(mLastErrorStartup); +} + +void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle, const am_Error_e error) +{ + if (error !=E_OK) + mLastErrorRundown=error; + mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); + if (mWaitRundown && mListRundownHandles.empty()) + mControlSender->confirmCommandRundown(mLastErrorRundown); +} + +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; + mLastErrorStartup=E_OK; +} + +am_Error_e CAmCommandReceiver::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) const +{ + return (mDatabaseHandler->getListMainSinkNotificationConfigurations(sinkID,listMainNotificationConfigurations)); +} + +am_Error_e CAmCommandReceiver::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) const +{ + return (mDatabaseHandler->getListMainSourceNotificationConfigurations(sourceID,listMainNotificationConfigurations)); +} + +am_Error_e CAmCommandReceiver::setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + logInfo("CommandReceiver::setMainSinkNotificationConfiguration got called, sinkID=", sinkID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status); + return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration)); +} + +am_Error_e CAmCommandReceiver::setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + logInfo("CommandReceiver::setMainSourceNotificationConfiguration got called, sourceID=", sourceID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status); + return (mControlSender->hookUserSetMainSourceNotificationConfiguration(sourceID,mainNotificationConfiguration)); +} + +void CAmCommandReceiver::waitOnRundown(bool rundown) +{ + mWaitRundown = rundown; + mLastErrorStartup=E_OK; +} + +} diff --git a/AudioManagerCore/src/CAmCommandSender.cpp b/AudioManagerCore/src/CAmCommandSender.cpp new file mode 100644 index 0000000..da064cc --- /dev/null +++ b/AudioManagerCore/src/CAmCommandSender.cpp @@ -0,0 +1,367 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmCommandSender.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmCommandSender.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "CAmCommandReceiver.h" +#include "TAmPluginTemplate.h" +#include "CAmDltWrapper.h" +#include "audiomanagerconfig.h" + +namespace am +{ + +/** + * 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() +{ + if (listOfPluginDirectories.empty()) + { + logError("CAmCommandSender::CAmCommandSender: List of commandplugins is empty"); + } + + 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; + std::string fullName = *dirIter + "/" + entryName; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + + 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"); + dlclose(tempLibHandle); + continue; + } + + //check libversion + std::string version, cVersion(CommandVersion); + commander->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion; + std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion; + + + + if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion))) + { + logError("CommandInterface initialization failed. Version of Interface to old"); + dlclose(tempLibHandle); + 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); + + //create a list of handles + std::vector listStartupHandles; + for (size_t i = 0; i < mListInterfaces.size(); i++) + { + listStartupHandles.push_back(mCommandReceiver->getStartupHandle()); + } + + //set the receiver ready to wait for replies + mCommandReceiver->waitOnStartup(true); + + //now do the calls + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + std::vector::const_iterator handleIter(listStartupHandles.begin()); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandReady(*(handleIter++)); + } +} + +void CAmCommandSender::setCommandRundown() +{ + mCommandReceiver->waitOnRundown(false); + //create a list of handles + std::vector listStartupHandles; + for (size_t i = 0; i < mListInterfaces.size(); i++) + { + listStartupHandles.push_back(mCommandReceiver->getRundownHandle()); + } + + //set the receiver ready to wait for replies + mCommandReceiver->waitOnRundown(true); + + //now do the calls + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + std::vector::const_iterator handleIter(listStartupHandles.begin()); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandRundown(*(handleIter++)); + } +} + +void CAmCommandSender::getInterfaceVersion(std::string & version) const +{ + version = CommandVersion; +} + +am_Error_e am::CAmCommandSender::getListPlugins(std::vector & interfaces) const +{ + interfaces = mListLibraryNames; + return (E_OK); +} + +void CAmCommandSender::cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties) +{ + CALL_ALL_INTERFACES(cbSinkUpdated(sinkID,sinkClassID,listMainSoundProperties)); +} + +void CAmCommandSender::cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties) +{ + CALL_ALL_INTERFACES(cbSourceUpdated(sourceID,sourceClassID,listMainSoundProperties)); +} + +void CAmCommandSender::cbSinkNotification(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification) +{ + CALL_ALL_INTERFACES(cbSinkNotification(sinkID,notification)); +} + +void CAmCommandSender::cbSourceNotification(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification) +{ + CALL_ALL_INTERFACES(cbSourceNotification(sourceID,notification)); +} + +void CAmCommandSender::cbSinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + CALL_ALL_INTERFACES(cbMainSinkNotificationConfigurationChanged(sinkID,mainNotificationConfiguration)); +} + +void CAmCommandSender::cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + CALL_ALL_INTERFACES(cbMainSourceNotificationConfigurationChanged(sourceID,mainNotificationConfiguration)); +} + +void CAmCommandSender::unloadLibraries(void) +{ + std::vector::iterator iterator = mListLibraryHandles.begin(); + for (; iterator < mListLibraryHandles.end(); ++iterator) + { + dlclose(*iterator); + } + mListLibraryHandles.clear(); +} +} diff --git a/AudioManagerCore/src/CAmControlReceiver.cpp b/AudioManagerCore/src/CAmControlReceiver.cpp new file mode 100644 index 0000000..c1c161e --- /dev/null +++ b/AudioManagerCore/src/CAmControlReceiver.cpp @@ -0,0 +1,606 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmControlReceiver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmControlReceiver.h" +#include +#include +#include +#include "audiomanagerconfig.h" +#include "IAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "CAmCommandSender.h" +#include "CAmRouter.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" + +namespace am { + +CAmControlReceiver::CAmControlReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter) : + mDatabaseHandler(iDatabaseHandler), // + mRoutingSender(iRoutingSender), // + mCommandSender(iCommandSender), // + mSocketHandler(iSocketHandler), // + mRouter(iRouter), // + mNodeStateCommunicator(NULL) +{ + 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_CustomConnectionFormat_t 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; + tempConnection.delay=-1; + + mDatabaseHandler->enterConnectionDB(tempConnection, connectionID); + am_Error_e syncError(mRoutingSender->asyncConnect(handle, connectionID, sourceID, sinkID, format)); + if (syncError) + { + mDatabaseHandler->removeConnection(connectionID); + } + return(syncError); +} + +am_Error_e CAmControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID) +{ + logInfo("CAmControlReceiver::disconnect got called, connectionID=", connectionID); + 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_CustomRampType_t rampType, const am_time_t rampTime) +{ + logInfo("CAmControlReceiver::crossfade got called, hotSource=", hotSource, "crossfaderID=", crossfaderID, "rampType=", rampType, "rampTime=", rampTime); + 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); + 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_CustomRampType_t ramp, const am_time_t time) +{ + logInfo("CAmControlReceiver::setSinkVolume got called, sinkID=", sinkID, "volume=", volume, "ramp=", ramp, "time=", time); + 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_CustomRampType_t rampType, const am_time_t time) +{ + logInfo("CAmControlReceiver::setSourceVolume got called, sourceID=", sourceID, "volume=", volume, "ramp=", rampType, "time=", time); + 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); + 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); + 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); + 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); + 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); + 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::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID) +{ + return (mDatabaseHandler->enterConverterDB(converterData, converterID)); +} + +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->changeMainSourceSoundPropertyDB(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::removeConverterDB(const am_converterID_t converterID) +{ + return (mDatabaseHandler->removeConverterDB(converterID)); +} + +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::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s & converterData) const +{ + return (mDatabaseHandler->getConverterInfoDB(converterID, converterData)); +} + + +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::getListConvertersOfDomain(const am_domainID_t domainID,std::vector& listConverterID) const +{ + return (mDatabaseHandler->getListConvertersOfDomain(domainID,listConverterID)); +} + +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::getListConverters(std::vector& listConverters) const +{ + return (mDatabaseHandler->getListConverters(listConverters)); +} + +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(const am_Error_e error) +{ + if (error!=E_OK) + logError("CAmControlReceiver::confirmControllerReady controller reported error", error); +} + +void CAmControlReceiver::confirmControllerRundown(const am_Error_e error) +{ + if (error!=E_OK) + { + logError("CAmControlReceiver::confirmControllerRundown() exited with error ",error); + //we might be blocked here -> so lets better exit right away + throw std::runtime_error("controller Confirmed with error"); + } + + logInfo ("CAmControlReceiver::confirmControllerRundown(), will exit now"); + + //end the mainloop here... + mSocketHandler->exit_mainloop(); +} + +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 = ControlVersion; +} + +am_Error_e CAmControlReceiver::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + logInfo("CAmControlReceiver::changeSourceDB was called, sourceID", sourceID); + return (mDatabaseHandler->changeSourceDB(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlReceiver::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + logInfo("CAmControlReceiver::changeSinkDB was called with sinkID", sinkID); + return (mDatabaseHandler->changeSinkDB(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlReceiver::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) +{ + logInfo("CAmControlReceiver::changeGatewayDB was called with gatewayID", gatewayID); + return (mDatabaseHandler->changeGatewayDB(gatewayID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix)); +} + +am_Error_e CAmControlReceiver::changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) +{ + logInfo("CAmControlReceiver::changeConverterDB was called with converterID", converterID); + return (mDatabaseHandler->changeConverterDB(converterID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix)); +} + +am_Error_e CAmControlReceiver::setVolumes(am_Handle_s& handle, const std::vector& listVolumes) +{ + logInfo("CAmControlReceiver::setVolumes got called"); + return (mRoutingSender->asyncSetVolumes(handle,listVolumes)); +} + +am_Error_e CAmControlReceiver::setSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + logInfo("CAmControlReceiver::setSinkNotificationConfiguration called, sinkID=",sinkID,"notificationConfiguration.type=",notificationConfiguration.type,"notificationConfiguration.status",notificationConfiguration.status,"notificationConfiguration.parameter",notificationConfiguration.parameter); + return (mRoutingSender->asyncSetSinkNotificationConfiguration(handle,sinkID,notificationConfiguration)); +} + +am_Error_e CAmControlReceiver::setSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + logInfo("CAmControlReceiver::setSourceNotificationConfiguration called, sourceID=",sourceID,"notificationConfiguration.type=",notificationConfiguration.type,"notificationConfiguration.status",notificationConfiguration.status,"notificationConfiguration.parameter",notificationConfiguration.parameter); + return (mRoutingSender->asyncSetSourceNotificationConfiguration(handle,sourceID,notificationConfiguration)); +} + +void CAmControlReceiver::sendMainSinkNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s& notificationPayload) +{ + logInfo("CAmControlReceiver::sendSinkMainNotificationPayload called, sinkID=",sinkID,"type=",notificationPayload.type,"value=",notificationPayload.value); + mCommandSender->cbSinkNotification(sinkID,notificationPayload); +} + +void CAmControlReceiver::sendMainSourceNotificationPayload(const am_sourceID_t sourceID, const am_NotificationPayload_s& notificationPayload) +{ + logInfo("CAmControlReceiver::sendSourceMainNotificationPayload called, sourceID=",sourceID,"type=",notificationPayload.type,"value=",notificationPayload.value); + mCommandSender->cbSourceNotification(sourceID,notificationPayload); +} + +am_Error_e CAmControlReceiver::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + logInfo("CAmControlReceiver::changeMainSinkNotificationConfigurationDB was called with sinkID", sinkID); + return (mDatabaseHandler->changeMainSinkNotificationConfigurationDB(sinkID,mainNotificationConfiguration)); +} + +am_Error_e CAmControlReceiver::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) +{ + logInfo("CAmControlReceiver::changeMainSourceNotificationConfigurationDB was called with sourceID", sourceID); + return (mDatabaseHandler->changeMainSourceNotificationConfigurationDB(sourceID,mainNotificationConfiguration)); +} + +am_Error_e CAmControlReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListMainSinkSoundProperties was called, sinkID", sinkID); + return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID,listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListMainSourceSoundProperties was called, sourceID", sourceID); + return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListSinkSoundProperties was called, sinkID", sinkID); + return (mDatabaseHandler->getListSinkSoundProperties(sinkID,listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListSourceSoundProperties was called, sourceID", sourceID); + return (mDatabaseHandler->getListSourceSoundProperties(sourceID, listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getMainSinkSoundPropertyValue was called, sinkID", sinkID); + return (mDatabaseHandler->getMainSinkSoundPropertyValue(sinkID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getSinkSoundPropertyValue was called, sinkID", sinkID); + return (mDatabaseHandler->getSinkSoundPropertyValue(sinkID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getMainSourceSoundPropertyValue was called, sourceID", sourceID); + return (mDatabaseHandler->getMainSourceSoundPropertyValue(sourceID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getSourceSoundPropertyValue was called, sourceID", sourceID); + return (mDatabaseHandler->getSourceSoundPropertyValue(sourceID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::resyncConnectionState(const am_domainID_t domainID,std::vector& listOfExistingConnections) +{ + logInfo("CAmControlReceiver::resyncConnectionState was called, domainID", domainID); + return (mRoutingSender->resyncConnectionState(domainID,listOfExistingConnections)); +} + +} + diff --git a/AudioManagerCore/src/CAmControlSender.cpp b/AudioManagerCore/src/CAmControlSender.cpp new file mode 100644 index 0000000..10125d5 --- /dev/null +++ b/AudioManagerCore/src/CAmControlSender.cpp @@ -0,0 +1,571 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmControlSender.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmControlSender.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "TAmPluginTemplate.h" +#include "CAmDltWrapper.h" + +namespace am +{ + +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 //!< major interface version. All versions smaller than this will be rejected +#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< minor interface version. All versions smaller than this will be rejected + +CAmControlSender* CAmControlSender::mInstance=NULL; + +CAmControlSender::CAmControlSender(std::string controlPluginFile,CAmSocketHandler* sockethandler) : + receiverCallbackT(this, &CAmControlSender::receiverCallback),// + checkerCallbackT(this, &CAmControlSender::checkerCallback),// + dispatcherCallbackT(this, &CAmControlSender::dispatcherCallback), // + mPipe(), // + mlibHandle(NULL), // + mController(NULL), // + mSignal(0) +{ + assert(sockethandler); + + //Check if a folder is given, then select the first plugin + struct stat buf; + const char* conFile(controlPluginFile.c_str()); + stat(conFile, &buf); + if (S_ISDIR(buf.st_mode)) + { + std::string directoryName(controlPluginFile); + logInfo("Searching for ControlPlugin in", directoryName); + DIR *directory = opendir(directoryName.c_str()); + + if (!directory) + { + logError("Error opening directory ", directoryName); + throw std::runtime_error("Controller directory could not be openend"); + } + + // iterate content of directory + struct dirent *itemInDirectory = 0; + while ((itemInDirectory = readdir(directory))) + { + unsigned char entryType = itemInDirectory->d_type; + std::string entryName = itemInDirectory->d_name; + std::string fullName = directoryName + "/" + entryName; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + + if (regularFile && sharedLibExtension) + { + controlPluginFile=directoryName + "/" + entryName; + logInfo("Found ControlPlugin:", controlPluginFile); + break; + } + } + closedir(directory); + + } + + std::ifstream isfile(controlPluginFile.c_str()); + if (!isfile) + { + logError("ControlSender::ControlSender: Controller plugin not found:", controlPluginFile); + throw std::runtime_error("Could not find controller plugin!"); + } + else if (!controlPluginFile.empty()) + { + mInstance=this; + IAmControlSend* (*createFunc)(); + createFunc = getCreateFunction(controlPluginFile, mlibHandle); + assert(createFunc!=NULL); + mController = createFunc(); + + //check libversion + std::string version, cVersion(ControlVersion); + mController->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion; + std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion; + + + + if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion))) + { + 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 !"); + } + + //here we need a pipe to be able to call the rundown function out of the mainloop + if (pipe(mPipe) == -1) + { + logError("CAmControlSender could not create pipe!"); + } + + //add the pipe to the poll - nothing needs to be proccessed here we just need the pipe to trigger the ppoll + short event = 0; + sh_pollHandle_t handle; + event |= POLLIN; + sockethandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, handle); +} + +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) +{ + assert(mController); + return (mController->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID)); +} + +am_Error_e CAmControlSender::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) +{ + assert(mController); + return (mController->hookUserDisconnectionRequest(connectionID)); +} + +am_Error_e CAmControlSender::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) +{ + assert(mController); + return (mController->hookUserSetMainSinkSoundProperty(sinkID, soundProperty)); +} + +am_Error_e CAmControlSender::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) +{ + assert(mController); + return (mController->hookUserSetMainSourceSoundProperty(sourceID, soundProperty)); +} + +am_Error_e CAmControlSender::hookUserSetSystemProperty(const am_SystemProperty_s & property) +{ + assert(mController); + return (mController->hookUserSetSystemProperty(property)); +} + +am_Error_e CAmControlSender::hookUserVolumeChange(const am_sinkID_t sinkID, const am_mainVolume_t newVolume) +{ + assert(mController); + return (mController->hookUserVolumeChange(sinkID, newVolume)); +} + +am_Error_e CAmControlSender::hookUserVolumeStep(const am_sinkID_t sinkID, const int16_t increment) +{ + assert(mController); + return (mController->hookUserVolumeStep(sinkID, increment)); +} + +am_Error_e CAmControlSender::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ + assert(mController); + return (mController->hookUserSetSinkMuteState(sinkID, muteState)); +} + +am_Error_e CAmControlSender::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + assert(mController); + return (mController->hookSystemRegisterDomain(domainData, domainID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterDomain(const am_domainID_t domainID) +{ + assert(mController); + return (mController->hookSystemDeregisterDomain(domainID)); +} + +void CAmControlSender::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) +{ + assert(mController); + return (mController->hookSystemDomainRegistrationComplete(domainID)); +} + +am_Error_e CAmControlSender::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + assert(mController); + return (mController->hookSystemRegisterSink(sinkData, sinkID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterSink(const am_sinkID_t sinkID) +{ + assert(mController); + return (mController->hookSystemDeregisterSink(sinkID)); +} + +am_Error_e CAmControlSender::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + assert(mController); + return (mController->hookSystemRegisterSource(sourceData, sourceID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterSource(const am_sourceID_t sourceID) +{ + assert(mController); + return (mController->hookSystemDeregisterSource(sourceID)); +} + +am_Error_e CAmControlSender::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + assert(mController); + return (mController->hookSystemRegisterGateway(gatewayData, gatewayID)); +} + +am_Error_e CAmControlSender::hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID) +{ + assert(mController); + return (mController->hookSystemRegisterConverter(converterData, converterID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) +{ + assert(mController); + return (mController->hookSystemDeregisterGateway(gatewayID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterConverter(const am_converterID_t converterID) +{ + assert(mController); + return (mController->hookSystemDeregisterConverter(converterID)); +} + +am_Error_e CAmControlSender::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + assert(mController); + return (mController->hookSystemRegisterCrossfader(crossfaderData, crossfaderID)); +} + +am_Error_e CAmControlSender::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) +{ + assert(mController); + return (mController->hookSystemDeregisterCrossfader(crossfaderID)); +} + +void CAmControlSender::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + assert(mController); + mController->hookSystemSinkVolumeTick(handle, sinkID, volume); +} + +void CAmControlSender::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + assert(mController); + mController->hookSystemSourceVolumeTick(handle, sourceID, volume); +} + +void CAmControlSender::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + assert(mController); + mController->hookSystemInterruptStateChange(sourceID, interruptState); +} + +void CAmControlSender::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + assert(mController); + mController->hookSystemSinkAvailablityStateChange(sinkID, availability); +} + +void CAmControlSender::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + assert(mController); + mController->hookSystemSourceAvailablityStateChange(sourceID, availability); +} + +void CAmControlSender::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) +{ + assert(mController); + mController->hookSystemDomainStateChange(domainID, state); +} + +void CAmControlSender::hookSystemReceiveEarlyData(const std::vector & data) +{ + assert(mController); + mController->hookSystemReceiveEarlyData(data); +} + +void CAmControlSender::hookSystemSpeedChange(const am_speed_t speed) +{ + assert(mController); + mController->hookSystemSpeedChange(speed); +} + +void CAmControlSender::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) +{ + assert(mController); + mController->hookSystemTimingInformationChanged(mainConnectionID, time); +} + +void CAmControlSender::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) +{ + assert(mController); + mController->cbAckConnect(handle, errorID); +} + +void CAmControlSender::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) +{ + assert(mController); + mController->cbAckDisconnect(handle, errorID); +} + +void CAmControlSender::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) +{ + assert(mController); + mController->cbAckCrossFade(handle, hostsink, error); +} + +void CAmControlSender::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSinkVolumeChange(handle, volume, error); +} + +void CAmControlSender::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSourceVolumeChange(handle, volume, error); +} + +void CAmControlSender::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSourceState(handle, error); +} + +void CAmControlSender::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSourceSoundProperty(handle, error); +} + +am_Error_e CAmControlSender::startupController(IAmControlReceive *controlreceiveinterface) +{ + if (!mController) + { + logError("ControlSender::startupController: no Controller to startup!"); + throw std::runtime_error("ControlSender::startupController: no Controller to startup! Exiting now ..."); + return (E_NON_EXISTENT); + } + return (mController->startupController(controlreceiveinterface)); +} + +void CAmControlSender::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSinkSoundProperty(handle, error); +} + +void CAmControlSender::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSinkSoundProperties(handle, error); +} + +void CAmControlSender::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSourceSoundProperties(handle, error); +} + +void CAmControlSender::setControllerReady() +{ + assert(mController); + mController->setControllerReady(); +} + +void CAmControlSender::setControllerRundown(const int16_t signal) +{ + assert(mController); + logInfo("CAmControlSender::setControllerRundown received, signal=",signal); + mController->setControllerRundown(signal); +} + +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) +{ + assert(mController); + return (mController->getConnectionFormatChoice(sourceID, sinkID, listRoute, listPossibleConnectionFormats, listPrioConnectionFormats)); +} + +void CAmControlSender::getInterfaceVersion(std::string & version) const +{ + version = ControlVersion; +} + +void CAmControlSender::confirmCommandReady(const am_Error_e error) +{ + assert(mController); + mController->confirmCommandReady(error); +} + +void CAmControlSender::confirmRoutingReady(const am_Error_e error) +{ + assert(mController); + mController->confirmRoutingReady(error); +} + +void CAmControlSender::confirmCommandRundown(const am_Error_e error) +{ + assert(mController); + mController->confirmCommandRundown(error); +} + +void CAmControlSender::confirmRoutingRundown(const am_Error_e error) +{ + assert(mController); + mController->confirmRoutingRundown(error); +} + +am_Error_e CAmControlSender::hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + assert(mController); + return (mController->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlSender::hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + assert(mController); + return (mController->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlSender::hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) +{ + assert(mController); + return (mController->hookSystemUpdateGateway(gatewayID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix)); +} + +am_Error_e CAmControlSender::hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) +{ + assert(mController); + return (mController->hookSystemUpdateConverter(converterID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix)); +} + +void CAmControlSender::cbAckSetVolume(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetVolumes(handle,listVolumes,error); +} + +void CAmControlSender::cbAckSetSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSinkNotificationConfiguration(handle,error); +} + +void CAmControlSender::cbAckSetSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetSourceNotificationConfiguration(handle,error); +} + +void CAmControlSender::hookSinkNotificationDataChanged(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) +{ + assert(mController); + mController->hookSinkNotificationDataChanged(sinkID,payload); +} + +void CAmControlSender::hookSourceNotificationDataChanged(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) +{ + assert(mController); + mController->hookSourceNotificationDataChanged(sourceID,payload); +} + +am_Error_e CAmControlSender::hookUserSetMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + assert(mController); + return (mController->hookUserSetMainSinkNotificationConfiguration(sinkID,notificationConfiguration)); +} + +am_Error_e CAmControlSender::hookUserSetMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + assert(mController); + return (mController->hookUserSetMainSourceNotificationConfiguration(sourceID,notificationConfiguration)); +} + +void CAmControlSender::receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) +{ + (void) handle; + (void) userData; + //get the signal number from the socket + ssize_t result = read(pollfd.fd, &mSignal, sizeof(mSignal)); +} + +bool CAmControlSender::checkerCallback(const sh_pollHandle_t handle, void* userData) +{ + (void) handle; + (void) userData; + return (true); +} + +void CAmControlSender::hookSystemSingleTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t time) +{ + assert(mController); + mController->hookSystemSingleTimingInformationChanged(connectionID,time); +} + +/**for testing only contructor - do not use ! + * + */ +CAmControlSender::CAmControlSender() : + receiverCallbackT(this, &CAmControlSender::receiverCallback),// + checkerCallbackT(this, &CAmControlSender::checkerCallback),// + dispatcherCallbackT(this, &CAmControlSender::dispatcherCallback), // + mPipe(), // + mlibHandle(NULL), // + mController(NULL), // + mSignal(0) +{ + logInfo("CAmControlSender was loaded in test mode!"); +} + +bool CAmControlSender::dispatcherCallback(const sh_pollHandle_t handle, void* userData) +{ + (void)handle; + (void)userData; + setControllerRundown(mSignal); + return (false); +} + +} + + diff --git a/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp new file mode 100644 index 0000000..929c8d5 --- /dev/null +++ b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp @@ -0,0 +1,3079 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmDatabaseHandlerMap.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "CAmDatabaseHandlerMap.h" +#include "CAmDatabaseObserver.h" +#include "CAmRouter.h" +#include "CAmDltWrapper.h" + + +#ifdef WITH_DATABASE_CHANGE_CHECK +# define DB_COND_UPDATE_RIE(x,y) \ + if (isDataEqual(x,y)) return (E_NO_CHANGE); else x = y +# define DB_COND_UPDATE_INIT \ + bool modified = false +# define DB_COND_UPDATE(x,y) \ + if (!isDataEqual(x,y)) { x = y; modified = true; } +# define DB_COND_ISMODIFIED \ + (modified == true) +#else +# define DB_COND_UPDATE_RIE(x,y) \ + x = y +# define DB_COND_UPDATE_INIT +# define DB_COND_UPDATE(x,y) \ + x = y +# define DB_COND_ISMODIFIED \ + (true) +#endif + + +namespace am +{ + +/* + * Checks if content of data is equal + */ +template bool isDataEqual(const T & left, const T & right) +{ + return static_cast(!std::memcmp(&left, &right, sizeof(T))); +} + +template > bool isDataEqual(const L & left, const L & right) +{ + return std::equal(left.begin(), left.end(), right.begin(), isDataEqual); +} + + +/* + * Returns an object for given key + */ +template TMapObjectType const * objectForKeyIfExistsInMap(const TMapKeyType & key, const std::unordered_map & map) +{ + typename std::unordered_map::const_iterator iter = map.find(key); + if( iter!=map.end() ) + return &iter->second; + return NULL; +} + +/* + * Checks whether any object with key exists in a given map + */ +template bool existsObjectWithKeyInMap(const TMapKeyType & key, const std::unordered_map & map) +{ + return objectForKeyIfExistsInMap(key, map)!=NULL; +} + +/** + * \brief Returns an object matching predicate. + * + * Convenient method for searching in a given map. + * + * @param map Map reference. + * @param comparator Search predicate. + * @return NULL or pointer to the found object. + */ +template const TReturn * objectMatchingPredicate(const std::unordered_map & map, + std::function comparator) +{ + typename std::unordered_map::const_iterator elementIterator = map.begin(); + for (;elementIterator != map.end(); ++elementIterator) + { + if( comparator(elementIterator->second) ) + return &elementIterator->second; + } + return NULL; +} + + +/* Domain */ + +void CAmDatabaseHandlerMap::CAmDomain::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Domain(" << name.c_str() << ") id(" << domainID << ")" << std::endl << + "bus name(" << busname.c_str() << + ") node name(" << nodename.c_str() << + ") early(" << early << + ") domainID(" << domainID << + ") complete(" << complete << + ") state(" << state << + ") reserved(" << reserved << ")" << std::endl; + outString = fmt.str(); +} + +/* Source */ + +void CAmDatabaseHandlerMap::CAmSource::getSourceType(am_SourceType_s & sourceType) const +{ + sourceType.name = name; + sourceType.sourceClassID = sourceClassID; + sourceType.availability = available; + sourceType.sourceID = sourceID; +} + +void CAmDatabaseHandlerMap::CAmSource::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Source(" << name.c_str() << ") id(" << sourceID << ")" << std::endl << + "sourceClassID(" << sourceClassID << + ") domainID(" << domainID << + ") visible(" << visible << + ") volume(" << volume << + ") interruptState(" << interruptState << + ") sourceState(" << sourceState << + ") reserved(" << reserved << ")" << + ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]" + ") listSoundProperties ("; + std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) { + fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; + }); + fmt << ") listConnectionFormats ("; + std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") listMainSoundProperties ("; + std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) { + fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; + }); + fmt << ") listMainNotificationConfigurations ("; + std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { + fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; + }); + fmt << ") listNotificationConfigurations ("; + std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { + fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + +/* Sink */ + +void CAmDatabaseHandlerMap::CAmSink::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Sink(" << name.c_str() << ") id(" << sinkID << ")" << std::endl << + "sinkClassID(" << sinkClassID << + ") domainID(" << domainID << + ") visible(" << visible << + ") volume(" << volume << + ") muteState(" << muteState << + ") mainVolume(" << mainVolume << + ") reserved(" << reserved << ")" << + ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]" + ") listSoundProperties ("; + std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) { + fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; + }); + fmt << ") listConnectionFormats ("; + std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") listMainSoundProperties ("; + std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) { + fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; + }); + fmt << ") listMainNotificationConfigurations ("; + std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { + fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; + }); + fmt << ") listNotificationConfigurations ("; + std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { + fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + +void CAmDatabaseHandlerMap::CAmSink::getSinkType(am_SinkType_s & sinkType) const +{ + sinkType.name = name; + sinkType.sinkID = sinkID; + sinkType.availability = available; + sinkType.muteState = muteState; + sinkType.volume = mainVolume; + sinkType.sinkClassID = sinkClassID; +} + +/* Connection */ + +void CAmDatabaseHandlerMap::CAmConnection::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Connection id(" << connectionID << ") " << std::endl << + "sourceID(" << sourceID << + ") sinkID(" << sinkID << + ") delay(" << delay << + ") connectionFormat(" << connectionFormat << + ") reserved(" << reserved << ")" << std::endl; + outString = fmt.str(); +} + +/* Main Connection */ + +void CAmDatabaseHandlerMap::CAmMainConnection::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "MainConnection id(" << mainConnectionID << ") " << std::endl << + "connectionState(" << connectionState << + ") sinkID(" << sinkID << + ") sourceID(" << sourceID << + ") delay(" << delay << + ") listConnectionID ("; + std::for_each(listConnectionID.begin(), listConnectionID.end(), [&](const am_connectionID_t & connID) { + fmt << "["<< connID << "]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + +void CAmDatabaseHandlerMap::am_MainConnection_Database_s::getMainConnectionType(am_MainConnectionType_s & connectionType) const +{ + connectionType.mainConnectionID = mainConnectionID; + connectionType.sourceID = sourceID; + connectionType.sinkID = sinkID; + connectionType.connectionState = connectionState; + connectionType.delay = delay; +} + +/* Source Class */ + +void CAmDatabaseHandlerMap::CAmSourceClass::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Source class(" << name.c_str() << ") id(" << sourceClassID << ")\n" << + ") listClassProperties ("; + std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) { + fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + +/* Sink Class */ + +void CAmDatabaseHandlerMap::CAmSinkClass::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Sink class(" << name.c_str() << ") id(" << sinkClassID << ")\n" << + ") listClassProperties ("; + std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) { + fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + + +/* Gateway */ + +void CAmDatabaseHandlerMap::CAmGateway::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Gateway(" << name.c_str() << ") id(" << gatewayID << ")\n" << + "sinkID(" << sinkID << + ") sourceID(" << sourceID << + ") domainSinkID(" << domainSinkID << + ") domainSourceID(" << domainSourceID << + ") controlDomainID(" << controlDomainID << + ") listSourceFormats ("; + std::for_each(listSourceFormats.begin(), listSourceFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") listSinkFormats ("; + std::for_each(listSinkFormats.begin(), listSinkFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") convertionMatrix ("; + std::for_each(convertionMatrix.begin(), convertionMatrix.end(), [&](const bool & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + +/* Crossfader */ + +void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Crossfader(" << name.c_str() << ") id(" << crossfaderID << ")\n" << + "sinkID_A(" << sinkID_A << + ") sinkID_B(" << sinkID_B << + ") sourceID(" << sourceID << + ") hotSink(" << hotSink << + ")" << std::endl; + outString = fmt.str(); +} + +bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t & resultID, am_Identifier_s & sourceID, + int16_t const desiredStaticID = 0) +{ + if( desiredStaticID > 0 && desiredStaticID < sourceID.mMin ) + { + resultID = desiredStaticID; + return true; + } + else if( sourceID.mCurrentValue < sourceID.mMax ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved. + { + resultID = sourceID.mCurrentValue++; + return true; + } + else + { + resultID = -1; + return false; + } + } + +template bool CAmDatabaseHandlerMap::CAmMappedData::getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, + const std::unordered_map & map) +{ + TMapKey nextID; + int16_t const lastID = sourceID.mCurrentValue; + if( sourceID.mCurrentValue < sourceID.mMax ) + nextID = sourceID.mCurrentValue++; + else + nextID = sourceID.mCurrentValue = sourceID.mMin; + + bool notFreeIDs = false; + while( existsObjectWithKeyInMap(nextID, map) ) + { + + if( sourceID.mCurrentValue < sourceID.mMax ) + nextID = sourceID.mCurrentValue++; + else + { + sourceID.mCurrentValue = sourceID.mMin; + nextID = sourceID.mCurrentValue++; + } + + if( sourceID.mCurrentValue == lastID ) + { + notFreeIDs = true; + break; + } + } + if(notFreeIDs) + { + resultID = -1; + return false; + } + resultID = nextID; + return true; +} + +bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t & resultID) +{ + return getNextConnectionID(resultID, mCurrentMainConnectionID, mMainConnectionMap); +} + +bool CAmDatabaseHandlerMap::CAmMappedData::increaseConnectionID(int16_t & resultID) +{ + return getNextConnectionID(resultID, mCurrentConnectionID, mConnectionMap); +} + + +CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), // + mFirstStaticSource(true), // + mFirstStaticGateway(true), // + mFirstStaticConverter(true), // + mFirstStaticSinkClass(true), // + mFirstStaticSourceClass(true), // + mFirstStaticCrossfader(true), // + mpDatabaseObserver(NULL), // + mListConnectionFormat(), // + mMappedData() +{ + logInfo(__PRETTY_FUNCTION__,"Init "); +} + +CAmDatabaseHandlerMap::~CAmDatabaseHandlerMap() +{ + logInfo(__PRETTY_FUNCTION__,"Destroy"); + mpDatabaseObserver = NULL; +} + +am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + assert(!domainData.name.empty()); + assert(!domainData.busname.empty()); + assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX); + //first check for a reserved domain + am_Domain_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const CAmDomain & obj){ + return domainData.name.compare(obj.name)==0; + }); + + int16_t nextID = 0; + + if( NULL != reservedDomain ) + { + nextID = reservedDomain->domainID; + domainID = nextID; + mMappedData.mDomainMap[nextID] = domainData; + mMappedData.mDomainMap[nextID].domainID = nextID; + mMappedData.mDomainMap[nextID].reserved = 0; + logInfo("DatabaseHandler::enterDomainDB entered reserved domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "reserved ID:", domainID); + if (mpDatabaseObserver) + mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); + return (E_OK); + } + else + { + if(mMappedData.increaseID(nextID, mMappedData.mCurrentDomainID, domainData.domainID)) + { + domainID = nextID; + mMappedData.mDomainMap[nextID] = domainData; + mMappedData.mDomainMap[nextID].domainID = nextID; + logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID); + if (mpDatabaseObserver) + mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); + return (E_OK); + } + else + { + domainID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (E_UNKNOWN); + } + } +} + +int16_t CAmDatabaseHandlerMap::calculateDelayForRoute(const std::vector& listConnectionID) +{ + int16_t delay = 0; + std::vector::const_iterator elementIterator = listConnectionID.begin(); + for (; elementIterator < listConnectionID.end(); ++elementIterator) + { + am_connectionID_t key = *elementIterator; + std::unordered_map::const_iterator it = mMappedData.mConnectionMap.find(key); + if (it!=mMappedData.mConnectionMap.end()) + { + int16_t temp_delay = it->second.delay; + if (temp_delay != -1 && delay != -1) + delay += temp_delay; + else + delay = -1; + } + } + return delay; +} + +am_Error_e CAmDatabaseHandlerMap::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); + + int16_t delay = 0; + int16_t nextID = 0; + if(mMappedData.increaseMainConnectionID(nextID)) + { + connectionID = nextID; + mMappedData.mMainConnectionMap[nextID] = mainConnectionData; + mMappedData.mMainConnectionMap[nextID].mainConnectionID = nextID; + } + else + { + connectionID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (E_UNKNOWN); + } + + //now check the connectionTable for all connections in the route. IF connectionID exist + delay = calculateDelayForRoute(mainConnectionData.listConnectionID); + logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); + + if (mpDatabaseObserver) + { + am_MainConnectionType_s mainConnection; + mMappedData.mMainConnectionMap[nextID].getMainConnectionType(mainConnection); + mpDatabaseObserver->newMainConnection(mainConnection); + mpDatabaseObserver->mainConnectionStateChanged(connectionID, mMappedData.mMainConnectionMap[nextID].connectionState); + } + + //finally, we update the delay value for the maintable + if (delay == 0) + delay = -1; + (void)changeDelayMainConnection(delay, connectionID); + + return (E_OK); +} + +/** + * Helper method, that inserts a new struct in the map and copies the given into it. + * This method uses the increaseID function to secure the global id is properly increased. + **/ +bool CAmDatabaseHandlerMap::insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + int16_t nextID = 0; + if( mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID, sinkData.sinkID) ) + { + sinkID = nextID; + mMappedData.mSinkMap[nextID] = sinkData; + mMappedData.mSinkMap[nextID].sinkID = nextID; + filterDuplicateNotificationConfigurationTypes(mMappedData.mSinkMap[nextID].listNotificationConfigurations); + filterDuplicateNotificationConfigurationTypes(mMappedData.mSinkMap[nextID].listMainNotificationConfigurations); + return (true); + } + else + { + sinkID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached!"); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + assert(sinkData.sinkID=MS_UNKNOWN && sinkData.muteState<=MS_MAX); + + am_sinkID_t temp_SinkID = 0; + am_sinkID_t temp_SinkIndex = 0; + //if sinkID is zero and the first Static Sink was already entered, the ID is created + am_Sink_s const *reservedDomain = objectMatchingPredicate(mMappedData.mSinkMap, [&](const CAmSink & obj){ + return true==obj.reserved && obj.name.compare(sinkData.name)==0; + }); + if( NULL!=reservedDomain ) + { + am_sinkID_t oldSinkID = reservedDomain->sinkID; + mMappedData.mSinkMap[oldSinkID] = sinkData; + mMappedData.mSinkMap[oldSinkID].reserved = 0; + temp_SinkID = oldSinkID; + temp_SinkIndex = oldSinkID; + } + else + { + bool result; + if ( sinkData.sinkID != 0 || mFirstStaticSink ) + { + //check if the ID already exists + if (existSinkNameOrID(sinkData.sinkID, sinkData.name)) + { + sinkID = sinkData.sinkID; + return (E_ALREADY_EXISTS); + } + } + result = insertSinkDB(sinkData, temp_SinkID); + if( false == result ) + return (E_UNKNOWN); + temp_SinkIndex = temp_SinkID; + } + //if the first static sink is entered, we need to set it onto the boundary + if (sinkData.sinkID == 0 && mFirstStaticSink) + { + mFirstStaticSink = false; + } + mMappedData.mSinkMap[temp_SinkIndex].sinkID = temp_SinkID; + sinkID = temp_SinkID; + + am_Sink_s & sink = mMappedData.mSinkMap[temp_SinkID]; + logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sink.name, "domainID:", sink.domainID, "classID:", sink.sinkClassID, "volume:", sink.volume, "assigned ID:", sink.sinkID); + + if (mpDatabaseObserver != NULL) + { + sink.sinkID=sinkID; + mpDatabaseObserver->newSink(sink); + } + return (E_OK); +} + +bool CAmDatabaseHandlerMap::insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentCrossfaderID, crossfaderData.crossfaderID)) + { + crossfaderID = nextID; + mMappedData.mCrossfaderMap[nextID] = crossfaderData; + mMappedData.mCrossfaderMap[nextID].crossfaderID = nextID; + return (true); + } + else + { + crossfaderID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::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)); + + am_crossfaderID_t temp_CrossfaderID = 0; + am_crossfaderID_t temp_CrossfaderIndex = 0; + + bool result; + //if gatewayData is zero and the first Static Sink was already entered, the ID is created + if (crossfaderData.crossfaderID != 0 || mFirstStaticCrossfader) + { + //check if the ID already exists + if (existCrossFader(crossfaderData.crossfaderID)) + { + crossfaderID = crossfaderData.crossfaderID; + return (E_ALREADY_EXISTS); + } + } + result = insertCrossfaderDB(crossfaderData, temp_CrossfaderID); + if( false == result ) + return (E_UNKNOWN); + temp_CrossfaderIndex = temp_CrossfaderID; + + //if the first static sink is entered, we need to set it onto the boundary + if ( 0==crossfaderData.crossfaderID && mFirstStaticCrossfader) + { + mFirstStaticCrossfader = false; + } + + mMappedData.mCrossfaderMap[temp_CrossfaderIndex].crossfaderID = temp_CrossfaderID; + crossfaderID = temp_CrossfaderID; + logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID); + + if (mpDatabaseObserver) + mpDatabaseObserver->newCrossfader(mMappedData.mCrossfaderMap[temp_CrossfaderIndex]); + return (E_OK); +} + +bool CAmDatabaseHandlerMap::insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentGatewayID, gatewayData.gatewayID)) + { + gatewayID = nextID; + mMappedData.mGatewayMap[nextID] = gatewayData; + mMappedData.mGatewayMap[nextID].gatewayID = nextID; + return (true); + } + else + { + gatewayID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + assert(gatewayData.gatewayIDnewGateway(mMappedData.mGatewayMap[temp_GatewayIndex]); + return (E_OK); +} + +bool CAmDatabaseHandlerMap::insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentConverterID, converteData.converterID)) + { + converterID = nextID; + mMappedData.mConverterMap[nextID] = converteData; + mMappedData.mConverterMap[nextID].converterID = nextID; + return (true); + } + else + { + converterID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID) +{ + assert(converterData.converterIDnewConverter(mMappedData.mConverterMap[tempIndex]); + return (E_OK); +} + +void CAmDatabaseHandlerMap::dump( std::ostream & output ) const +{ + output << std::endl << "****************** DUMP START ******************" << std::endl; + CAmMappedData::printMap(mMappedData.mDomainMap, output); + CAmMappedData::printMap(mMappedData.mSourceMap, output); + CAmMappedData::printMap(mMappedData.mSinkMap, output); + CAmMappedData::printMap(mMappedData.mSourceClassesMap, output); + CAmMappedData::printMap(mMappedData.mSinkClassesMap, output); + CAmMappedData::printMap(mMappedData.mConnectionMap, output); + CAmMappedData::printMap(mMappedData.mMainConnectionMap, output); + CAmMappedData::printMap(mMappedData.mCrossfaderMap, output); + CAmMappedData::printMap(mMappedData.mGatewayMap, output); + CAmVectorSystemProperties::const_iterator iter = mMappedData.mSystemProperties.begin(); + output << "System properties" << "\n"; + for(; iter!=mMappedData.mSystemProperties.end(); iter++) + output << "[type:" << iter->type << " value:" << iter->value << "]"; + output << std::endl << "****************** DUMP END ******************" << std::endl; +} + +bool CAmDatabaseHandlerMap::insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID, sourceData.sourceID)) + { + sourceID = nextID; + mMappedData.mSourceMap[nextID] = sourceData; + mMappedData.mSourceMap[nextID].sourceID = nextID; + filterDuplicateNotificationConfigurationTypes(mMappedData.mSourceMap[nextID].listNotificationConfigurations); + filterDuplicateNotificationConfigurationTypes(mMappedData.mSourceMap[nextID].listMainNotificationConfigurations); + return (true); + } + else + { + sourceID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + assert(sourceData.sourceID=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX); + + bool isFirstStatic = sourceData.sourceID == 0 && mFirstStaticSource; + am_sourceID_t temp_SourceID = 0; + am_sourceID_t temp_SourceIndex = 0; + CAmSource const *reservedSource = objectMatchingPredicate(mMappedData.mSourceMap, [&](const CAmSource & obj){ + return true==obj.reserved && obj.name.compare(sourceData.name)==0; + }); + if( NULL != reservedSource ) + { + am_sourceID_t oldSourceID = reservedSource->sourceID; + mMappedData.mSourceMap[oldSourceID] = sourceData; + mMappedData.mSourceMap[oldSourceID].reserved = 0; + temp_SourceID = oldSourceID; + temp_SourceIndex = oldSourceID; + } + else + { + bool result; + if ( !isFirstStatic ) + { + //check if the ID already exists + if (existSourceNameOrID(sourceData.sourceID, sourceData.name)) + { + sourceID = sourceData.sourceID; + return (E_ALREADY_EXISTS); + } + } + result = insertSourceDB(sourceData, temp_SourceID); + if( false == result ) + return (E_UNKNOWN); + temp_SourceIndex = temp_SourceID; + } + + if ( isFirstStatic ) + { + //if the first static sink is entered, we need to set it onto the boundary if needed + mFirstStaticSource = false; + } + mMappedData.mSourceMap[temp_SourceIndex].sourceID = temp_SourceID; + sourceID = temp_SourceID; + + logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); + + if (mpDatabaseObserver) + mpDatabaseObserver->newSource(mMappedData.mSourceMap[temp_SourceIndex]); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::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 + int16_t nextID = 0; + if(mMappedData.increaseConnectionID(nextID)) + { + connectionID = nextID; + mMappedData.mConnectionMap[nextID] = connection; + mMappedData.mConnectionMap[nextID].connectionID = nextID; + mMappedData.mConnectionMap[nextID].reserved = true; + } + else + { + connectionID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (E_UNKNOWN); + } + + logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID); + return (E_OK); +} + +bool CAmDatabaseHandlerMap::insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkClassesID, sinkClass.sinkClassID)) + { + sinkClassID = nextID; + mMappedData.mSinkClassesMap[nextID] = sinkClass; + mMappedData.mSinkClassesMap[nextID].sinkClassID = nextID; + return (true); + } + else + { + sinkClassID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) +{ + assert(sinkClass.sinkClassIDnumberOfSinkClassesChanged(); + return (E_OK); +} + +bool CAmDatabaseHandlerMap::insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) +{ + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceClassesID, sourceClass.sourceClassID)) + { + sourceClassID = nextID; + mMappedData.mSourceClassesMap[nextID] = sourceClass; + mMappedData.mSourceClassesMap[nextID].sourceClassID = nextID; + return (true); + } + else + { + sourceClassID = 0; + logInfo(__PRETTY_FUNCTION__,"Max limit reached."); + return (false); + } +} + +am_Error_e CAmDatabaseHandlerMap::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) +{ + assert(sourceClass.sourceClassIDnumberOfSourceClassesChanged(); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::enterSystemProperties(const std::vector & listSystemProperties) +{ + assert(!listSystemProperties.empty()); + + mMappedData.mSystemProperties = listSystemProperties; + + logInfo("DatabaseHandler::enterSystemProperties entered system properties"); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) +{ + assert(mainconnectionID!=0); + if (!existMainConnection(mainconnectionID)) + { + return (E_NON_EXISTENT); + } + + int16_t delay = calculateDelayForRoute(listConnectionID); + + //now we replace the data in the main connection object with the new one + mMappedData.mMainConnectionMap[mainconnectionID].listConnectionID = listConnectionID; + + if (changeDelayMainConnection(delay,mainconnectionID) == E_NO_CHANGE) + logError("DatabaseHandler::changeMainConnectionRouteDB error while changing mainConnectionDelay to ", delay); + + logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) +{ + assert(mainconnectionID!=0); + assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX); + + if (!existMainConnection(mainconnectionID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[mainconnectionID].connectionState, connectionState); + + logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); + if (mpDatabaseObserver) + mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].mainVolume, mainVolume); + + logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); + + if (mpDatabaseObserver) + mpDatabaseObserver->volumeChanged(sinkID, mainVolume); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].available, availability); + + logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); + + if (mpDatabaseObserver && sinkVisible(sinkID)) + mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) +{ + assert(domainID!=0); + assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX); + + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mDomainMap[domainID].state, domainState); + + logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].muteState, muteState); + + logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); + + if (mpDatabaseObserver) + mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; + std::vector::iterator elementIterator = sink.listMainSoundProperties.begin(); + for (;elementIterator != sink.listMainSoundProperties.end(); ++elementIterator) + { + if (elementIterator->type == soundProperty.type) + { + DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); + if(sink.cacheMainSoundProperties.size()) + sink.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + break; + } + } + + logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); + if (mpDatabaseObserver) + mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + am_Source_Database_s & source = mMappedData.mSourceMap.at(sourceID); + std::vector::iterator elementIterator = source.listMainSoundProperties.begin(); + for (;elementIterator != source.listMainSoundProperties.end(); ++elementIterator) + { + if (elementIterator->type == soundProperty.type) + { + DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); + if(source.cacheMainSoundProperties.size()) + source.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + break; + } + } + + logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); + + if (mpDatabaseObserver) + mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_RIE(mMappedData.mSourceMap[sourceID].available, availability); + + logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); + + if (mpDatabaseObserver && sourceVisible(sourceID)) + mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSystemPropertyDB(const am_SystemProperty_s & property) +{ + std::vector::iterator elementIterator = mMappedData.mSystemProperties.begin(); + for (;elementIterator != mMappedData.mSystemProperties.end(); ++elementIterator) + { + if (elementIterator->type == property.type) + DB_COND_UPDATE_RIE(elementIterator->value, property.value); + } + + logInfo("DatabaseHandler::changeSystemPropertyDB changed system property"); + + if (mpDatabaseObserver) + mpDatabaseObserver->systemPropertyChanged(property); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) +{ + assert(mainConnectionID!=0); + + if (!existMainConnection(mainConnectionID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mMainConnectionMap.erase(mainConnectionID); + + logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID); + if (mpDatabaseObserver) + { + mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); + mpDatabaseObserver->removedMainConnection(mainConnectionID); + } + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeSinkDB(const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + bool visible = sinkVisible(sinkID); + + mMappedData.mSinkMap.erase(sinkID); + // todo: Check the tables SinkMainSoundProperty and SinkMainNotificationConfiguration with 'visible' set to true + //if visible is true then delete SinkMainSoundProperty and SinkMainNotificationConfiguration ???? + logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); + + if (mpDatabaseObserver != NULL) + mpDatabaseObserver->removedSink(sinkID, visible); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeSourceDB(const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + bool visible = sourceVisible(sourceID); + + mMappedData.mSourceMap.erase(sourceID); + + // todo: Check the tables SourceMainSoundProperty and SourceMainNotificationConfiguration with 'visible' set to true + //if visible is true then delete SourceMainSoundProperty and SourceMainNotificationConfiguration ???? + + logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); + if (mpDatabaseObserver) + mpDatabaseObserver->removedSource(sourceID, visible); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeGatewayDB(const am_gatewayID_t gatewayID) +{ + assert(gatewayID!=0); + + if (!existGateway(gatewayID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mGatewayMap.erase(gatewayID); + + logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID); + if (mpDatabaseObserver) + mpDatabaseObserver->removeGateway(gatewayID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeConverterDB(const am_converterID_t converterID) +{ + assert(converterID!=0); + + if (!existConverter(converterID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mConverterMap.erase(converterID); + + logInfo("DatabaseHandler::removeConverterDB removed:", converterID); + if (mpDatabaseObserver) + mpDatabaseObserver->removeConverter(converterID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) +{ + assert(crossfaderID!=0); + + if (!existCrossFader(crossfaderID)) + { + return (E_NON_EXISTENT); + } + mMappedData.mCrossfaderMap.erase(crossfaderID); + + logInfo("DatabaseHandler::removeCrossfaderDB removed:", crossfaderID); + if (mpDatabaseObserver) + mpDatabaseObserver->removeCrossfader(crossfaderID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeDomainDB(const am_domainID_t domainID) +{ + assert(domainID!=0); + + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + mMappedData.mDomainMap.erase(domainID); + + logInfo("DatabaseHandler::removeDomainDB removed:", domainID); + if (mpDatabaseObserver) + mpDatabaseObserver->removeDomain(domainID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeSinkClassDB(const am_sinkClass_t sinkClassID) +{ + assert(sinkClassID!=0); + + if (!existSinkClass(sinkClassID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mSinkClassesMap.erase(sinkClassID); + + logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID); + if (mpDatabaseObserver) + mpDatabaseObserver->numberOfSinkClassesChanged(); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeSourceClassDB(const am_sourceClass_t sourceClassID) +{ + assert(sourceClassID!=0); + + if (!existSourceClass(sourceClassID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mSourceClassesMap.erase(sourceClassID); + logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID); + if (mpDatabaseObserver) + mpDatabaseObserver->numberOfSourceClassesChanged(); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::removeConnection(const am_connectionID_t connectionID) +{ + assert(connectionID!=0); + + mMappedData.mConnectionMap.erase(connectionID); + + logInfo("DatabaseHandler::removeConnection removed:", connectionID); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + am_Source_Database_s source = mMappedData.mSourceMap.at(sourceID); + classInfo.sourceClassID = source.sourceClassID; + + if (!existSourceClass(classInfo.sourceClassID)) + { + return (E_NON_EXISTENT); + } + am_SourceClass_s tmpClass = mMappedData.mSourceClassesMap.at(classInfo.sourceClassID); + classInfo = tmpClass; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + return (E_NON_EXISTENT); + + am_Sink_Database_s mappedSink = mMappedData.mSinkMap.at(sinkID); + if( true == mappedSink.reserved ) + return (E_NON_EXISTENT); + sinkData = mappedSink; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + return (E_NON_EXISTENT); + + am_Source_Database_s mappedSource = mMappedData.mSourceMap.at(sourceID); + if( true == mappedSource.reserved ) + return (E_NON_EXISTENT); + + sourceData = mappedSource; + + return (E_OK); +} + +am_Error_e am::CAmDatabaseHandlerMap::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const +{ + assert(mainConnectionID!=0); + if (!existMainConnection(mainConnectionID)) + { + return (E_NON_EXISTENT); + } + am_MainConnection_s temp = mMappedData.mMainConnectionMap.at(mainConnectionID); + mainConnectionData = temp; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) +{ + assert(sinkClass.sinkClassID!=0); + assert(!sinkClass.listClassProperties.empty()); + + //check if the ID already exists + if (!existSinkClass(sinkClass.sinkClassID)) + return (E_NON_EXISTENT); + + DB_COND_UPDATE_RIE(mMappedData.mSinkClassesMap[sinkClass.sinkClassID].listClassProperties, sinkClass.listClassProperties); + + logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) +{ + assert(sourceClass.sourceClassID!=0); + assert(!sourceClass.listClassProperties.empty()); + + //check if the ID already exists + if (!existSourceClass(sourceClass.sourceClassID)) + return (E_NON_EXISTENT); + + DB_COND_UPDATE_RIE(mMappedData.mSourceClassesMap[sourceClass.sourceClassID].listClassProperties, sourceClass.listClassProperties); + + logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + am_Sink_Database_s sink = mMappedData.mSinkMap.at(sinkID); + sinkClass.sinkClassID = sink.sinkClassID; + + if (!existSinkClass(sinkClass.sinkClassID)) + { + return (E_NON_EXISTENT); + } + am_SinkClass_s tmpSinkClass = mMappedData.mSinkClassesMap.at(sinkClass.sinkClassID); + sinkClass = tmpSinkClass; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const +{ + assert(gatewayID!=0); + if (!existGateway(gatewayID)) + { + return (E_NON_EXISTENT); + } + + gatewayData = mMappedData.mGatewayMap.at(gatewayID); + + return (E_OK); + +} + +am_Error_e CAmDatabaseHandlerMap::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const +{ + assert(converterID!=0); + if (!existConverter(converterID)) + { + return (E_NON_EXISTENT); + } + + converterData = mMappedData.mConverterMap.at(converterID); + + return (E_OK); + +} + +am_Error_e CAmDatabaseHandlerMap::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const +{ + assert(crossfaderID!=0); + if (!existCrossFader(crossfaderID)) + { + return (E_NON_EXISTENT); + } + + crossfaderData = mMappedData.mCrossfaderMap.at(crossfaderID); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const +{ + assert(domainID!=0); + listSinkID.clear(); + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + + std::unordered_map::const_iterator elementIterator = mMappedData.mSinkMap.begin(); + for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator) + { + if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID) + listSinkID.push_back(elementIterator->second.sinkID); + } + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const +{ + assert(domainID!=0); + listSourceID.clear(); + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + CAmMapSource::const_iterator elementIterator = mMappedData.mSourceMap.begin(); + for (;elementIterator != mMappedData.mSourceMap.end(); ++elementIterator) + { + if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID) + listSourceID.push_back(elementIterator->second.sourceID); + } + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listCrossfader) const +{ + assert(domainID!=0); + listCrossfader.clear(); + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + + CAmMapSource::const_iterator sourceIterator = mMappedData.mSourceMap.begin(); + for (;sourceIterator != mMappedData.mSourceMap.end(); ++sourceIterator) + { + if (domainID==sourceIterator->second.domainID) + { + CAmMapCrossfader::const_iterator elementIterator = mMappedData.mCrossfaderMap.begin(); + for (;elementIterator != mMappedData.mCrossfaderMap.end(); ++elementIterator) + { + if ( sourceIterator->second.sourceID==elementIterator->second.sourceID ) + listCrossfader.push_back(elementIterator->second.crossfaderID); + } + } + } + + return (E_OK); + +} + +am_Error_e CAmDatabaseHandlerMap::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const +{ + assert(domainID!=0); + listGatewaysID.clear(); + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + + CAmMapGateway::const_iterator elementIterator = mMappedData.mGatewayMap.begin(); + for (;elementIterator != mMappedData.mGatewayMap.end(); ++elementIterator) + { + if (domainID==elementIterator->second.controlDomainID) + listGatewaysID.push_back(elementIterator->second.gatewayID); + } + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) const +{ + assert(domainID!=0); + listConvertersID.clear(); + if (!existDomain(domainID)) + { + return (E_NON_EXISTENT); + } + + CAmMapConverter::const_iterator elementIterator = mMappedData.mConverterMap.begin(); + for (;elementIterator != mMappedData.mConverterMap.end(); ++elementIterator) + { + if (domainID==elementIterator->second.domainID) + listConvertersID.push_back(elementIterator->second.converterID); + } + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainConnections(std::vector & listMainConnections) const +{ + listMainConnections.clear(); + + CAmMapMainConnection::const_iterator elementIterator = mMappedData.mMainConnectionMap.begin(); + for (;elementIterator != mMappedData.mMainConnectionMap.end(); ++elementIterator) + { + listMainConnections.push_back(elementIterator->second); + } + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListDomains(std::vector & listDomains) const +{ + listDomains.clear(); + + CAmMapDomain::const_iterator elementIterator = mMappedData.mDomainMap.begin(); + for (;elementIterator != mMappedData.mDomainMap.end(); ++elementIterator) + { + if( 0==elementIterator->second.reserved ) + listDomains.push_back(elementIterator->second); + } + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListConnections(std::vector & listConnections) const +{ + listConnections.clear(); + + CAmMapConnection::const_iterator elementIterator = mMappedData.mConnectionMap.begin(); + for (;elementIterator != mMappedData.mConnectionMap.end(); ++elementIterator) + { + if( 0==elementIterator->second.reserved ) + listConnections.push_back(elementIterator->second); + } + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSinks(std::vector & listSinks) const +{ + listSinks.clear(); + + std::for_each(mMappedData.mSinkMap.begin(), mMappedData.mSinkMap.end(), [&](const std::pair& ref) { + if( 0==ref.second.reserved ) + listSinks.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSources(std::vector & listSources) const +{ + listSources.clear(); + + std::for_each(mMappedData.mSourceMap.begin(), mMappedData.mSourceMap.end(), [&](const std::pair& ref) { + if( 0==ref.second.reserved ) + { + listSources.push_back(ref.second); + } + }); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSourceClasses(std::vector & listSourceClasses) const +{ + listSourceClasses.clear(); + + std::for_each(mMappedData.mSourceClassesMap.begin(), mMappedData.mSourceClassesMap.end(), [&](const std::pair& ref) { + listSourceClasses.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListCrossfaders(std::vector & listCrossfaders) const +{ + listCrossfaders.clear(); + + std::for_each(mMappedData.mCrossfaderMap.begin(), mMappedData.mCrossfaderMap.end(), [&](const std::pair& ref) { + listCrossfaders.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListGateways(std::vector & listGateways) const +{ + listGateways.clear(); + + std::for_each(mMappedData.mGatewayMap.begin(), mMappedData.mGatewayMap.end(), [&](const std::pair& ref) { + listGateways.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListConverters(std::vector & listConverters) const +{ + listConverters.clear(); + + std::for_each(mMappedData.mConverterMap.begin(), mMappedData.mConverterMap.end(), [&](const std::pair& ref) { + listConverters.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSinkClasses(std::vector & listSinkClasses) const +{ + listSinkClasses.clear(); + + std::for_each(mMappedData.mSinkClassesMap.begin(), mMappedData.mSinkClassesMap.end(), [&](const std::pair& ref) { + listSinkClasses.push_back(ref.second); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListVisibleMainConnections(std::vector & listConnections) const +{ + listConnections.clear(); + std::for_each(mMappedData.mMainConnectionMap.begin(), mMappedData.mMainConnectionMap.end(), [&](const std::pair& ref) { + listConnections.emplace_back(); + ref.second.getMainConnectionType(listConnections.back()); + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSinks(std::vector & listMainSinks) const +{ + listMainSinks.clear(); + std::for_each(mMappedData.mSinkMap.begin(), mMappedData.mSinkMap.end(), [&](const std::pair& ref) { + if( 0==ref.second.reserved && 1==ref.second.visible ) + { + listMainSinks.emplace_back(); + ref.second.getSinkType(listMainSinks.back()); + } + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSources(std::vector & listMainSources) const +{ + listMainSources.clear(); + std::for_each(mMappedData.mSourceMap.begin(), mMappedData.mSourceMap.end(), [&](const std::pair& ref) { + if( 0==ref.second.reserved && 1==ref.second.visible ) + { + listMainSources.emplace_back(); + ref.second.getSourceType(listMainSources.back()); + } + }); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return E_NON_EXISTENT; + + const am_Sink_s & sink = mMappedData.mSinkMap.at(sinkID); + listSoundProperties = sink.listMainSoundProperties; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return E_NON_EXISTENT; + + const am_Source_s & source = mMappedData.mSourceMap.at(sourceID); + listSourceProperties = source.listMainSoundProperties; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return E_NON_EXISTENT; + + const am_Sink_Database_s & sink = mMappedData.mSinkMap.at(sinkID); + listSoundproperties = sink.listSoundProperties; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return E_NON_EXISTENT; + + const am_Source_Database_s & source = mMappedData.mSourceMap.at(sourceID); + listSoundproperties = source.listSoundProperties; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSystemProperties(std::vector & listSystemProperties) const +{ + listSystemProperties = mMappedData.mSystemProperties; + return (E_OK); +} + +am_Error_e am::CAmDatabaseHandlerMap::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const +{ + if (!existSink(sinkID)) + return E_NON_EXISTENT; + const am_Sink_s & sink = mMappedData.mSinkMap.at(sinkID); + listConnectionFormats = sink.listConnectionFormats; + + return (E_OK); +} + +am_Error_e am::CAmDatabaseHandlerMap::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const +{ + if (!existSource(sourceID)) + return E_NON_EXISTENT; + const am_Source_s & source = mMappedData.mSourceMap.at(sourceID); + listConnectionFormats = source.listConnectionFormats; + + return (E_OK); +} + +am_Error_e am::CAmDatabaseHandlerMap::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_NON_EXISTENT; + } + listConnectionFormat = iter->second; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const +{ + assert(mainConnectionID!=0); + if (!existMainConnection(mainConnectionID)) + return E_NON_EXISTENT; + delay = -1; + + const am_MainConnection_s & mainConnection = mMappedData.mMainConnectionMap.at(mainConnectionID); + delay = mainConnection.delay; + + if (delay == -1) + return (E_NOT_POSSIBLE); + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) +{ + assert(connectionID!=0); + if (!existMainConnection(connectionID)) + return (E_NON_EXISTENT); + DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[connectionID].delay, delay); + if (mpDatabaseObserver) + mpDatabaseObserver->timingInformationChanged(connectionID, delay); + return (E_OK); +} + +/** + * checks for a certain mainConnection + * @param mainConnectionID to be checked for + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existMainConnection(const am_mainConnectionID_t mainConnectionID) const +{ + return existsObjectWithKeyInMap(mainConnectionID, mMappedData.mMainConnectionMap); +} + +/** + * checks for a certain Source + * @param sourceID to be checked for + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existSource(const am_sourceID_t sourceID) const +{ + am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=source ) + return (0==source->reserved); + + return false; +} + +/** + * checks if a source name or ID exists + * @param sourceID the sourceID + * @param name the name + * @return true if it exits + */ +bool CAmDatabaseHandlerMap::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const +{ + return sourceWithNameOrID(sourceID, name); +} + +/** + * checks if a name exits + * @param name the name + * @return true if it exits + */ +bool CAmDatabaseHandlerMap::existSourceName(const std::string & name) const +{ + return existSourceNameOrID(mMappedData.mCurrentSourceID.mMax, name); +} + +/** + * checks for a certain Sink + * @param sinkID to be checked for + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existSink(const am_sinkID_t sinkID) const +{ + bool returnVal = false; + CAmMapSink::const_iterator elementIterator = mMappedData.mSinkMap.begin(); + for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator) + { + if( 0==elementIterator->second.reserved && + sinkID==elementIterator->second.sinkID) + { + returnVal = true; + break; + } + } + return (returnVal); +} + +/** + * returns source with given ID or the name if exists + * @param sourceID the ID + * @param name the name + * @return source structure if exists. + */ +const CAmDatabaseHandlerMap::am_Source_Database_s * CAmDatabaseHandlerMap::sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const +{ + std::function comparator = [&](const CAmDatabaseHandlerMap::am_Source_Database_s & source)->bool{ + return ( 0==source.reserved && + (sourceID==source.sourceID || name.compare(source.name)==0)); + }; + return objectMatchingPredicate(mMappedData.mSourceMap, comparator); +} + +/** + * returns sink with given ID or the name if exists + * @param sinkID the ID + * @param name the name + * @return sink structure if exists. + */ +const CAmDatabaseHandlerMap::am_Sink_Database_s * CAmDatabaseHandlerMap::sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const +{ + std::function comparator = [&](const CAmDatabaseHandlerMap::am_Sink_Database_s & sink)->bool{ + return ( 0==sink.reserved && + (sinkID==sink.sinkID || name.compare(sink.name)==0)); + }; + return objectMatchingPredicate(mMappedData.mSinkMap, comparator); +} + +/** + * 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 CAmDatabaseHandlerMap::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const +{ + return sinkWithNameOrID( sinkID, name)!=NULL; +} + +/** + * checks if a sink with the name exists + * @param name the name + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existSinkName(const std::string & name) const +{ + return existSinkNameOrID(mMappedData.mCurrentSinkID.mMax, name); +} + +/** + * checks for a certain domain + * @param domainID to be checked for + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existDomain(const am_domainID_t domainID) const +{ + am_Domain_Database_s const * source = objectForKeyIfExistsInMap(domainID, mMappedData.mDomainMap); + if( NULL!=source ) + return (0==source->reserved); + + return false; +} + +/** + * checks for certain gateway + * @param gatewayID to be checked for + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existGateway(const am_gatewayID_t gatewayID) const +{ + return existsObjectWithKeyInMap(gatewayID, mMappedData.mGatewayMap); +} + +bool CAmDatabaseHandlerMap::existConverter(const am_converterID_t converterID) const +{ + return existsObjectWithKeyInMap(converterID, mMappedData.mConverterMap); +} + +am_Error_e CAmDatabaseHandlerMap::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const +{ + assert(sourceID!=0); + domainID=0; + + am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=source ) + { + domainID = source->domainID; + return E_OK; + } + return E_NON_EXISTENT; +} + +am_Error_e am::CAmDatabaseHandlerMap::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const +{ + assert(sinkID!=0); + domainID=0; + + am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=source ) + { + domainID = source->domainID; + return E_OK; + } + return E_NON_EXISTENT; +} + +am_Error_e am::CAmDatabaseHandlerMap::getDomainOfCrossfader(const am_converterID_t crossfader, am_domainID_t & domainID) const +{ + assert(crossfader!=0); + domainID=0; + + am_Crossfader_Database_s const * cross = objectForKeyIfExistsInMap(crossfader, mMappedData.mCrossfaderMap); + if( NULL!=cross ) + { + getDomainOfSource(cross->sinkID_A,domainID); + return E_OK; + } + return E_NON_EXISTENT; +} + +/** + * checks for certain SinkClass + * @param sinkClassID + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existSinkClass(const am_sinkClass_t sinkClassID) const +{ + return existsObjectWithKeyInMap(sinkClassID, mMappedData.mSinkClassesMap); +} + +/** + * checks for certain sourceClass + * @param sourceClassID + * @return true if it exists + */ +bool CAmDatabaseHandlerMap::existSourceClass(const am_sourceClass_t sourceClassID) const +{ + return existsObjectWithKeyInMap(sourceClassID, mMappedData.mSourceClassesMap); +} + +am_Error_e CAmDatabaseHandlerMap::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) +{ + assert(connectionID!=0); + if(!existConnectionID(connectionID)) + return E_NON_EXISTENT; + + mMappedData.mConnectionMap[connectionID].delay = delay; + + //now we need to find all mainConnections that use the changed connection and update their timing + + //first get all route tables for all mainconnections + am_Error_e error = E_OK; + CAmMapMainConnection::const_iterator iter = mMappedData.mMainConnectionMap.begin(); + for(; iter != mMappedData.mMainConnectionMap.end(); ++iter) + { + const am_MainConnection_s & mainConnection = iter->second; + if (std::find(mainConnection.listConnectionID.begin(), mainConnection.listConnectionID.end(), connectionID) != mainConnection.listConnectionID.end()) + { + // Got it. + error = changeDelayMainConnection(calculateMainConnectionDelay(mainConnection.mainConnectionID), mainConnection.mainConnectionID); + } + } + + return error; +} + +am_Error_e CAmDatabaseHandlerMap::changeConnectionFinal(const am_connectionID_t connectionID) +{ + assert(connectionID!=0); + am_Connection_Database_s const * connection = objectForKeyIfExistsInMap(connectionID, mMappedData.mConnectionMap); + if( NULL!=connection ) + { + mMappedData.mConnectionMap.at(connectionID).reserved = false; + return E_OK; + } + return (E_NON_EXISTENT); +} + +am_timeSync_t CAmDatabaseHandlerMap::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const +{ + assert(mainConnectionID!=0); + if (!existMainConnection(mainConnectionID)) + return -1; + const am_MainConnection_s & mainConnection = mMappedData.mMainConnectionMap.at(mainConnectionID); + am_timeSync_t delay = 0; + std::vector::const_iterator iter = mainConnection.listConnectionID.begin(); + for(;iterdelay, static_cast(0)); + } + } + return (delay == 0 ? -1 : std::min(delay, static_cast(SHRT_MAX))); +} + +/** + * registers the Observer at the Database + * @param iObserver pointer to the observer + */ +void CAmDatabaseHandlerMap::registerObserver(CAmDatabaseObserver *iObserver) +{ + assert(iObserver!=NULL); + mpDatabaseObserver = iObserver; +} + +/** + * gives information about the visibility of a source + * @param sourceID the sourceID + * @return true if source is visible + */ +bool CAmDatabaseHandlerMap::sourceVisible(const am_sourceID_t sourceID) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return false; + am_Source_Database_s source = mMappedData.mSourceMap.at(sourceID); + return source.visible; +} + +/** + * gives information about the visibility of a sink + * @param sinkID the sinkID + * @return true if source is visible + */ +bool CAmDatabaseHandlerMap::sinkVisible(const am_sinkID_t sinkID) const +{ + am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=source ) + { + if(0==source->reserved) + return source->visible; + } + return false; +} + +/** + * 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 CAmDatabaseHandlerMap::existConnection(const am_Connection_s & connection) const +{ + am_Connection_Database_s const * connectionObject = objectMatchingPredicate(mMappedData.mConnectionMap, [&](const am_Connection_Database_s & obj){ + return false==obj.reserved && + connection.sinkID == obj.sinkID && + connection.sourceID == obj.sourceID && + connection.connectionFormat == obj.connectionFormat; + }); + return ( NULL!=connectionObject ); +} + +/** + * checks if a connection with the given ID exists + * @param connectionID + * @return true if connection exits + */ +bool CAmDatabaseHandlerMap::existConnectionID(const am_connectionID_t connectionID) const +{ + am_Connection_Database_s const * connection = objectForKeyIfExistsInMap(connectionID, mMappedData.mConnectionMap); + if( NULL!=connection ) + { + return (0==connection->reserved); + } + return false; +} + +/** + * checks if a CrossFader exists + * @param crossfaderID the ID of the crossfader to be checked + * @return true if exists + */ +bool CAmDatabaseHandlerMap::existCrossFader(const am_crossfaderID_t crossfaderID) const +{ + return existsObjectWithKeyInMap(crossfaderID, mMappedData.mCrossfaderMap); +} + +am_Error_e CAmDatabaseHandlerMap::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const +{ + am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=source ) + { + sourceState = source->sourceState; + return (E_OK); + } + else + { + sourceState = SS_UNKNNOWN; + return (E_NON_EXISTENT); + } +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) +{ + assert(sourceID!=0); + assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX); + if(existSource(sourceID)) + { + mMappedData.mSourceMap.at(sourceID).sourceState = sourceState; + return (E_OK); + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const { + assert(sinkID!=0); + + am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=source ) + { + mainVolume = source->mainVolume; + return (E_OK); + } + mainVolume = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const +{ + assert(sinkID!=0); + + am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=source ) + { + volume = source->volume; + return (E_OK); + } + volume = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const +{ + assert(sourceID!=0); + am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=source ) + { + volume = source->volume; + return (E_OK); + } + volume = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t & value) const +{ + assert(sinkID!=0); + + am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=pObject ) + { + if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) + { + std::vector::const_iterator iter = pObject->listSoundProperties.begin(); + for(; iterlistSoundProperties.end(); ++iter) + pObject->cacheSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheSoundProperties.find(propertyType); + if(it!=pObject->cacheSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + value = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t & value) const +{ + assert(sourceID!=0); + + am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=pObject ) + { + if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) + { + std::vector::const_iterator iter = pObject->listSoundProperties.begin(); + for(; iterlistSoundProperties.end(); ++iter) + pObject->cacheSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheSoundProperties.find(propertyType); + if(it!=pObject->cacheSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + value = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sinkID!=0); + + am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=pObject ) + { + if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) + { + std::vector::const_iterator iter = pObject->listMainSoundProperties.begin(); + for(; iterlistMainSoundProperties.end(); ++iter) + pObject->cacheMainSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheMainSoundProperties.find(propertyType); + if(it!=pObject->cacheMainSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + value = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sourceID!=0); + + am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=pObject ) + { + if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) + { + std::vector::const_iterator iter = pObject->listMainSoundProperties.begin(); + for(; iterlistMainSoundProperties.end(); ++iter) + pObject->cacheMainSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheMainSoundProperties.find(propertyType); + if(it!=pObject->cacheMainSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + + value = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const +{ + assert(domainID!=0); + + am_Domain_Database_s const * source = objectForKeyIfExistsInMap(domainID, mMappedData.mDomainMap); + if( NULL!=source ) + { + state = source->state; + return (E_OK); + } + state = DS_UNKNOWN; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::peekDomain(const std::string & name, am_domainID_t & domainID) +{ + domainID=0; + + am_Domain_Database_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const am_Domain_Database_s & obj){ + return name.compare(obj.name)==0; + }); + + if( NULL != reservedDomain ) + { + domainID = reservedDomain->domainID; + return E_OK; + } + else + { + int16_t nextID = 0; + if( mMappedData.increaseID( nextID, mMappedData.mCurrentDomainID) ) + { + domainID = nextID; + am_Domain_Database_s domain; + domain.domainID = nextID; + domain.name = name; + domain.reserved = 1; + mMappedData.mDomainMap[nextID] = domain; + return E_OK; + } + return E_UNKNOWN; + } + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::peekSink(const std::string & name, am_sinkID_t & sinkID) +{ + am_Sink_Database_s const *reservedSink = objectMatchingPredicate(mMappedData.mSinkMap, [&](const am_Sink_Database_s & obj){ + return name.compare(obj.name)==0; + }); + if( NULL!=reservedSink ) + { + sinkID = reservedSink->sinkID; + return E_OK; + } + else + { + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID)) + { + if(mFirstStaticSink) + { + nextID = DYNAMIC_ID_BOUNDARY; + mFirstStaticSink = false; + } + sinkID = nextID; + am_Sink_Database_s object; + object.sinkID = nextID; + object.name = name; + object.reserved = 1; + mMappedData.mSinkMap[nextID] = object; + return E_OK; + } + return E_UNKNOWN; + } +} + +am_Error_e CAmDatabaseHandlerMap::peekSource(const std::string & name, am_sourceID_t & sourceID) +{ + am_Source_Database_s const *reservedSrc = objectMatchingPredicate(mMappedData.mSourceMap, [&](const am_Source_Database_s & obj){ + return name.compare(obj.name)==0; + }); + if( NULL!=reservedSrc ) + { + sourceID = reservedSrc->sourceID; + return E_OK; + } + else + { + int16_t nextID = 0; + if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID)) + { + if(mFirstStaticSource) + { +// nextID = DYNAMIC_ID_BOUNDARY; + mFirstStaticSource = false; + } + sourceID = nextID; + am_Source_Database_s object; + object.sourceID = nextID; + object.name = name; + object.reserved = 1; + mMappedData.mSourceMap[nextID] = object; + return E_OK; + } + else + return E_UNKNOWN; + } +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mSinkMap[sinkID].volume = volume; + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + mMappedData.mSourceMap[sourceID].volume = volume; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + am_Source_Database_s & source = mMappedData.mSourceMap[sourceID]; + std::vector::iterator iter = source.listSoundProperties.begin(); + for(; itertype ) + { + iter->value = soundProperty.value; + if(source.cacheSoundProperties.size()) + source.cacheSoundProperties[soundProperty.type] = soundProperty.value; + return (E_OK); + } + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; + std::vector::iterator iter = sink.listSoundProperties.begin(); + for(; itertype ) + { + iter->value = soundProperty.value; + if(sink.cacheSoundProperties.size()) + sink.cacheSoundProperties[soundProperty.type] = soundProperty.value; + return (E_OK); + } + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) +{ + assert(crossfaderID!=0); + assert(hotsink!=HS_UNKNOWN); + + if (!existCrossFader(crossfaderID)) + { + return (E_NON_EXISTENT); + } + + mMappedData.mCrossfaderMap[crossfaderID].hotSink = hotsink; + return (E_OK); +} + +bool CAmDatabaseHandlerMap::isComponentConnected(const am_Gateway_s & gateway) const +{ + bool ret = isConnected(gateway); + return ret; +} + +bool CAmDatabaseHandlerMap::isComponentConnected(const am_Converter_s & converter) const +{ + bool ret = isConnected(converter); + return ret; +} + +am_Error_e am::CAmDatabaseHandlerMap::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID) +{ + if (name.empty()) + return (E_NON_EXISTENT); + am_SinkClass_Database_s const *reserved = objectMatchingPredicate(mMappedData.mSinkClassesMap, [&](const am_SinkClass_Database_s & obj){ + return name.compare(obj.name)==0; + }); + if( NULL!=reserved ) + { + sinkClassID = reserved->sinkClassID; + return E_OK; + } + return (E_NON_EXISTENT); +} + +am_Error_e am::CAmDatabaseHandlerMap::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID) +{ + if (name.empty()) + return (E_NON_EXISTENT); + am_SourceClass_Database_s const *ptrSource = objectMatchingPredicate(mMappedData.mSourceClassesMap, [&](const am_SourceClass_Database_s & obj){ + return name.compare(obj.name)==0; + }); + if( NULL!=ptrSource ) + { + sourceClassID = ptrSource->sourceClassID; + return E_OK; + } + return (E_NON_EXISTENT); +} + + +am_Error_e CAmDatabaseHandlerMap::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + DB_COND_UPDATE_INIT; + am_sourceClass_t sourceClassOut(sourceClassID); + std::vector listMainSoundPropertiesOut(listMainSoundProperties); + //check if sinkClass needs to be changed + + std::unordered_map::iterator iter = mMappedData.mSourceMap.begin(); + for(; iter!=mMappedData.mSourceMap.end(); ++iter) + { + if( iter->second.sourceID == sourceID ) + { + if (sourceClassID != 0) + { + DB_COND_UPDATE(iter->second.sourceClassID, sourceClassID); + } + else if (0 == iter->second.reserved) + { + sourceClassOut = iter->second.sourceClassID; + } + break; + } + } + + //check if soundProperties need to be updated + if (!listSoundProperties.empty()) + { + mMappedData.mSourceMap.at(sourceID).listSoundProperties = listSoundProperties; + mMappedData.mSourceMap.at(sourceID).cacheSoundProperties.clear(); + } + + //check if we have to update the list of connectionformats + if (!listConnectionFormats.empty()) + { + mMappedData.mSourceMap.at(sourceID).listConnectionFormats = listConnectionFormats; + } + + //then we need to check if we need to update the listMainSoundProperties + if (sourceVisible(sourceID)) + { + if (!listMainSoundProperties.empty()) + { + DB_COND_UPDATE(mMappedData.mSourceMap.at(sourceID).listMainSoundProperties, listMainSoundProperties); + mMappedData.mSourceMap.at(sourceID).cacheMainSoundProperties.clear(); + } + else + { + getListMainSourceSoundProperties(sourceID,listMainSoundPropertiesOut); + } + } + + if (DB_COND_ISMODIFIED) + { + logInfo("DatabaseHandler::changeSource changed changeSource of source:", sourceID); + + if (mpDatabaseObserver != NULL) + { + mpDatabaseObserver->sourceUpdated(sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID)); + } + } + + return (E_OK); + +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + assert(sinkID!=0); + + DB_COND_UPDATE_INIT; + am_sinkClass_t sinkClassOut(sinkClassID); + std::vector listMainSoundPropertiesOut(listMainSoundProperties); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + + std::unordered_map::iterator iter = mMappedData.mSinkMap.begin(); + for(; iter!=mMappedData.mSinkMap.end(); ++iter) + { + if (iter->second.sinkID == sinkID) + { + if (sinkClassID != 0) + { + DB_COND_UPDATE(iter->second.sinkClassID, sinkClassID); + } + else if (0 == iter->second.reserved) + { + sinkClassOut = iter->second.sinkClassID; + } + break; + } + } + + //check if soundProperties need to be updated + if (!listSoundProperties.empty()) + { + mMappedData.mSinkMap.at(sinkID).listSoundProperties = listSoundProperties; + mMappedData.mSinkMap.at(sinkID).cacheSoundProperties.clear(); + } + + //check if we have to update the list of connectionformats + if (!listConnectionFormats.empty()) + { + mMappedData.mSinkMap.at(sinkID).listConnectionFormats = listConnectionFormats; + } + + //then we need to check if we need to update the listMainSoundProperties + if (sinkVisible(sinkID)) + { + if (!listMainSoundProperties.empty()) + { + DB_COND_UPDATE(mMappedData.mSinkMap.at(sinkID).listMainSoundProperties, listMainSoundProperties); + mMappedData.mSinkMap.at(sinkID).cacheMainSoundProperties.clear(); + } + else //read out the properties + { + getListMainSinkSoundProperties(sinkID,listMainSoundPropertiesOut); + } + } + + if (DB_COND_ISMODIFIED) + { + logInfo("DatabaseHandler::changeSink changed changeSink of sink:", sinkID); + + if (mpDatabaseObserver != NULL) + { + mpDatabaseObserver->sinkUpdated(sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID)); + } + } + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences + listMainNotificationConfigurations.clear(); + + listMainNotificationConfigurations = mMappedData.mSinkMap.at(sinkID).listMainNotificationConfigurations; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences + + listMainNotificationConfigurations = mMappedData.mSourceMap.at(sourceID).listMainNotificationConfigurations; + + return (E_OK); +} + +bool changeMainNotificationConfiguration(std::vector & listMainNotificationConfigurations, + const am_NotificationConfiguration_s & mainNotificationConfiguration) +{ + std::vector::iterator iter = listMainNotificationConfigurations.begin(); + for(; itertype ) + { +#ifdef WITH_DATABASE_CHANGE_CHECK + if( iter->status == mainNotificationConfiguration.status && iter->parameter == mainNotificationConfiguration.parameter ) + return false; +#endif + *iter = mainNotificationConfiguration; + return true; + } + } + return false; +} + +am_Error_e CAmDatabaseHandlerMap::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + if(!changeMainNotificationConfiguration(mMappedData.mSinkMap.at(sinkID).listMainNotificationConfigurations, mainNotificationConfiguration)) + return (E_NO_CHANGE); + + logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); + + if (mpDatabaseObserver) + mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + if(!changeMainNotificationConfiguration(mMappedData.mSourceMap.at(sourceID).listMainNotificationConfigurations, mainNotificationConfiguration)) + return (E_NO_CHANGE); + + logInfo("DatabaseHandler::changeMainSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); + + if (mpDatabaseObserver) + mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration); + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) +{ + assert(gatewayID!=0); + + if (!existGateway(gatewayID)) + { + return (E_NON_EXISTENT); + } + + if (!listSourceConnectionFormats.empty()) + { + mMappedData.mGatewayMap.at(gatewayID).listSourceFormats = listSourceConnectionFormats; + } + + if (!listSinkConnectionFormats.empty()) + { + mMappedData.mGatewayMap.at(gatewayID).listSinkFormats = listSinkConnectionFormats; + } + + if (!convertionMatrix.empty()) + { + mListConnectionFormat.clear(); + mListConnectionFormat.insert(std::make_pair(gatewayID, convertionMatrix)); + } + + logInfo("DatabaseHandler::changeGatewayDB changed Gateway with ID", gatewayID); + + //todo: check if observer needs to be adopted. + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) +{ + assert(converterID!=0); + + if (!existConverter(converterID)) + { + return (E_NON_EXISTENT); + } + + if (!listSourceConnectionFormats.empty()) + { + mMappedData.mConverterMap.at(converterID).listSourceFormats = listSourceConnectionFormats; + } + + if (!listSinkConnectionFormats.empty()) + { + mMappedData.mConverterMap.at(converterID).listSinkFormats = listSinkConnectionFormats; + } + + if (!convertionMatrix.empty()) + { + mListConnectionFormat.clear(); + mListConnectionFormat.insert(std::make_pair(converterID, convertionMatrix)); + } + + logInfo("DatabaseHandler::changeConverterDB changed Gateway with ID", converterID); + + //todo: check if observer needs to be adopted. + return (E_OK); +} + +bool changeNotificationConfiguration(std::vector & listNotificationConfigurations, const am_NotificationConfiguration_s & notificationConfiguration) +{ + bool changed = false; + std::vector::iterator iter = listNotificationConfigurations.begin(); + for(; itertype ) + { + iter->status = notificationConfiguration.status; + iter->parameter = notificationConfiguration.parameter; + changed |= true; + } + } + return changed; +} + +am_Error_e CAmDatabaseHandlerMap::changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s notificationConfiguration) +{ + assert(sinkID!=0); + + if (!existSink(sinkID)) + { + return (E_NON_EXISTENT); + } + if(!changeNotificationConfiguration(mMappedData.mSinkMap.at(sinkID).listNotificationConfigurations, notificationConfiguration)) + return (E_NO_CHANGE); + + logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); + + //todo:: inform obsever here... + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s notificationConfiguration) +{ + assert(sourceID!=0); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + if(!changeNotificationConfiguration(mMappedData.mSourceMap.at(sourceID).listNotificationConfigurations, notificationConfiguration)) + return (E_NO_CHANGE); + + logInfo("DatabaseHandler::changeSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); + + //todo:: implement observer function + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::enumerateSources(std::function cb) const +{ + for(auto it = mMappedData.mSourceMap.begin(); it!=mMappedData.mSourceMap.end(); it++) + { + const am_Source_Database_s *pObject = &it->second; + if( 0==pObject->reserved ) + cb(*pObject); + } + return E_OK; +} + +am_Error_e CAmDatabaseHandlerMap::enumerateSinks(std::function cb) const +{ + for(auto it = mMappedData.mSinkMap.begin(); it!=mMappedData.mSinkMap.end(); it++) + { + const am_Sink_Database_s *pObject = &it->second; + if( 0==pObject->reserved ) + cb(*pObject); + } + return E_OK; +} + +am_Error_e CAmDatabaseHandlerMap::enumerateGateways(std::function cb) const +{ + for(auto it = mMappedData.mGatewayMap.begin(); it!=mMappedData.mGatewayMap.end(); it++) + { + const am_Gateway_s *pObject = &it->second; + cb(*pObject); + } + return E_OK; +} + +am_Error_e CAmDatabaseHandlerMap::enumerateConverters(std::function cb) const +{ + for(auto it = mMappedData.mConverterMap.begin(); it!=mMappedData.mConverterMap.end(); it++) + { + const am_Converter_s *pObject = &it->second; + cb(*pObject); + } + return E_OK; +} + +} diff --git a/AudioManagerCore/src/CAmDatabaseObserver.cpp b/AudioManagerCore/src/CAmDatabaseObserver.cpp new file mode 100644 index 0000000..acac639 --- /dev/null +++ b/AudioManagerCore/src/CAmDatabaseObserver.cpp @@ -0,0 +1,242 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmDatabaseObserver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmDatabaseObserver.h" +#include +#include +#include +#include +#include +#include "CAmCommandSender.h" +#include "CAmRoutingSender.h" +#include "CAmTelnetServer.h" +#include "CAmDltWrapper.h" +#include "CAmSerializer.h" + +namespace am { + +CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : + mCommandSender(iCommandSender), // + mRoutingSender(iRoutingSender), // + mTelnetServer(NULL), // + 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::newConverter(const am_Converter_s& coverter) +{ + (void) coverter; + //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::removeConverter(const am_converterID_t converterID) +{ + (void) converterID; + //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); +} + +void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) +{ + if (visible) + mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sinkID, sinkClassID, listMainSoundProperties); +} + +void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) +{ + if (visible) + mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sourceID, sourceClassID, listMainSoundProperties); +} + +void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + mSerializer.asyncCall (mCommandSender, &CAmCommandSender::cbSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration); +} + +void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration); +} + +} diff --git a/AudioManagerCore/src/CAmLog.cpp b/AudioManagerCore/src/CAmLog.cpp new file mode 100644 index 0000000..f68f660 --- /dev/null +++ b/AudioManagerCore/src/CAmLog.cpp @@ -0,0 +1,101 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmLog.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmLog.h" + + +void CAmLog::CAmFileLogger::generateLogFilename(std::string &result) +{ + static uint32_t logFileID = 1; + time_t rawtime; + time (&rawtime); + + std::ostringstream stream; + stream << DEFAULT_LOG_FOLDER << DEFAULT_LOGFILE_PREFIX << logFileID << "_" << rawtime << DEFAULT_LOGFILE_EXT; + logFileID++; + result = stream.str(); +} + +CAmLog::CAmFileLogger::~CAmFileLogger() +{ + if (mOutputStream) + { + std::ofstream* of = static_cast(mOutputStream); + of->close(); + DEL(mOutputStream) + } +} + +CAmLog::CAmLog(const eCAmLogType type ):mLogType(type) +{ + instantiateLogger(type); +} + +CAmLog::CAmLog():mLogType(eCAmLogStdout) +{ + instantiateLogger((const eCAmLogType)eCAmLogStdout); +} + +CAmLog::~CAmLog() +{ + releaseLogger(); +} + +void CAmLog::releaseLogger() +{ + if(mLogger) + DEL(mLogger) +} + +void CAmLog::instantiateLogger( const eCAmLogType type) +{ + if( eCAmLogStdout == type ) + mLogger = new CAmStdOutLogger(); + else if( eCAmLogFile == type ) + { + std::string filename(""); + CAmLog::CAmFileLogger::generateLogFilename(filename); + mLogger = new CAmFileLogger(filename); + } +} + +CAmLog *CAmLog::getDefaultLog() +{ + static CAmLog theInstance; + return &theInstance; +} + +void CAmLog::setLogType( const eCAmLogType type) +{ + if(mLogType!=type) + { + mLogType = type; + releaseLogger(); + instantiateLogger(type); + } +} + +eCAmLogType CAmLog::getLogType() const +{ + return mLogType; +} diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp new file mode 100644 index 0000000..f98bf11 --- /dev/null +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -0,0 +1,884 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014 + * + * \file CAmRouter.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include +#include +#include +#include +#include "CAmRouter.h" +#include "IAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "CAmDltWrapper.h" + + + +namespace am { + + +template void getMergeConnectionFormats(const X * element, + const am_CustomConnectionFormat_t connectionFormat, + const std::vector & listConnectionFormats, + std::vector & outListMergeConnectionFormats) +{ + std::vector listRestrictedConnectionFormats; + CAmRouter::getRestrictedOutputFormats(element->convertionMatrix, + element->listSourceFormats, + element->listSinkFormats, + connectionFormat, + listRestrictedConnectionFormats); + std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input + std::insert_iterator > inserter(outListMergeConnectionFormats, outListMergeConnectionFormats.begin()); + set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter); +} + + +CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : + mpDatabaseHandler(iDatabaseHandler), // + mpControlSender(iSender), + mOnlyFreeConversionNodes(false), + mRoutingGraph(), + mNodeListSources(), + mNodeListSinks(), + mNodeListGateways(), + mNodeListConverters() +{ + assert(mpDatabaseHandler); + assert(mpControlSender); +} + +CAmRouter::~CAmRouter() +{ +} + +/** + * returns the best route between a source and a sink + * @param onlyfree if true only free gateways are used + * @param sourceID + * @param sinkID + * @param returnList this list contains a set of routes + * @return E_OK in case of success + */ +am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) +{ + returnList.clear(); + am_Source_s source; + am_Sink_s sink; + am_Error_e error = mpDatabaseHandler->getSourceInfoDB(sourceID, source); + if(error!=E_OK) + return error; + error = mpDatabaseHandler->getSinkInfoDB(sinkID, sink); + if(error!=E_OK) + return error; + error = getRoute(onlyfree, source, sink, returnList); + return error; +} + + +am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) +{ + am_Error_e error; + load(onlyfree); + + CAmRoutingNode* pRootSource = sourceNodeWithID(aSource.sourceID); + CAmRoutingNode* pRootSink = sinkNodeWithID(aSink.sinkID); + + assert(pRootSource); + assert(pRootSink); + +#ifdef TRACE_GRAPH + mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { + std::cout << "Node " << node.getIndex() << " :"; + ((CAmRoutingNode &)node).getData().trace(); + std::cout << "-->"; + std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ + am::CAmNode* data = refVertex->getNode(); + std::cout << "Node " << data->getIndex() << " :"; + data->getData().trace(); + }); + std::cout << std::endl; + }); +#endif + + std::vector> pathNodes; + error = getAllPaths(*pRootSource, *pRootSink, listRoutes, pathNodes); + return error; +} + +void CAmRouter::load(const bool onlyFree) +{ + clear(); + mOnlyFreeConversionNodes = onlyFree; + +#if defined (WITH_DATABASE_STORAGE) + std::deque listSources; + std::deque listSinks; + std::deque listGateways; + std::deque listConverters; +#endif + am_RoutingNodeData_s nodeDataSrc; + nodeDataSrc.type = CAmNodeDataType::SOURCE; + mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){ +#if defined (WITH_DATABASE_STORAGE) + listSources.push_back(obj); + nodeDataSrc.data.source = &listSources.back(); +#else + nodeDataSrc.data.source = (am_Source_s*)&obj; +#endif + mNodeListSources[nodeDataSrc.data.source->domainID].push_back(&mRoutingGraph.addNode(nodeDataSrc)); + }); + am_RoutingNodeData_s nodeDataSink; + nodeDataSink.type = CAmNodeDataType::SINK; + mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){ +#if defined (WITH_DATABASE_STORAGE) + listSinks.push_back(obj); + nodeDataSrc.data.sink = &listSinks.back(); +#else + nodeDataSink.data.sink = (am_Sink_s*)&obj; +#endif + mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(&mRoutingGraph.addNode(nodeDataSink)); + }); + am_RoutingNodeData_s nodeDataGateway; + nodeDataGateway.type = CAmNodeDataType::GATEWAY; + mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){ +#if defined (WITH_DATABASE_STORAGE) + listGateways.push_back(obj); + nodeDataSrc.data.gateway = &listGateways.back(); +#else + nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; +#endif + mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(&mRoutingGraph.addNode(nodeDataGateway)); + }); + am_RoutingNodeData_s nodeDataConverter; + nodeDataConverter.type = CAmNodeDataType::CONVERTER; + mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){ +#if defined (WITH_DATABASE_STORAGE) + listConverters.push_back(obj); + nodeDataSrc.data.converter = &listConverters.back(); +#else + nodeDataConverter.data.converter = (am_Converter_s*)&obj; +#endif + mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(&mRoutingGraph.addNode(nodeDataConverter)); + }); + +#ifdef ROUTING_BUILD_CONNECTIONS + constructConverterConnections(); + constructGatewayConnections(); + constructSourceSinkConnections(); +#endif +} + +void CAmRouter::clear() +{ + mRoutingGraph.clear(); + mNodeListSources.clear(); + mNodeListSinks.clear(); + mNodeListGateways.clear(); + mNodeListConverters.clear(); +} + +CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID) +{ + CAmRoutingNode* result = NULL; + for(auto it = mNodeListSinks.begin(); it!=mNodeListSinks.end(); it++) + { + result = sinkNodeWithID(sinkID, it->first); + if(result) + return result; + } + return result; +} + +CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID) +{ + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListSinks[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ + return node->getData().data.sink->sinkID==sinkID; + }); + if(iter!=value.end()) + result = *iter; + return result; +} + +CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID) +{ + CAmRoutingNode* result = NULL; + for(auto it = mNodeListSources.begin(); it!=mNodeListSources.end(); it++) + { + result = sourceNodeWithID(sourceID, it->first); + if(result) + return result; + } + return result; +} + +CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID) +{ + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListSources[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sourceID](CAmRoutingNode* node){ + return node->getData().data.source->sourceID==sourceID; + }); + if(iter!=value.end()) + result = *iter; + return result; +} + +CAmRoutingNode* CAmRouter::converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID) +{ + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListConverters[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ + return node->getData().data.converter->sinkID==sinkID; + }); + if(iter!=value.end()) + result = *iter; + return result; +} + +CAmRoutingNode* CAmRouter::gatewayNodeWithSinkID(const am_sinkID_t sinkID) +{ + for(auto it = mNodeListGateways.begin(); it!=mNodeListGateways.end(); it++) + { + std::vector & value = it->second; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ + return node->getData().data.gateway->sinkID==sinkID; + }); + if(iter!=value.end()) + return *iter; + } + return NULL; +} + +#ifdef ROUTING_BUILD_CONNECTIONS + +void CAmRouter::constructSourceSinkConnections() +{ + std::vector intersection; + for(auto itSrc = mNodeListSources.begin(); itSrc!=mNodeListSources.end(); itSrc++) + { + for(auto it = itSrc->second.begin(); it!=itSrc->second.end(); it++) + { + CAmRoutingNode* srcNode = *it; + am_RoutingNodeData_s & srcNodeData = srcNode->getData(); + am_Source_s * source = srcNodeData.data.source; + for(auto itSink = mNodeListSinks[itSrc->first].begin(); itSink!=mNodeListSinks[itSrc->first].end(); itSink++) + { + CAmRoutingNode* sinkNode = *itSink; + am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); + am_Sink_s * sink = sinkNodeData.data.sink; + + intersection.clear(); + //Check whether the hidden sink formats match the source formats... + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); + if(intersection.size()>0)//OK match source -> sink + { + mRoutingGraph.connectNodes(*srcNode, *sinkNode, CF_UNKNOWN, 1); + } + } + } + } +} + +void CAmRouter::constructGatewayConnections() +{ + std::vector sourceFormats, sinkFormats; + for(auto iter = mNodeListGateways.begin(); iter!=mNodeListGateways.end(); iter++) + { + for(auto it = iter->second.begin(); it!=iter->second.end(); it++) + { + CAmRoutingNode* gatewayNode = *it; + am_RoutingNodeData_s & gatewayNodeData = gatewayNode->getData(); + am_Gateway_s * gateway = gatewayNodeData.data.gateway; + //Get only gateways with end point in current source domain + if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) + { + //Get the sink connected to the gateway... + CAmRoutingNode *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID, gateway->domainSinkID); + if(gatewaySinkNode) + { + am_RoutingNodeData_s & gatewaySinkData = gatewaySinkNode->getData(); + //Check whether the hidden sink formats match the source formats... + sourceFormats.clear(); + sinkFormats.clear(); + if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); + if(gatewaySourceNode) + { + //Connections hidden_sink->gateway->hidden_source + mRoutingGraph.connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1); + mRoutingGraph.connectNodes(*gatewayNode, *gatewaySourceNode, CF_UNKNOWN, 1); + } + } + } + } + } + } +} + +void CAmRouter::constructConverterConnections() +{ + std::vector sourceFormats, sinkFormats; + + for(auto iter = mNodeListConverters.begin(); iter!=mNodeListConverters.end(); iter++) + { + for(auto it = iter->second.begin(); it!=iter->second.end(); it++) + { + CAmRoutingNode* converterNode = *it; + am_RoutingNodeData_s & converterNodeData = converterNode->getData(); + am_Converter_s * converter = converterNodeData.data.converter; + //Get only converters with end point in current source domain + if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) + { + //Get the sink connected to the converter... + CAmRoutingNode *converterSinkNode = this->sinkNodeWithID(converter->sinkID, converter->domainID); + if(converterSinkNode) + { + am_RoutingNodeData_s & converterSinkData = converterSinkNode->getData(); + //Check whether the hidden sink formats match the source formats... + sourceFormats.clear(); + sinkFormats.clear(); + if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); + if(converterSourceNode) + { + //Connections hidden_sink->converter->hidden_source + mRoutingGraph.connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1); + mRoutingGraph.connectNodes(*converterNode, *converterSourceNode, CF_UNKNOWN, 1); + } + } + } + } + } + } +} +#else + +void CAmRouter::getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list) +{ + am_RoutingNodeData_s & srcNodeData = ((CAmRoutingNode*)&node)->getData(); + std::vector intersection; + am_Source_s * source = srcNodeData.data.source; + std::vector & sinks = mNodeListSinks[source->domainID]; + for(auto itSink = sinks.begin(); itSink!=sinks.end(); itSink++) + { + CAmRoutingNode* sinkNode = *itSink; + am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); + am_Sink_s * sink = sinkNodeData.data.sink; + + intersection.clear(); + //Check whether the hidden sink formats match the source formats... + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); + if(intersection.size()>0)//OK match source -> sink + { + list.emplace_back(sinkNode, CF_UNKNOWN, 1); + } + } +} + +void CAmRouter::getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list) +{ + am_RoutingNodeData_s & sinkNodeData = ((CAmRoutingNode*)&node)->getData(); + std::vector intersection; + am_Sink_s * sink = sinkNodeData.data.sink; + + CAmRoutingNode *converterNode = converterNodeWithSinkID(sink->sinkID, sink->domainID); + if(converterNode) + { + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & converterData = converterNode->getData(); + am_Converter_s * converter = converterData.data.converter; + if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) + { + if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) + list.emplace_back(converterNode, CF_UNKNOWN, 1); + } + } + else + { + std::vector sourceFormats, sinkFormats; + CAmRoutingNode *gatewayNode = gatewayNodeWithSinkID(sink->sinkID); + if(gatewayNode) + { + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & gatewayData = gatewayNode->getData(); + am_Gateway_s * gateway = gatewayData.data.gateway; + if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) + { + if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) + list.emplace_back(gatewayNode, CF_UNKNOWN, 1); + } + } + } + +} + +void CAmRouter::getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list) +{ + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & converterNodeData = ((CAmRoutingNode*)&node)->getData(); + am_Converter_s * converter = converterNodeData.data.converter; + //Get only converters with end point in current source domain + if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); + if(converterSourceNode) + { + list.emplace_back(converterSourceNode, CF_UNKNOWN, 1); + } + } +} + +void CAmRouter::getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list) +{ + am_RoutingNodeData_s & gatewayNodeData = ((CAmRoutingNode*)&node)->getData(); + std::vector sourceFormats, sinkFormats; + am_Gateway_s * gateway = gatewayNodeData.data.gateway; + if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); + if(gatewaySourceNode) + { + //Connections hidden_sink->gateway->hidden_source + list.emplace_back(gatewaySourceNode, CF_UNKNOWN, 1); + } + } +} + +void CAmRouter::getVerticesForNode( + const CAmRoutingNode & node, + CAmRoutingListVertices & list + ) +{ + am_RoutingNodeData_s & nodeData = ((CAmRoutingNode*)&node)->getData(); + if(nodeData.type==CAmNodeDataType::SOURCE) + { + getVerticesForSource(node, list); + } + else if(nodeData.type==CAmNodeDataType::SINK) + { + getVerticesForSink(node, list); + } + else if(nodeData.type==CAmNodeDataType::CONVERTER) + { + getVerticesForConverter(node, list); + } + else if(nodeData.type==CAmNodeDataType::GATEWAY) + { + getVerticesForGateway(node, list); + } +} + +#endif + +am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes) +{ + std::vector::iterator routingElementIterator = routeObjects.route.begin(); + std::vector::iterator nodeIterator = nodes.begin(); + if( routingElementIterator!= routeObjects.route.end() && nodeIterator!=nodes.end() ) + return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator); + return E_OK; +} + +am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, + std::vector & nodes, + std::vector::iterator routingElementIterator, + std::vector::iterator nodeIterator) +{ + am_Error_e returnError = E_NOT_POSSIBLE; + std::vector listConnectionFormats; + std::vector listMergeConnectionFormats; + + std::vector::iterator currentNodeIterator = nodeIterator; + std::vector::iterator currentRoutingElementIterator = routingElementIterator; + + if (currentRoutingElementIterator!=routeObjects.route.begin()) + { + std::vector listConnectionFormats; + std::vector::iterator tempIterator = (currentRoutingElementIterator-1); + CAmRoutingNode * currentNode = *currentNodeIterator; + getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats); + + if(currentNode->getData().type==CAmNodeDataType::GATEWAY) + { + am_Gateway_s *gateway = currentNode->getData().data.gateway; + getMergeConnectionFormats(gateway, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); + } + else if(currentNode->getData().type==CAmNodeDataType::CONVERTER) + { + am_Converter_s *converter = currentNode->getData().data.converter; + getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); + } + currentNodeIterator+=3; + } + else + { + CAmRoutingNode * currentNode = *currentNodeIterator; + assert(currentNode->getData().type==CAmNodeDataType::SOURCE); + + currentNodeIterator++; + assert(currentNodeIterator!=nodes.end()); + + CAmRoutingNode * nodeSink = *currentNodeIterator; + assert(nodeSink->getData().type==CAmNodeDataType::SINK); + + am_Source_s *source = currentNode->getData().data.source; + am_Sink_s *sink = nodeSink->getData().data.sink; + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats); + currentNodeIterator+=1; //now we are on the next converter/gateway + } + + //let the controller decide: + std::vector listPriorityConnectionFormats; + mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects, + listMergeConnectionFormats, listPriorityConnectionFormats); + + //we have the list sorted after priors - 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 + std::vector::iterator nextIterator = currentRoutingElementIterator + 1;//next pair source and sink + if (nextIterator == routeObjects.route.end()) + { + if (!listPriorityConnectionFormats.empty()) + { + currentRoutingElementIterator->connectionFormat = listPriorityConnectionFormats.front(); + return (E_OK); + } + else + return (E_NOT_POSSIBLE); + } + + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + { + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + if ((returnError = doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator)) == E_OK) + { + break; + } + } + return (returnError); +} + +#ifdef ROUTING_BUILD_CONNECTIONS + +void CAmRouter::getShortestPath(const CAmRoutingNode & source, + const CAmRoutingNode & destination, + std::vector & resultPath) +{ + mRoutingGraph.getShortestPath(source, destination, resultPath); +} + +void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, + am_Route_s & resultPath, std::vector & resultNodesPath) +{ + am_RoutingElement_s * element; + am_RoutingNodeData_s & sinkNodeData = aSink.getData(); + am_RoutingNodeData_s & sourceNodeData = aSource.getData(); + resultPath.sinkID = sinkNodeData.data.sink->sinkID; + resultPath.sourceID = sourceNodeData.data.source->sourceID; + + std::function cb = [&](const am_GraphPathPosition_e, CAmRoutingNode & object) + { + resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); + am_RoutingNodeData_s & routingData = object.getData(); + if(routingData.type==CAmNodeDataType::SINK) + { + auto iter = resultPath.route.emplace(resultPath.route.begin()); + element = &(*iter); + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SOURCE) + { + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + }; + mRoutingGraph.getShortestPath(aSource, aSink, cb); +} + +#endif + +am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector & resultPath, + std::vector> & resultNodesPath, + const bool includeCycles) +{ +#ifndef ROUTING_BUILD_CONNECTIONS + bool cycles = false; +#else + bool cycles = includeCycles; +#endif + if(((CAmRoutingNode*)&aSource)->getData().type!=CAmNodeDataType::SOURCE || + ((CAmRoutingNode*)&aSink)->getData().type!=CAmNodeDataType::SINK) + return E_NOT_POSSIBLE; + + uint8_t errorsCount = 0, successCount = 0; + generateAllPaths(aSource, aSink, cycles, [&](const std::vector & path) { + resultNodesPath.push_back(path); + resultPath.emplace_back(); + am_Route_s & nextRoute = resultPath.back(); + nextRoute.sinkID = aSink.getData().data.sink->sinkID; + nextRoute.sourceID = aSource.getData().data.source->sourceID; + am_RoutingElement_s * element; + for(auto it = path.begin(); it!=path.end(); it++) + { + am_RoutingNodeData_s & routingData = (*it)->getData(); + if(routingData.type==CAmNodeDataType::SOURCE) + { + auto iter = nextRoute.route.emplace(nextRoute.route.end()); + element = &(*iter); + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SINK) + { + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + } + + am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector &)path); + if(err!=E_OK) + { + errorsCount++; + auto last = resultPath.end()-1; + resultPath.erase(last); +#ifdef TRACE_GRAPH + std::cout<<"Error by determining connection formats for path from source:"<" + < & visitedDomains, const am_domainID_t nodeDomainID) +{ + if(visitedDomains.size()) + { + if(visitedDomains.back()==nodeDomainID) + return true; + + for(auto it=visitedDomains.begin();it!=visitedDomains.end()-1; it++) + { + if(nodeDomainID==*it) + return false; + } + } + return true; +} + +void CAmRouter::generateAllPaths(const CAmRoutingNode & src, + const CAmRoutingNode & dst, + const bool includeCycles, + std::function & path)> cb) +{ + if(!includeCycles) + { + std::vector visited; + std::vector visitedDomains; + visited.push_back((CAmRoutingNode*)&src); + visitedDomains.push_back(((CAmRoutingNode*)&src)->getData().domainID()); + ((CAmRoutingNode*)&src)->setStatus(GES_VISITED); + goThroughAllPaths(dst, visited, visitedDomains, cb); + } + else + mRoutingGraph.getAllPaths(src, dst, cb); +} + +void CAmRouter::goThroughAllPaths(const CAmRoutingNode & dst, + std::vector & visited, + std::vector & visitedDomains, + std::function & path)> cb) +{ +#ifndef ROUTING_BUILD_CONNECTIONS + CAmRoutingListVertices vertices; + getVerticesForNode(*visited.back(), vertices); + const CAmRoutingListVertices * nodes = &vertices; +#else + const CAmRoutingListVertices * nodes = mRoutingGraph.getVertexList()[visited.back()->getIndex()]; +#endif + CAmRoutingListVertices::const_iterator vItr(nodes->begin()); + for (; vItr != nodes->end(); ++vItr) + { + const CAmRoutingVertex & vertex = (*vItr); + if(vertex.getNode()->getStatus()!=GES_NOT_VISITED || !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) + continue; + if (vertex.getNode()==&dst) + { + vertex.getNode()->setStatus(GES_IN_PROGRESS); + visited.push_back(vertex.getNode()); + visitedDomains.push_back(vertex.getNode()->getData().domainID()); + //notify observer + cb(visited); + //remove last node from the list + auto last = visited.end()-1; + visited.erase(last); + visitedDomains.erase(visitedDomains.end()-1); + vertex.getNode()->setStatus(GES_NOT_VISITED); + break; + } + } + vItr = nodes->begin(); + //bfs like loop + for (; vItr != nodes->end(); ++vItr) + { + const CAmRoutingVertex & vertex = (*vItr); + if(vertex.getNode()->getStatus()!=GES_NOT_VISITED + ||vertex.getNode()==&dst || + !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) + continue; + vertex.getNode()->setStatus(GES_IN_PROGRESS); + visited.push_back(vertex.getNode()); + visitedDomains.push_back(vertex.getNode()->getData().domainID()); + goThroughAllPaths(dst, visited, visitedDomains, cb); + //remove last node from the list + auto last = visited.end()-1; + visited.erase(last); + visitedDomains.erase(visitedDomains.end()-1); + vertex.getNode()->setStatus(GES_NOT_VISITED); + } +} + +bool CAmRouter::getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, + const std::vector & listSourceFormats, + const std::vector & listSinkFormats, + std::vector & sourceFormats, + std::vector & sinkFormats) +{ + const size_t sizeSourceFormats = listSourceFormats.size(); + const size_t sizeSinkFormats = listSinkFormats.size(); + const size_t sizeConvertionMatrix = convertionMatrix.size(); + + if(sizeSourceFormats==0||sizeSinkFormats==0||sizeConvertionMatrix==0||sizeConvertionMatrix!=sizeSinkFormats*sizeSourceFormats) + { + return false; + } + + std::vector::const_iterator iterator = convertionMatrix.begin(); + for (; iterator != convertionMatrix.end(); ++iterator) + { + if( true == *iterator ) + { + const size_t index = iterator-convertionMatrix.begin(); + size_t idx = index%sizeSourceFormats; + sourceFormats.push_back(listSourceFormats.at(idx)); + idx = index/sizeSourceFormats; + sinkFormats.push_back(listSinkFormats.at(idx)); + } + } + return sourceFormats.size()>0; +} + +void CAmRouter::listPossibleConnectionFormats(std::vector & inListSourceFormats, + std::vector & inListSinkFormats, + std::vector & outListFormats) +{ + std::sort(inListSourceFormats.begin(), inListSourceFormats.end()); + std::sort(inListSinkFormats.begin(), inListSinkFormats.end()); + std::insert_iterator > inserter(outListFormats, outListFormats.begin()); + set_intersection(inListSourceFormats.begin(), inListSourceFormats.end(), inListSinkFormats.begin(), inListSinkFormats.end(), inserter); +} + + +bool CAmRouter::getRestrictedOutputFormats(const std::vector & convertionMatrix, + const std::vector & listSourceFormats, + const std::vector & listSinkFormats, + const am_CustomConnectionFormat_t connectionFormat, + std::vector & listFormats) +{ + listFormats.clear(); + std::vector::const_iterator rowSinkIterator = listSinkFormats.begin(); + std::vector::const_iterator matrixIterator = convertionMatrix.begin(); + + //find the row number of the sink + rowSinkIterator = find(listSinkFormats.begin(), listSinkFormats.end(), connectionFormat); + int rowNumberSink = rowSinkIterator - 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(listSourceFormats.at((matrixIterator - convertionMatrix.begin()) / listSinkFormats.size())); + } + std::advance(matrixIterator, listSinkFormats.size()); + } while (convertionMatrix.end() - matrixIterator > 0); + + return listFormats.size(); +} + + +void CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, + std::vector::iterator iteratorSink, + std::vector & outConnectionFormats) +{ + CAmRoutingNode * nodeSink = *iteratorSink; + assert(nodeSink->getData().type==CAmNodeDataType::SINK); + + CAmRoutingNode * nodeSource = *iteratorSource; + assert(nodeSource->getData().type==CAmNodeDataType::SOURCE); + + am_Source_s *source = nodeSource->getData().data.source; + am_Sink_s *sink = nodeSink->getData().data.sink; + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats); +} + + +} diff --git a/AudioManagerCore/src/CAmRoutingReceiver.cpp b/AudioManagerCore/src/CAmRoutingReceiver.cpp new file mode 100644 index 0000000..4189936 --- /dev/null +++ b/AudioManagerCore/src/CAmRoutingReceiver.cpp @@ -0,0 +1,620 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmRoutingReceiver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRoutingReceiver.h" +#include +#include +#include "IAmDatabaseHandler.h" +#include "CAmRoutingSender.h" +#include "CAmControlSender.h" +#include "CAmDltWrapper.h" +#include "CAmSocketHandler.h" + +namespace am +{ + +CAmRoutingReceiver::CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : + mpDatabaseHandler(iDatabaseHandler), // + mpRoutingSender(iRoutingSender), // + mpControlSender(iControlSender), // + mpSocketHandler(iSocketHandler), // + mpDBusWrapper(NULL), // + mListStartupHandles(), // + mListRundownHandles(), // + handleCount(0), // + mWaitStartup(false), // + mWaitRundown(false), // + mLastStartupError(E_OK), // + mLastRundownError(E_OK) // +{ + assert(mpDatabaseHandler!=NULL); + assert(mpRoutingSender!=NULL); + assert(mpControlSender!=NULL); + assert(mpSocketHandler!=NULL); +} + +CAmRoutingReceiver::CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : + mpDatabaseHandler(iDatabaseHandler), // + mpRoutingSender(iRoutingSender), // + mpControlSender(iControlSender), // + mpSocketHandler(iSocketHandler), // + mpDBusWrapper(iDBusWrapper), // + mListStartupHandles(), // + mListRundownHandles(), // + handleCount(0), // + mWaitStartup(false), // + mWaitRundown(false), + mLastStartupError(E_OK), // + mLastRundownError(E_OK) // +{ + assert(mpDatabaseHandler!=NULL); + assert(mpRoutingSender!=NULL); + assert(mpControlSender!=NULL); + assert(mpSocketHandler!=NULL); + assert(mpDBusWrapper!=NULL); +} + +CAmRoutingReceiver::~CAmRoutingReceiver() +{ +} + +void CAmRoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + mpRoutingSender->removeHandle(handle); + if (error == am_Error_e::E_OK) + { + mpDatabaseHandler->changeConnectionFinal(connectionID); + } + else + { + mpDatabaseHandler->removeConnection(connectionID); + mpRoutingSender->removeConnectionLookup(connectionID); + } + mpControlSender->cbAckConnect(handle, error); +} + +void CAmRoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) +{ + + //so we will remove the connection anyway no matter what is answered + mpRoutingSender->removeHandle(handle); + mpDatabaseHandler->removeConnection(connectionID); + mpRoutingSender->removeConnectionLookup(connectionID); + mpControlSender->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; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if (error== am_Error_e::E_OK || error== am_Error_e::E_ABORTED) + { + mpDatabaseHandler->changeSinkVolume(handleData.sinkID, volume); + } + + if(error == am_Error_e::E_OK || handleData.volume!=volume) + { + logError("ackSetSinkVolumeChange volumes do not match, requested volume",handleData.volume,"returned volume",volume); + } + mpControlSender->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; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if (error== am_Error_e::E_OK || error== am_Error_e::E_ABORTED) + { + mpDatabaseHandler->changeSourceVolume(handleData.sourceID, volume); + } + + if(error == E_OK || handleData.volume!=volume) + { + logError("ackSetSourceVolumeChange volumes do not match, requested volume",handleData.volume,"returned volume",volume); + } + mpControlSender->cbAckSetSourceVolumeChange(handle, volume, error); +} + +void CAmRoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + //no error, so we can write the change into the database; + if (error == am_Error_e::E_OK) + { + mpDatabaseHandler->changeSourceState(handleData.sourceID, handleData.sourceState); + } + + mpControlSender->cbAckSetSourceState(handle, error); +} + +void CAmRoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if (error==am_Error_e::E_OK) + { + mpDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery, handleData.sinkID); + } + + mpControlSender->cbAckSetSinkSoundProperty(handle, error); + +} + +void am::CAmRoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if (error==am_Error_e::E_OK) + { + std::vector::const_iterator it = handleData.soundProperties->begin(); + for (; it != handleData.soundProperties->end(); ++it) + { + mpDatabaseHandler->changeSinkSoundPropertyDB(*it, handleData.sinkID); + } + } + + try + { + delete handleData.soundProperties; + } + catch(...) + { + logError("exception while deleting handleData while ackSetSinkSoundProperties"); + } + mpControlSender->cbAckSetSinkSoundProperties(handle, error); +} + +void CAmRoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + mpDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery, handleData.sourceID); + } + mpControlSender->cbAckSetSourceSoundProperty(handle, error); +} + +void am::CAmRoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + std::vector::const_iterator it = handleData.soundProperties->begin(); + for (; it != handleData.soundProperties->end(); ++it) + { + mpDatabaseHandler->changeSourceSoundPropertyDB(*it, handleData.sourceID); + } + } + + try + { + delete handleData.soundProperties; + } + catch(...) + { + logError("exception while deleting handleData while ackSetSourceSoundProperties"); + } + mpControlSender->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; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + mpDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID, hotSink); + } + mpControlSender->cbAckCrossFade(handle, hotSink, error); +} + +void CAmRoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) +{ + mpControlSender->hookSystemSourceVolumeTick(handle, sourceID, volume); +} + +void CAmRoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) +{ + mpControlSender->hookSystemSinkVolumeTick(handle, sinkID, volume); +} + +am_Error_e CAmRoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID) +{ + return (mpDatabaseHandler->peekDomain(name, domainID)); + +} + +am_Error_e CAmRoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) +{ + return (mpControlSender->hookSystemRegisterDomain(domainData, domainID)); +} + +am_Error_e CAmRoutingReceiver::deregisterDomain(const am_domainID_t domainID) +{ + return (mpControlSender->hookSystemDeregisterDomain(domainID)); +} + +am_Error_e CAmRoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) +{ + return (mpControlSender->hookSystemRegisterGateway(gatewayData, gatewayID)); +} + +am_Error_e CAmRoutingReceiver::registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID) +{ + return (mpControlSender->hookSystemRegisterConverter(converterData, converterID)); +} + +am_Error_e CAmRoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID) +{ + return (mpControlSender->hookSystemDeregisterGateway(gatewayID)); +} + +am_Error_e CAmRoutingReceiver::deregisterConverter(const am_converterID_t converterID) +{ + return (mpControlSender->hookSystemDeregisterConverter(converterID)); +} + +am_Error_e CAmRoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID) +{ + return (mpDatabaseHandler->peekSink(name, sinkID)); +} + +am_Error_e CAmRoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) +{ + return (mpControlSender->hookSystemRegisterSink(sinkData, sinkID)); +} + +am_Error_e CAmRoutingReceiver::deregisterSink(const am_sinkID_t sinkID) +{ + return (mpControlSender->hookSystemDeregisterSink(sinkID)); +} + +am_Error_e CAmRoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID) +{ + return (mpDatabaseHandler->peekSource(name, sourceID)); +} + +am_Error_e CAmRoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) +{ + return (mpControlSender->hookSystemRegisterSource(sourceData, sourceID)); +} + +am_Error_e CAmRoutingReceiver::deregisterSource(const am_sourceID_t sourceID) +{ + return (mpControlSender->hookSystemDeregisterSource(sourceID)); +} + +am_Error_e CAmRoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) +{ + return (mpControlSender->hookSystemRegisterCrossfader(crossfaderData, crossfaderID)); +} + +am_Error_e CAmRoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID) +{ + return (mpControlSender->hookSystemDeregisterCrossfader(crossfaderID)); +} + +void CAmRoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) +{ + return (mpControlSender->hookSystemInterruptStateChange(sourceID, interruptState)); +} + +void CAmRoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID) +{ + mpControlSender->hookSystemDomainRegistrationComplete(domainID); +} + +void CAmRoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) +{ + mpControlSender->hookSystemSinkAvailablityStateChange(sinkID, availability); +} + +void CAmRoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) +{ + mpControlSender->hookSystemSourceAvailablityStateChange(sourceID, availability); +} + +void CAmRoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) +{ + mpControlSender->hookSystemDomainStateChange(domainID, domainState); +} + +void CAmRoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) +{ + mpDatabaseHandler->changeConnectionTimingInformation(connectionID, delay); + mpControlSender->hookSystemSingleTimingInformationChanged(connectionID,delay); +} + +void CAmRoutingReceiver::sendChangedData(const std::vector & earlyData) +{ + mpControlSender->hookSystemReceiveEarlyData(earlyData); +} + +am_Error_e CAmRoutingReceiver::peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) +{ + return (mpDatabaseHandler->peekSinkClassID(name, sinkClassID)); +} + +am_Error_e CAmRoutingReceiver::peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) +{ + return (mpDatabaseHandler->peekSourceClassID(name, sourceClassID)); +} + +#ifdef WITH_DBUS_WRAPPER +am_Error_e CAmRoutingReceiver::getDBusConnectionWrapper(CAmDbusWrapper *& dbusConnectionWrapper) const +{ + dbusConnectionWrapper = mpDBusWrapper; + return (E_OK); +#else +am_Error_e CAmRoutingReceiver::getDBusConnectionWrapper(CAmDbusWrapper *& ) const +{ + return (E_UNKNOWN); +#endif +} + +am_Error_e CAmRoutingReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const +{ + socketHandler = mpSocketHandler; + return (E_OK); +} + +void CAmRoutingReceiver::getInterfaceVersion(std::string & version) const +{ + version = RoutingVersion; +} + +void CAmRoutingReceiver::confirmRoutingReady(const uint16_t handle, const am_Error_e error) +{ + if (error!=E_OK) + mLastStartupError=error; + mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); + if (mWaitStartup && mListStartupHandles.empty()) + mpControlSender->confirmRoutingReady(mLastStartupError); +} + +void CAmRoutingReceiver::confirmRoutingRundown(const uint16_t handle, const am_Error_e error) +{ + if (error!=E_OK) + mLastRundownError=error; + mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); + if (mWaitRundown && mListRundownHandles.empty()) + mpControlSender->confirmRoutingRundown(mLastRundownError); +} + +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; + mLastStartupError=E_OK; +} + +void CAmRoutingReceiver::ackSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + mpDatabaseHandler->changeSinkNotificationConfigurationDB(handleData.sinkID,*handleData.notificationConfiguration); + } + + try + { + delete handleData.notificationConfiguration; + } + catch(...) + { + logError("exception while deleting handleData while ackSinkNotificationConfiguration"); + } + mpControlSender->cbAckSetSinkNotificationConfiguration(handle,error); +} + +void CAmRoutingReceiver::ackSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + mpDatabaseHandler->changeSourceNotificationConfigurationDB(handleData.sourceID,*handleData.notificationConfiguration); + } + try + { + delete handleData.notificationConfiguration; + } + catch(...) + { + logError("exception while deleting handleData while ackSourceNotificationConfiguration"); + } + mpControlSender->cbAckSetSourceNotificationConfiguration(handle,error); +} + +am_Error_e CAmRoutingReceiver::updateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) +{ + return (mpControlSender->hookSystemUpdateGateway(gatewayID,listSourceFormats,listSinkFormats,convertionMatrix)); +} + +am_Error_e CAmRoutingReceiver::updateConverter(const am_converterID_t converterID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) +{ + return (mpControlSender->hookSystemUpdateConverter(converterID,listSourceFormats,listSinkFormats,convertionMatrix)); +} + +am_Error_e CAmRoutingReceiver::updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + return (mpControlSender->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmRoutingReceiver::updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) +{ + return (mpControlSender->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +void CAmRoutingReceiver::ackSetVolumes(const am_Handle_s handle, const std::vector& listvolumes, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData; + if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) + { + logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); + return; + } + + if(error==am_Error_e::E_OK) + { + std::vector::const_iterator iterator (listvolumes.begin()); + + for (;iterator!=listvolumes.end();++iterator) + { + if (iterator->volumeType==VT_SINK) + { + mpDatabaseHandler->changeSinkVolume(iterator->volumeID.sink,iterator->volume); + } + else if (iterator->volumeType==VT_SOURCE) + { + mpDatabaseHandler->changeSourceVolume(iterator->volumeID.source,iterator->volume); + } + } + + } + + try + { + delete handleData.listVolumes; + } + catch(...) + { + logError("exception while deleting handleData while ackSetVolumes"); + } + + mpControlSender->cbAckSetVolume(handle,listvolumes,error); +} + +void CAmRoutingReceiver::hookSinkNotificationDataChange(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) +{ + logInfo("CAmRoutingReceiver::hookSinkNotificationDataChange received, sinkID=",sinkID,"type=",payload.type,"notificationValue=",payload.value); + mpControlSender->hookSinkNotificationDataChanged(sinkID,payload); +} + +void CAmRoutingReceiver::hookSourceNotificationDataChange(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) +{ + logInfo("CAmRoutingReceiver::hookSourceNotificationDataChange received, sinkID=",sourceID,"type=",payload.type,"notificationValue=",payload.value); + mpControlSender->hookSourceNotificationDataChanged(sourceID,payload); +} + +am_Error_e CAmRoutingReceiver::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const +{ + return (mpDatabaseHandler->getDomainOfSink(sinkID,domainID)); +} + +am_Error_e CAmRoutingReceiver::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const +{ + return (mpDatabaseHandler->getDomainOfSource(sourceID,domainID)); +} + +am_Error_e CAmRoutingReceiver::getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const +{ + return (mpDatabaseHandler->getDomainOfCrossfader(crossfader,domainID)); +} + +void CAmRoutingReceiver::waitOnRundown(bool rundown) +{ + mWaitRundown = rundown; + mLastRundownError=E_OK; +} + +am_Error_e CAmRoutingSender::removeConnectionLookup(const am_connectionID_t connectionID) +{ + ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin(); + iter = mMapConnectionInterface.find(connectionID); + if (iter != mMapConnectionInterface.end()) + { + mMapConnectionInterface.erase(iter); + return (E_OK); + } + return (E_UNKNOWN); +} + +} diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp new file mode 100644 index 0000000..35e35b8 --- /dev/null +++ b/AudioManagerCore/src/CAmRoutingSender.cpp @@ -0,0 +1,838 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmRoutingSender.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRoutingSender.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "CAmRoutingReceiver.h" +#include "TAmPluginTemplate.h" +#include "CAmDltWrapper.h" + +namespace am +{ + +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 //!< major interface version. All versions smaller than this will be rejected +#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< minor interface version. All versions smaller than this will be rejected + +CAmRoutingSender::CAmRoutingSender(const std::vector& listOfPluginDirectories) : + mHandleCount(0), // + mlistActiveHandles(), // + mListInterfaces(), // + mMapConnectionInterface(), // + mMapCrossfaderInterface(), // + mMapDomainInterface(), // + mMapSinkInterface(), // + mMapSourceInterface(), // + mMapHandleInterface(), // + mpRoutingReceiver() +{ + + if (listOfPluginDirectories.empty()) + { + logError("CAmRoutingSender::CAmRoutingSender: List of routingplugins is empty"); + } + + 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; + std::string fullName = *dirIter + "/" + entryName; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + + 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"); + dlclose(tempLibHandle); + continue; + } + + InterfaceNamePairs routerInterface; + routerInterface.routingInterface = router; + + //check libversion + std::string version, cVersion(RoutingVersion); + router->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion; + std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion; + + + + if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion))) + { + logError("Routing initialization failed. Version of Interface to old"); + dlclose(tempLibHandle); + 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) +{ + mpRoutingReceiver = 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()) + { + removeHandle(handle); + 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_CustomConnectionFormat_t 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)); + am_Error_e syncError(iter->second->asyncConnect(handle, connectionID, sourceID, sinkID, connectionFormat)); + + if (syncError) + { + removeHandle(handle); + removeConnectionLookup(connectionID); + } + return(syncError); + + } + + 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 syncError(iter->second->asyncDisconnect(handle, connectionID)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + + 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_CustomRampType_t 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)); + am_Error_e syncError(iter->second->asyncSetSinkVolume(handle, sinkID, volume, ramp, time)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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_CustomRampType_t 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)); + am_Error_e syncError(iter->second->asyncSetSourceVolume(handle, sourceID, volume, ramp, time)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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)); + am_Error_e syncError(iter->second->asyncSetSourceState(handle, sourceID, state)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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)); + am_Error_e syncError(iter->second->asyncSetSinkSoundProperty(handle, sinkID, soundProperty)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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)); + am_Error_e syncError(iter->second->asyncSetSourceSoundProperty(handle, sourceID, soundProperty)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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)); + am_Error_e syncError(iter->second->asyncSetSourceSoundProperties(handle, sourceID, listSoundProperties)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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)); + am_Error_e syncError(iter->second->asyncSetSinkSoundProperties(handle, sinkID, listSoundProperties)); + if (syncError) + { + removeHandle(handle); + delete handleData.soundProperties; + } + return(syncError); + } + 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_CustomRampType_t 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)); + am_Error_e syncError(iter->second->asyncCrossFade(handle, crossfaderID, hotSink, rampType, time)); + if (syncError) + { + removeHandle(handle); + } + return(syncError); + } + 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); +} + +/** + * @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 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); + } + } + logError(__PRETTY_FUNCTION__," Could not find busname for bus",domainData.busname); + return (E_UNKNOWN); +} + +/** + * @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 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); + } + logError(__PRETTY_FUNCTION__," Could not find domainInterface for domainID",sourceData.domainID); + return (E_UNKNOWN); +} + +/** + * @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 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); + } + logError(__PRETTY_FUNCTION__,"Could not find domainInterface for domainID",sinkData.domainID); + return (E_UNKNOWN); +} + +/** + * @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 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); + } + logError(__PRETTY_FUNCTION__," Could not find sourceInterface for source",crossfaderData.sourceID); + return (E_UNKNOWN); +} + +/** + * @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 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); +} + +/** + * @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 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); +} + +/** + * @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 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); +} + +/** + * @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 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); +} + +/** + * removes a handle from the list + * @param handle to be removed + * @return E_OK in case of success + */ +am_Error_e CAmRoutingSender::removeHandle(const am_Handle_s& handle) +{ + if (mlistActiveHandles.erase(handle)) + { + return (E_OK); + } + logError(__PRETTY_FUNCTION__,"Could not remove handle",handle.handle); + 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); +} + +/** + * 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 CAmRoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type) +{ + am_Handle_s handle; + if (++mHandleCount>=1024) //defined by 10 bit (out if structure!) + mHandleCount=1; + handle.handle = mHandleCount; + handle.handleType = type; + mlistActiveHandles.insert(std::make_pair(handle, handleData)); + if ((mlistActiveHandles.size()%100) == 0) + logInfo("CAmRoutingSender::createHandle warning: too many open handles, number of handles: ", mlistActiveHandles.size()); + logInfo(__PRETTY_FUNCTION__,handle.handle, handle.handleType); + return (handle); +} + +/** + * returns the data that belong to handles + * @param handle the handle + * @return a class holding the handle data + */ +am_Error_e CAmRoutingSender::returnHandleData(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) const +{ + HandlesMap::const_iterator it = mlistActiveHandles.begin(); + it = mlistActiveHandles.find(handle); + if (it!=mlistActiveHandles.end()) + { + handleData = it->second; + return (am_Error_e::E_OK); + } + handleData.sinkID=0; + logError(__PRETTY_FUNCTION__,"could not find handle data for handle",handle.handle,handle.handleType); + return (am_Error_e::E_NON_EXISTENT); +} + +void CAmRoutingSender::setRoutingReady() +{ + mpRoutingReceiver->waitOnStartup(false); + + //create a list of handles + std::vector listStartupHandles; + for (size_t i = 0; i < mListInterfaces.size(); i++) + { + listStartupHandles.push_back(mpRoutingReceiver->getStartupHandle()); + } + + //set the receiver ready to wait for replies + mpRoutingReceiver->waitOnStartup(true); + + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + std::vector::const_iterator handleIter(listStartupHandles.begin()); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingReady(*(handleIter++)); + } +} + +void CAmRoutingSender::setRoutingRundown() +{ + mpRoutingReceiver->waitOnRundown(false); + //create a list of handles + std::vector listStartupHandles; + for (size_t i = 0; i < mListInterfaces.size(); i++) + { + listStartupHandles.push_back(mpRoutingReceiver->getRundownHandle()); + } + + //set the receiver ready to wait for replies + mpRoutingReceiver->waitOnRundown(true); + + std::vector::iterator iter = mListInterfaces.begin(); + std::vector::iterator iterEnd = mListInterfaces.end(); + std::vector::const_iterator handleIter(listStartupHandles.begin()); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingRundown(*(handleIter++)); + } +} + +am_Error_e CAmRoutingSender::asyncSetVolumes(am_Handle_s& handle, const std::vector& listVolumes) +{ + am_handleData_c handleData; + IAmRoutingSend* pRoutingInterface(NULL); + if (listVolumes.empty()) + return (E_NOT_POSSIBLE); + + //we need an interface so lets get either the sink or source ID from the first entry in the listVolumes + if (listVolumes[0].volumeType==VT_SINK) + { + am_sinkID_t sinkID=listVolumes[0].volumeID.sink; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if(iter!=mMapSinkInterface.end()) + pRoutingInterface=iter->second; + else + return(E_NON_EXISTENT); + } + + else if (listVolumes[0].volumeType==VT_SOURCE) + { + am_sourceID_t sourceID=listVolumes[0].volumeID.source; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter!=mMapSourceInterface.end()) + pRoutingInterface=iter->second; + else + return(E_NON_EXISTENT); + } + else + return (E_NON_EXISTENT); + + handleData.volumeID=listVolumes[0].volumeID; + handleData.listVolumes= new std::vector(listVolumes); + handle = createHandle(handleData, H_SETVOLUMES); + + mMapHandleInterface.insert(std::make_pair(+ handle.handle, pRoutingInterface)); + am_Error_e syncError(pRoutingInterface->asyncSetVolumes(handle, listVolumes)); + if (syncError) + { + removeHandle(handle); + delete handleData.listVolumes; + } + return(syncError); + +} + +am_Error_e CAmRoutingSender::asyncSetSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + am_handleData_c handleData; + SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); + iter = mMapSinkInterface.find(sinkID); + if (iter != mMapSinkInterface.end()) + { + handleData.sinkID = sinkID; + handleData.notificationConfiguration = new am_NotificationConfiguration_s(notificationConfiguration); + handle = createHandle(handleData, H_SETSINKNOTIFICATION); + mMapHandleInterface.insert(std::make_pair(+ handle.handle, iter->second)); + am_Error_e syncError(iter->second->asyncSetSinkNotificationConfiguration(handle, sinkID,notificationConfiguration)); + if (syncError) + { + removeHandle(handle); + delete handleData.notificationConfiguration; + } + return(syncError); + } + return (E_NON_EXISTENT); +} + +am_Error_e CAmRoutingSender::asyncSetSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) +{ + am_handleData_c handleData; + SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); + iter = mMapSourceInterface.find(sourceID); + if (iter != mMapSourceInterface.end()) + { + handleData.sourceID = sourceID; + handleData.notificationConfiguration = new am_NotificationConfiguration_s(notificationConfiguration); + handle = createHandle(handleData, H_SETSOURCENOTIFICATION); + mMapHandleInterface.insert(std::make_pair(+ handle.handle, iter->second)); + am_Error_e syncError(iter->second->asyncSetSourceNotificationConfiguration(handle, sourceID,notificationConfiguration)); + if (syncError) + { + removeHandle(handle); + delete handleData.notificationConfiguration; + } + return(syncError); + } + return (E_NON_EXISTENT); +} + +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 = RoutingVersion; +} +am_Error_e CAmRoutingSender::resyncConnectionState(const am_domainID_t domainID,std::vector& listOfExistingConnections) +{ + DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); + iter = mMapDomainInterface.find(domainID); + if (iter != mMapDomainInterface.end()) + return (iter->second->resyncConnectionState(domainID, listOfExistingConnections)); + return (E_NON_EXISTENT); +} + +am_Error_e CAmRoutingSender::returnHandleDataAndRemove(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) +{ + HandlesMap::const_iterator it = mlistActiveHandles.begin(); + it = mlistActiveHandles.find(handle); + if (it!=mlistActiveHandles.end()) + { + handleData = it->second; + mlistActiveHandles.erase(handle); + return (am_Error_e::E_OK); + } + handleData.sinkID=0; + logError(__PRETTY_FUNCTION__,"could not find handle data for handle",handle.handle,handle.handleType); + return (am_Error_e::E_NON_EXISTENT); + +} + +} diff --git a/AudioManagerCore/src/CAmTelnetMenuHelper.cpp b/AudioManagerCore/src/CAmTelnetMenuHelper.cpp new file mode 100644 index 0000000..2aae4f5 --- /dev/null +++ b/AudioManagerCore/src/CAmTelnetMenuHelper.cpp @@ -0,0 +1,1438 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * \file CAmTelnetMenuHelper.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmTelnetMenuHelper.h" +#include +#include "audiomanagerconfig.h" +#include "CAmRouter.h" +#include "CAmTelnetServer.h" +#include "IAmDatabaseHandler.h" +#include "CAmControlSender.h" +#include "CAmCommandSender.h" +#include "CAmRoutingSender.h" +#include "CAmRoutingReceiver.h" +#include "CAmCommandReceiver.h" +#include "CAmControlReceiver.h" +#include "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"); + + +namespace am { + +CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL; + +/****************************************************************************/ +CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *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) +{ + instance = this; + createCommandMaps(); +} + +/****************************************************************************/ +CAmTelnetMenuHelper::~CAmTelnetMenuHelper() +/****************************************************************************/ +{ +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::createCommandMaps() +/****************************************************************************/ +{ + // ROOT commands + mRootCommands.clear(); + mRootCommands.insert(std::make_pair("help", sCommandPrototypeInfo("show all possible commands", &CAmTelnetMenuHelper::helpCommand))); + mRootCommands.insert(std::make_pair("list", sCommandPrototypeInfo("Go into 'list'-submenu", &CAmTelnetMenuHelper::rootListCommand))); + mRootCommands.insert(std::make_pair("info", sCommandPrototypeInfo("Go into 'info'-submenu", &CAmTelnetMenuHelper::rootInfoCommand))); + mRootCommands.insert(std::make_pair("set", sCommandPrototypeInfo("Go into 'set'-submenu", &CAmTelnetMenuHelper::rootSetCommand))); + mRootCommands.insert(std::make_pair("get", sCommandPrototypeInfo("Go into 'get'-submenu", &CAmTelnetMenuHelper::rootGetCommand))); + mRootCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("quit telnet session", &CAmTelnetMenuHelper::exitCommand))); + // List commands + mListCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); + mListCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("list all connections", &CAmTelnetMenuHelper::listConnectionsCommand))); + mListCommands.insert(std::make_pair("sources", sCommandPrototypeInfo("list all available sources", &CAmTelnetMenuHelper::listSourcesCommand))); + mListCommands.insert(std::make_pair("sinks", sCommandPrototypeInfo("list all available sinks", &CAmTelnetMenuHelper::listSinksCommands))); + mListCommands.insert(std::make_pair("crfader", sCommandPrototypeInfo("list all crossfaders", &CAmTelnetMenuHelper::listCrossfaders))); + mListCommands.insert(std::make_pair("domains", sCommandPrototypeInfo("list all domains", &CAmTelnetMenuHelper::listDomainsCommand))); + mListCommands.insert(std::make_pair("gws", sCommandPrototypeInfo("list all gateways", &CAmTelnetMenuHelper::listGatewaysCommand))); + mListCommands.insert(std::make_pair("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand))); + mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand))); + mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand))); + mListCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); + mListCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); + // Set commands + mSetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); + mSetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); + mSetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); + mSetCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink", &CAmTelnetMenuHelper::setConnection))); + mSetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("use 'routing sourceId sinkId' to get all\n\t possible routes between a sourceID and a sinkID", &CAmTelnetMenuHelper::setRoutingCommand))); + mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection", &CAmTelnetMenuHelper::setDisconnectConnId))); + mSetCommands.insert(std::make_pair("sinkvolume", sCommandPrototypeInfo("use 'sinkvolume sinkID volume' to set \n\t absorption in db of sink", &CAmTelnetMenuHelper::setSinkVolume))); + mSetCommands.insert(std::make_pair("sinkvolstep", sCommandPrototypeInfo("use 'sinkvolstep sinkID volumestep' to increment \n\t or decrement volume", &CAmTelnetMenuHelper::setVolumeStep))); + mSetCommands.insert(std::make_pair("sinkprop", sCommandPrototypeInfo("use 'sinkprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSinkSoundProperty))); + mSetCommands.insert(std::make_pair("sinkmute", sCommandPrototypeInfo("use 'sinkmute sinkid mutestate' to mute \n\t or unmute", &CAmTelnetMenuHelper::setSinkMuteState))); + mSetCommands.insert(std::make_pair("sourceprop", sCommandPrototypeInfo("use 'sourceprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSourceSoundProperty))); + // Get commands + mGetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); + mGetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("show current routing", &CAmTelnetMenuHelper::getRoutingCommand))); + mGetCommands.insert(std::make_pair("sendv", sCommandPrototypeInfo("show senderversion", &CAmTelnetMenuHelper::getSenderversionCommand))); + mGetCommands.insert(std::make_pair("recv", sCommandPrototypeInfo("show receiverversion ", &CAmTelnetMenuHelper::getReceiverversionCommand))); + mGetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); + mGetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); + // Info comands + mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); + mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand))); + mInfoCommands.insert(std::make_pair("dump", sCommandPrototypeInfo("create a database dump of currently used data", &CAmTelnetMenuHelper::infoDumpCommand))); + mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); + mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor) +/****************************************************************************/ +{ + EMainState state = eRootState; + std::map::iterator it; + std::stringstream welcome; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + // socket connection already exists, delete entry and go back to root state + mCurrentMainStateMap.erase(it); + } + it = mCurrentMainStateMap.begin(); + // insert new socket connection + mCurrentMainStateMap.insert(it, std::make_pair(filedescriptor, state)); + // Send welcome message + welcome << COLOR_WELCOME << "Welcome to GENIVI AudioManager " << DAEMONVERSION << COLOR_DEFAULT << "\n>"; + assert(send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0)>=0); + logInfo("[TN] New connection: ", filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor) +/****************************************************************************/ +{ + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + mCurrentMainStateMap.erase(it); + } + else + { + logError("[TN] socketConnectionsClosed, fd not found, ", filedescriptor); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::enterCmdQueue(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + std::map::iterator it; + std::string cmd; + tCommandMap::iterator cmditer; + // find current filedescriptor to get the current state of the telnet session + it = mCurrentMainStateMap.find(filedescriptor); + while (!CmdQueue.empty()) + { + cmd = CmdQueue.front(); + // Now remove the first command, it's stored in 'cmd' + CmdQueue.pop(); + // telnet session found. depending on the current state, different commands are available + switch (it->second) + { + case eRootState: + cmditer = mRootCommands.find(cmd); + if (mRootCommands.end() != cmditer) + cmditer->second.CommandPrototype(CmdQueue, filedescriptor); + else + sendError(filedescriptor, "Command not found\n"); + + break; + case eListState: + cmditer = mListCommands.find(cmd); + if (mListCommands.end() != cmditer) + cmditer->second.CommandPrototype(CmdQueue, filedescriptor); + else + sendError(filedescriptor, "Command not found\n"); + + break; + case eInfoState: + cmditer = mInfoCommands.find(cmd); + if (mInfoCommands.end() != cmditer) + cmditer->second.CommandPrototype(CmdQueue, filedescriptor); + else + sendError(filedescriptor, "Command not found\n"); + + break; + case eGetState: + cmditer = mGetCommands.find(cmd); + if (mGetCommands.end() != cmditer) + cmditer->second.CommandPrototype(CmdQueue, filedescriptor); + else + sendError(filedescriptor, "Command not found\n"); + + break; + case eSetState: + cmditer = mSetCommands.find(cmd); + if (mSetCommands.end() != cmditer) + cmditer->second.CommandPrototype(CmdQueue, filedescriptor); + else + sendError(filedescriptor, "Command not found\n"); + + break; + default: + break; + } + } + + sendCurrentCmdPrompt(filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::sendError(int& filedescriptor, std::string error_string) +/****************************************************************************/ +{ + assert(send(filedescriptor, error_string.c_str(), error_string.size(), 0)>=0); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::sendTelnetLine(int& filedescriptor, std::stringstream& line) +/****************************************************************************/ +{ + assert(send(filedescriptor, line.str().c_str(), line.str().size(), 0)>=0); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int& filedescriptor) +/****************************************************************************/ +{ + std::map::iterator it; + std::stringstream outputstream; + outputstream << std::endl; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + switch (it->second) + { + case eRootState: + outputstream << "\\>"; + break; + case eListState: + outputstream << "\\List>"; + break; + case eGetState: + outputstream << "\\Get>"; + break; + case eSetState: + outputstream << "\\Set>"; + break; + case eInfoState: + outputstream << "\\Info>"; + break; + default: + break; + } + assert(send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0)>=0); + } + else + { + logInfo("[TN] sendCurrentCmdPrompt, fd not found: ", filedescriptor); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::exitCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->exitCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + switch (it->second) + { + case eRootState: + it->second = eRootState; + break; + case eListState: + it->second = eRootState; + ; + break; + case eGetState: + it->second = eRootState; + ; + break; + case eSetState: + it->second = eRootState; + ; + break; + case eInfoState: + it->second = eRootState; + ; + break; + default: + it->second = eRootState; + break; + } + logInfo("[TN] oneStepBackCommandExec, state: ", it->second); + } + +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::oneStepBackCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->oneStepBackCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::exitCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + std::stringstream line; + std::stringstream output; + // Sending a last message to the client + output << "bye!" << COLOR_DEFAULT << std::endl; + sendTelnetLine(filedescriptor, output); + tCommandMap::iterator iter; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + if (NULL != mpTelenetServer) + { + logInfo("[TN] exitCommandExec, removing fd ", filedescriptor); + mpTelenetServer->disconnectClient(filedescriptor); + mCurrentMainStateMap.erase(it); + } + else + { + logError("[TN] exitCommandExec, mpTelenetServer == NULL, fd ", filedescriptor); + } + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::helpCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->helpCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::helpCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + std::stringstream line; + tCommandMap::iterator cmdIter; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl; + line << COLOR_HEAD << "###### The following commands are supported: ######" << COLOR_DEFAULT << std::endl; + line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl << std::endl; + switch (it->second) + { + case eRootState: + cmdIter = mRootCommands.begin(); + while (cmdIter != mRootCommands.end()) + { + line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; + cmdIter++; + } + break; + case eListState: + cmdIter = mListCommands.begin(); + while (cmdIter != mListCommands.end()) + { + line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; + cmdIter++; + } + break; + case eGetState: + cmdIter = mGetCommands.begin(); + while (cmdIter != mGetCommands.end()) + { + line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; + cmdIter++; + } + break; + case eSetState: + cmdIter = mSetCommands.begin(); + while (cmdIter != mSetCommands.end()) + { + line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; + cmdIter++; + } + break; + case eInfoState: + cmdIter = mInfoCommands.begin(); + while (cmdIter != mInfoCommands.end()) + { + line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; + cmdIter++; + } + break; + default: + break; + } + + sendTelnetLine(filedescriptor, line); + } + +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootGetCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->rootGetCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootGetCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + it->second = eGetState; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootSetCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->rootSetCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootSetCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + it->second = eSetState; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootListCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->rootListCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootListCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + it->second = eListState; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootInfoCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->rootInfoCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::map::iterator it; + it = mCurrentMainStateMap.find(filedescriptor); + if (it != mCurrentMainStateMap.end()) + { + it->second = eInfoState; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listConnectionsCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listConnectionsCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Connection_s > listConnections; + if (E_OK == mpDatabasehandler->getListConnections(listConnections)) + { + std::stringstream output; + output << "\tConnections: " << listConnections.size() << std::endl; + for (std::vector::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++) + { + output << "\tID: " << iter->connectionID << "\tSrcID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << "\tFormat: " << iter->connectionFormat << "\tdelay: " << iter->delay << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListConnections"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listSourcesCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listSourcesCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Source_s > listSources; + if (E_OK == mpDatabasehandler->getListSources(listSources)) + { + std::stringstream output; + output << "\tSources: " << listSources.size() << std::endl; + for (std::vector::iterator iter(listSources.begin()); iter < listSources.end(); iter++) + { + output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tDomainID: " << iter->domainID << "\tState: " << iter->sourceState << "\tVolume: " << iter->volume << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListSources"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listSinksCommands(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listSinksCommandsExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Sink_s > listSinks; + if (E_OK == mpDatabasehandler->getListSinks(listSinks)) + { + std::stringstream output; + output << "\tSinks: " << listSinks.size() << std::endl; + for (std::vector::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++) + { + output << "\tID: " << iter->sinkID << "\tDomainID: " << iter->domainID << "\tName: " << iter->name << "\tAvailable: " << iter->available.availability << "\tVolume: " << iter->volume << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListSinks"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listCrossfaders(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listCrossfadersExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listCrossfadersExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Crossfader_s > listCrossfaders; + if (E_OK == mpDatabasehandler->getListCrossfaders(listCrossfaders)) + { + std::stringstream output; + output << "\tCrossfader: " << listCrossfaders.size() << std::endl; + for (std::vector::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++) + { + output << "\tID: " << iter->crossfaderID << "\tName: " << iter->name << "\tSinkA: " << iter->sinkID_A << "\tSinkB: " << iter->sinkID_B << "\tSourceID: " << iter->sourceID << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListCrossfaders"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listDomainsCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listDomainsCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Domain_s > listDomains; + if (E_OK == mpDatabasehandler->getListDomains(listDomains)) + { + std::stringstream output; + output << "\tDomains: " << listDomains.size() << std::endl; + for (std::vector::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++) + { + output << "\tID: " << iter->domainID << "\tName: " << iter->name << "\tBusname: " << iter->busname << "\tNodename: " << iter->nodename << "\tState: " << static_cast(iter->state) << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListDomains"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listGatewaysCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listGatewaysCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_Gateway_s > listGateways; + if (E_OK == mpDatabasehandler->getListGateways(listGateways)) + { + std::stringstream output; + output << "\tGateways: " << listGateways.size(); + for (std::vector::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++) + { + output << "\tID: " << iter->gatewayID << "\tName: " << iter->name << "\tSourceID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListGateways"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getRoutingCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->getRoutingCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + (void) (filedescriptor); +//TODO: fill with function +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getSenderversionCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->getSenderversionCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::stringstream output; + std::string versionCommand; + std::string versionRouting; + std::string versionControl; + mpControlSender->getInterfaceVersion(versionControl); + mpRoutingSender->getInterfaceVersion(versionRouting); + mpCommandSender->getInterfaceVersion(versionCommand); + output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; + sendTelnetLine(filedescriptor, output); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->getReceiverversionCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::stringstream output; + std::string versionCommand; + std::string versionRouting; + std::string versionControl; + mpControlReceiver->getInterfaceVersion(versionControl); + mpRoutingReceiver->getInterfaceVersion(versionRouting); + mpCommandReceiver->getInterfaceVersion(versionCommand); + output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; + sendTelnetLine(filedescriptor, output); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::infoDumpCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->infoDumpCommandExec(CmdQueue, filedescriptor); +} + + +/****************************************************************************/ +void CAmTelnetMenuHelper::setVolumeStep(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setSinkVolumeExec(CmdQueue,filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setVolumeStepExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + if (CmdQueue.size() >= 2) + { + int16_t volumestep = 0; + am_sinkID_t sinkID = 0; + bool error = false; + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_volumestep(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_volumestep >> volumestep)) + error = true; + + if (!(istream_sinkID >> sinkID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing setVolumeStep 'sinkID' or 'volumestep'"); + return; + } + if (E_OK == mpCommandReceiver->volumeStep(sinkID,volumestep)) + { + std::stringstream output; + output << "SetSinkVolumeStep set: " << sinkID << "->" << volumestep << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error SetSinkVolumeStep"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set SetSinkVolumeStep, please enter 'sinkID' and 'volumestep' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkMuteState(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setSinkMuteStateExec(CmdQueue,filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkMuteStateExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + if (CmdQueue.size() >= 2) + { + u_int16_t tmp = 0; + am_MuteState_e MuteState = MS_UNKNOWN; + am_sinkID_t sinkID = 0; + bool error = false; + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_mutestate(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_mutestate >> tmp)) + error = true; + + if (!(istream_sinkID >> sinkID)) + error = true; + + if(tmp < MS_MAX) + { + MuteState = static_cast(tmp); + } + else + { + sendError(filedescriptor, "You tried to set an invalid am_MuteState_e"); + error = true; + } + + if (error) + { + sendError(filedescriptor, "Error parsing setSinkMuteState 'sinkID' or 'mutestate'"); + return; + } + if (E_OK == mpCommandReceiver->setSinkMuteState(sinkID,MuteState)) + { + std::stringstream output; + output << "setSinkMuteState set: " << sinkID << "->" << MuteState << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error setSinkMuteState"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set setSinkMuteState, please enter 'sinkID' and 'mutestate' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSourceSoundProperty(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setSourceSoundPropertiesExec(CmdQueue,filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSourceSoundPropertyExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + unsigned int tmpType = 0; + bool error = false; + if (CmdQueue.size() >= 3) + { + std::istringstream istream_sourceID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_type(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_value(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_type >> tmpType)) + error = true; + + am_MainSoundProperty_s soundProperty; + soundProperty.type = static_cast(tmpType); + + if (!(istream_value >> soundProperty.value)) + error = true; + + am_sourceID_t sourceID = 0; + if (!(istream_sourceID >> sourceID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing setMainSourceSoundProperty 'type', 'value' or 'sourceID'"); + return; + } + if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) + { + std::stringstream output; + output << "setMainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error setMainSourceSoundProperty"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set setMainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_SystemProperty_s > listSystemProperties; + if (E_OK == mpDatabasehandler->getListSystemProperties(listSystemProperties)) + { + std::stringstream output; + output << "\tSystemproperties: " << listSystemProperties.size() << std::endl; + std::vector::iterator it; + for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++) + { + output << "\tType: " << it->type << " Value: " << it->value << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListSystemProperties"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::infoDumpCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + + std::stringstream *pOutput = new std::stringstream(); + + mpDatabasehandler->dump(*pOutput); + + sendTelnetLine(filedescriptor, *pOutput); + + delete pOutput; +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setRoutingCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setRoutingCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + if (CmdQueue.size() >= 2) + { + bool error = false; + std::istringstream istream_sourceID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + am_sourceID_t sourceID = 0; + if (!(istream_sourceID >> sourceID)) + error = true; + + am_sinkID_t sinkID = 0; + if (!(istream_sinkID >> sinkID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing sourcID and sinkID"); + return; + } + std::vector < am_Route_s > routingList; + if (E_OK == mpRouter->getRoute(true, sourceID, sinkID, routingList)) + { + std::stringstream output; + std::vector::iterator rlIter = routingList.begin(); + for (int rlCnt = 1; rlIter < routingList.end(); rlIter++) + { + output << "#" << rlCnt << " "; + std::vector::iterator reIter = rlIter->route.begin(); + for (; reIter < rlIter->route.end(); reIter++) + { + output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl; + } + rlCnt++; + } + + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error getting route"); + } + } + else + { + if (!CmdQueue.empty()) + CmdQueue.pop(); + + sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setConnection(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setConnectionExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setConnectionExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + bool error = false; + am_Error_e rError = E_OK; + if (CmdQueue.size() >= 2) + { + std::istringstream istream_sourceID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + am_sourceID_t sourceID = 0; + if (!(istream_sourceID >> sourceID)) + error = true; + + am_sinkID_t sinkID = 0; + if (!(istream_sinkID >> sinkID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing sinkID and/or sourceID"); + return; + } +// Try to set up connection + am_mainConnectionID_t connID = 0; + rError = mpCommandReceiver->connect(sourceID, sinkID, connID); + if (E_OK == rError) + { + std::stringstream output; + output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error connecting sourceID and sinkID"); + } + } + else + { +// remove 1 element if list is not empty + if (!CmdQueue.empty()) + CmdQueue.pop(); + + sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setDisconnectConnId(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setDisconnectConnIdExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + am_mainConnectionID_t connID = 0; + bool error = false; + am_Error_e rError = E_OK; + if (CmdQueue.size() >= 1) + { + std::istringstream istream_connID(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_connID >> connID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing connID"); + return; + } +// Try to disconnect connection id + rError = mpCommandReceiver->disconnect(connID); + if (E_OK == rError) + { + std::stringstream output; + output << "ConnID " << connID << " closed successfully! " << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error disconnecting connectionID"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setConnectionExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + if (CmdQueue.size() >= 3) + { + bool error = false; + std::istringstream istream_sourceID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_type(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_value(CmdQueue.front()); + CmdQueue.pop(); + unsigned int tmpType = 0; + if (!(istream_type >> tmpType)) + error = true; + + am_MainSoundProperty_s soundProperty; + soundProperty.type = static_cast(tmpType); + + if (!(istream_value >> soundProperty.value)) + error = true; + + am_sinkID_t sourceID = 0; + if (!(istream_sourceID >> sourceID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'"); + return; + } + if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) + { + std::stringstream output; + output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error setMainSourceSoundProperty"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkSoundProperty(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setSinkSoundPropertyExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkSoundPropertyExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + unsigned int tmpType = 0; + bool error = false; + if (CmdQueue.size() >= 3) + { + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_type(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_value(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_type >> tmpType)) + error = true; + + am_MainSoundProperty_s soundProperty; + soundProperty.type = static_cast(tmpType); + + if (!(istream_value >> soundProperty.value)) + error = true; + + am_sinkID_t sinkID = 0; + if (!(istream_sinkID >> sinkID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'"); + return; + } + if (E_OK == mpCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID)) + { + std::stringstream output; + output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error setMainSinkSoundProperty"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkVolume(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->setSinkVolumeExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::setSinkVolumeExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + if (CmdQueue.size() >= 2) + { + am_volume_t volume = 0; + am_sinkID_t sinkID = 0; + bool error = false; + std::istringstream istream_sinkID(CmdQueue.front()); + CmdQueue.pop(); + std::istringstream istream_volume(CmdQueue.front()); + CmdQueue.pop(); + if (!(istream_volume >> volume)) + error = true; + + if (!(istream_sinkID >> sinkID)) + error = true; + + if (error) + { + sendError(filedescriptor, "Error parsing SetSinkVolume 'sinkID' or 'volume'"); + return; + } + if (E_OK == mpCommandReceiver->setVolume(sinkID,volume)) + { + std::stringstream output; + output << "setVolume set: " << sinkID << "->" << volume << std::endl; + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "Error setVolume"); + } + } + else + { + sendError(filedescriptor, "Not enough arguments to set setVolume, please enter 'sinkID' and 'volume' after command"); + return; + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listPluginsCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listPluginsCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < std::string > PlugInNames; + std::vector::iterator iter; + std::stringstream output; + if (E_OK == mpCommandSender->getListPlugins(PlugInNames)) + { + output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl; + for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) + { + output << iter->c_str() << std::endl; + } + } + else + { + sendError(filedescriptor, "ERROR: mCommandSender->getListPlugins"); + } + if (E_OK == mpRoutingSender->getListPlugins(PlugInNames)) + { + output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl; + for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) + { + output << iter->c_str() << std::endl; + } + } + else + { + sendError(filedescriptor, "ERROR: mRoutingSender->getListPlugins"); + } + sendTelnetLine(filedescriptor, output); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listMainSourcesCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_SourceType_s > listMainSources; + if (E_OK == mpDatabasehandler->getListMainSources(listMainSources)) + { + std::stringstream output; + output << std::endl << "\tMainSources: " << listMainSources.size() << std::endl; + std::vector::iterator iter; + for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++) + { + output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tsourceClassID: " << iter->sourceClassID << "\tavailability: " << iter->availability.availability << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSources"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainSinksCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listMainSinksCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector < am_SinkType_s > listMainSinks; + if (E_OK == mpDatabasehandler->getListMainSinks(listMainSinks)) + { + std::stringstream output; + output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl; + std::vector::iterator iter; + for (iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++) + { + output << "\tID: " << iter->sinkID << "\tsinkClassID: " << iter->sinkClassID << "\tName: " << iter->name << "\tAvailable: " << iter->availability.availability << "\tVolume: " << iter->volume << std::endl; + } + sendTelnetLine(filedescriptor, output); + } + else + { + sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSinks"); + } +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + instance->listMainConnectionsCommandExec(CmdQueue, filedescriptor); +} + +/****************************************************************************/ +void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue& CmdQueue, int& filedescriptor) +/****************************************************************************/ +{ + (void) (CmdQueue); + std::vector listMainConnections; + + if(E_OK == mpDatabasehandler->getListMainConnections(listMainConnections)) + { + std::stringstream output; + output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl; + + std::vector::iterator iter; + for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++) + { + output << "\tID: " << iter->mainConnectionID + << "\tState: " << iter->connectionState + << "\tDelay: " << iter->delay + << "\tsourceID: " << iter->sourceID + << "\tsinkID: " << iter->sinkID << std::endl; + + output << "ConnectionIDs: "; + std::vector::iterator list_connIDs_iter = iter->listConnectionID.begin(); + for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++) + { + output << *list_connIDs_iter << " "; + } + + output << std::endl; + } + sendTelnetLine(filedescriptor,output); + } + else + { + sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks"); + } +} +} + + + + + diff --git a/AudioManagerCore/src/CAmTelnetServer.cpp b/AudioManagerCore/src/CAmTelnetServer.cpp new file mode 100755 index 0000000..22f7b0e --- /dev/null +++ b/AudioManagerCore/src/CAmTelnetServer.cpp @@ -0,0 +1,257 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * \file CAmTelnetServer.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmTelnetServer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "CAmRoutingSender.h" +#include "CAmTelnetMenuHelper.h" +#include "CAmDltWrapper.h" + +namespace am +{ + +CAmTelnetServer* CAmTelnetServer::mpInstance = 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, IAmDatabaseHandler *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), // + mpSocketHandler(iSocketHandler), // + mpCommandSender(iCommandSender), // + mpCommandReceiver(iCommandReceiver), // + mpRoutingSender(iRoutingSender), // + mpRoutingReceiver(iRoutingReceiver), // + mpControlSender(iControlSender), // + mpControlReceiver(iControlReceiver), // + mpDatabasehandler(iDatabasehandler), // + mpRouter(iRouter), // + mConnecthandle(), // + mListMessages(), // + mListConnections(), // + mConnectFD(0), // + mServerPort(servPort), // + mMaxConnections(maxConnections), // + mTelnetMenuHelper(iSocketHandler, iCommandSender, iCommandReceiver, iRoutingSender, iRoutingReceiver, iControlSender, iControlReceiver, iDatabasehandler, iRouter, this) +{ + assert(mpSocketHandler!=NULL); + assert(mpCommandReceiver!=NULL); + assert(mpCommandSender!=NULL); + assert(mpControlSender!=NULL); + assert(mpControlReceiver!=NULL); + assert(mpRoutingSender!=NULL); + assert(mpRoutingReceiver!=NULL); + assert(mpDatabasehandler!=NULL); + assert(mpRouter!=NULL); + assert(servPort!=0); + assert(mMaxConnections!=0); + + mpInstance = this; + //mTelnetMenuHelper.setTelnetServer(this); + + int yes = 1; + struct sockaddr_in servAddr; + + //setup the port Listener + mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + assert (mConnectFD>0); + assert(setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==0); + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = INADDR_ANY; + servAddr.sin_port = htons(servPort); + if(bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr))!=0) + { + logError("CAmTelnetServer::CAmTelnetServer bind failed, error",errno); + throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); + } + + if (listen(mConnectFD, mMaxConnections) < 0) + { + logError("TelnetServer::TelnetServerk cannot listen ", errno); + throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); + } + 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; + mpSocketHandler->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); + + assert(connection.filedescriptor>0); + + // Notiy menuhelper + mTelnetMenuHelper.newSocketConnection(connection.filedescriptor); + + //set the correct event: + short event = 0; + event |= POLLIN; + + //add the filedescriptor to the sockethandler and register the callbacks for receiving the data + mpSocketHandler->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 == mpSocketHandler->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, 0); + 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); + mListMessages.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()) + { + logError("CAmTelnetServer::dispatchData could not find handle !"); + return (false); + } + + std::string command; + std::queue MsgQueue; + if (!mListMessages.empty()) + { + sliceCommand(mListMessages.front(), command, MsgQueue); + mListMessages.pop(); + mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor); + } + else + { + logError("CAmTelnetServer::dispatchData Message queue was empty!"); + } + + // must return false to stop endless polling + return (false); +} + +bool CAmTelnetServer::check(const sh_pollHandle_t handle, void *userData) +{ + (void) handle; + (void) userData; + if (mListMessages.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++; + } +} +} + diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp new file mode 100644 index 0000000..9008ce6 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp @@ -0,0 +1,673 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmControlInterfaceTest.h" +#include +#include +#include +#include +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +DLT_DECLARE_CONTEXT(AudioManager) +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +ACTION(returnResyncConnection) +{ + std::vector listConnections; + am_Connection_s conn; + conn.sinkID=1; + conn.sourceID=1; + conn.connectionFormat=CF_GENIVI_ANALOG; + listConnections.push_back(conn); + arg1=listConnections; +} + +CAmControlInterfaceTest::CAmControlInterfaceTest() : + pSocketHandler(), // + plistCommandPluginDirs(), // + plistRoutingPluginDirs(), // + pDatabaseHandler(), // + pRoutingSender(plistRoutingPluginDirs), //RoutingReceiver + pCommandSender(plistCommandPluginDirs), // + pMockControlInterface(), // + pMockRoutingInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlSender(), // + pRouter(&pDatabaseHandler,&pControlSender), // + pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pDatabaseObserver); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); + pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock"); + +} + +CAmControlInterfaceTest::~CAmControlInterfaceTest() +{ + CAmDltWrapper::instance()->unregisterContext(AudioManager); +} + +void CAmControlInterfaceTest::SetUp() +{ + +} + +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 = DYNAMIC_ID_BOUNDARY; + + //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)); + //needed to be removed because logic changed here +} + +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 = DYNAMIC_ID_BOUNDARY; + + //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,ackDisconnectFailAndRetry) +{ + logInfo("ackDisconnectFailAndRetry test started"); + 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 = DYNAMIC_ID_BOUNDARY; + + //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_NON_EXISTENT)).Times(1); + pRoutingReceiver.ackDisconnect(handle, connectionID+1, E_NON_EXISTENT); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //make sure the connection is still there + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_FALSE(connectionList.empty()); + + ASSERT_TRUE(pDatabaseHandler.existConnectionID(1)); + + //Now let's try to disconnect now + EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); + logInfo("ackDisconnectFailAndRetry test finished"); +} + +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 = DYNAMIC_ID_BOUNDARY; + + //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)); + //needed to be removed because logic changed here +} + +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 = DYNAMIC_ID_BOUNDARY; + 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)); + //needed to be removed because logic changed here +} + +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 = DYNAMIC_ID_BOUNDARY; + 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)); + //needed to be removed because logic changed here +} + +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; + int16_t oldvalue; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + soundProperty.type = SP_GENIVI_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_GENIVI_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_GENIVI_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)); + //needed to be removed because logic changed here +} + +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; + int16_t oldvalue; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + soundProperty.type = SP_GENIVI_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_GENIVI_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_GENIVI_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)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,crossFading) +{ + //todo: implement crossfading test +} + +TEST_F(CAmControlInterfaceTest,resyncConnectionsTest) +{ + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + std::vector listConnections; + + EXPECT_CALL(pMockRoutingInterface,resyncConnectionState(domainID,_)).WillOnce(DoAll(returnResyncConnection(), Return(E_OK))); + ASSERT_EQ(am_Error_e::E_OK,pControlReceiver.resyncConnectionState(domainID,listConnections)); + ASSERT_EQ(listConnections[0].sinkID,1); + ASSERT_EQ(listConnections[0].sourceID,1); + ASSERT_EQ(listConnections[0].connectionFormat,CF_GENIVI_ANALOG); +} + +TEST_F(CAmControlInterfaceTest,ackConnectNotPossible) +{ + 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 = DYNAMIC_ID_BOUNDARY; + + //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_COMMUNICATION)); + ASSERT_EQ(E_COMMUNICATION, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //The list of handles shall be empty + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); + CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); + logInfo("RoutingSendInterface Test started"); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h new file mode 100644 index 0000000..b7fa27a --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h @@ -0,0 +1,76 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +//#include "CAmDatabaseHandlerSQLite.h" +#include "CAmDatabaseHandlerMap.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 "CAmSocketHandler.h" + +namespace am +{ + +class CAmControlInterfaceTest: public ::testing::Test +{ +public: + CAmControlInterfaceTest(); + ~CAmControlInterfaceTest(); + CAmSocketHandler pSocketHandler; + std::vector plistCommandPluginDirs; + std::vector plistRoutingPluginDirs; + CAmDatabaseHandlerMap 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/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..4f33ac5 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmControlInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + + file(GLOB CONTROL_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +add_executable(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmControlInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +add_test(AmControlInterfaceTest AmControlInterfaceTest) + +ADD_DEPENDENCIES(AmControlInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmControlInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests) + + + + diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ new file mode 100644 index 0000000..5b71a59 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ @@ -0,0 +1,50 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmControlInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + + file(GLOB CONTROL_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +add_executable(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmControlInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmControlInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmControlInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests) + + + + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp new file mode 100644 index 0000000..337ecb7 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp @@ -0,0 +1,3276 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmMapHandlerTest.h" +#include +#include +#include +#include +#include +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + + +extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b); +extern bool equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b); +extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b); +extern std::string int2string(int i); + +int16_t const TEST_MAX_CONNECTION_ID = 20; +int16_t const TEST_MAX_MAINCONNECTION_ID = 20; +int16_t const TEST_MAX_SINK_ID = 40; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + + +CAmMapBasicTest::CAmMapBasicTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(),// + pDatabaseHandler(), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlSender(), // + pRouter(&pDatabaseHandler, &pControlSender), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pCF() +{ +} + +CAmMapBasicTest::~CAmMapBasicTest() +{ +} + +void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection) +{ + //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 + 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)); + std::vector::iterator listIterator = mainConnectionList.begin(); + for (; listIterator < mainConnectionList.end(); ++listIterator) + { + if (listIterator->mainConnectionID == mainConnectionID) + { + ASSERT_EQ(listIterator->connectionState, mainConnection.connectionState); + ASSERT_EQ(listIterator->sinkID, mainConnection.sinkID); + ASSERT_EQ(listIterator->sourceID, mainConnection.sourceID); + ASSERT_EQ(listIterator->delay, mainConnection.delay); + ASSERT_TRUE(std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); + } + } +} + +void CAmMapBasicTest::SetUp() +{ + ::testing::FLAGS_gmock_verbose = "error"; +} + +void CAmMapBasicTest::TearDown() +{ + ::testing::FLAGS_gmock_verbose = "warning"; +} + + + +CAmMapHandlerTest::CAmMapHandlerTest() : + pMockInterface(), // + pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.setConnectionIDRange(1, TEST_MAX_CONNECTION_ID); + pDatabaseHandler.setMainConnectionIDRange(1, TEST_MAX_MAINCONNECTION_ID); + pDatabaseHandler.setSinkIDRange(DYNAMIC_ID_BOUNDARY, DYNAMIC_ID_BOUNDARY+TEST_MAX_SINK_ID); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); +} + +CAmMapHandlerTest::~CAmMapHandlerTest() +{ +} + +TEST_F(CAmMapHandlerTest,getMainConnectionInfo) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection, mainConnectionT; + createMainConnectionSetup(mainConnectionID, mainConnection); + + ASSERT_EQ(E_OK, pDatabaseHandler.getMainConnectionInfoDB(mainConnectionID,mainConnectionT)); + ASSERT_TRUE(mainConnection.connectionState == mainConnectionT.connectionState); + ASSERT_TRUE(mainConnection.delay == mainConnectionT.delay); + ASSERT_TRUE(std::equal(mainConnection.listConnectionID.begin(),mainConnection.listConnectionID.end(),mainConnectionT.listConnectionID.begin())); + ASSERT_TRUE(mainConnection.sinkID == mainConnectionT.sinkID); + ASSERT_TRUE(mainConnection.sourceID == mainConnectionT.sourceID); + ASSERT_TRUE(mainConnectionID == mainConnectionT.mainConnectionID); +} + +TEST_F(CAmMapHandlerTest,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"; + + std::vector::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); + } + } + + am_Sink_s sinkData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkInfoDB(secondDynamicSinkID,sinkData)); + ASSERT_EQ(secondDynamicSink.available.availability, sinkData.available.availability); + ASSERT_EQ(secondDynamicSink.available.availabilityReason, sinkData.available.availabilityReason); + ASSERT_EQ(secondDynamicSink.sinkClassID, sinkData.sinkClassID); + ASSERT_EQ(secondDynamicSink.domainID, sinkData.domainID); + ASSERT_EQ(secondDynamicSink.visible, sinkData.visible); + ASSERT_EQ(0, secondDynamicSink.name.compare(sinkData.name)); + ASSERT_EQ(secondDynamicSink.volume, sinkData.volume); + ASSERT_TRUE(std::equal(secondDynamicSink.listConnectionFormats.begin(), secondDynamicSink.listConnectionFormats.end(), sinkData.listConnectionFormats.begin())); + ASSERT_TRUE(std::equal(secondDynamicSink.listMainSoundProperties.begin(), secondDynamicSink.listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty)); + ASSERT_TRUE(std::equal(secondDynamicSink.listNotificationConfigurations.begin(), secondDynamicSink.listNotificationConfigurations.end(), sinkData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); + ASSERT_TRUE(std::equal(secondDynamicSink.listMainNotificationConfigurations.begin(), secondDynamicSink.listMainNotificationConfigurations.end(), sinkData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); +} + +TEST_F(CAmMapHandlerTest,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"; + + std::vector::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); + } + } + + am_Source_s sourceData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceInfoDB(secondDynamicSourceID,sourceData)); + ASSERT_EQ(secondDynamicSource.available.availability, sourceData.available.availability); + ASSERT_EQ(secondDynamicSource.available.availabilityReason, sourceData.available.availabilityReason); + ASSERT_EQ(secondDynamicSource.sourceClassID, sourceData.sourceClassID); + ASSERT_EQ(secondDynamicSource.domainID, sourceData.domainID); + ASSERT_EQ(secondDynamicSource.interruptState, sourceData.interruptState); + ASSERT_EQ(secondDynamicSource.visible, sourceData.visible); + ASSERT_EQ(0, secondDynamicSource.name.compare(sourceData.name)); + ASSERT_EQ(secondDynamicSource.volume, sourceData.volume); + ASSERT_TRUE(std::equal(secondDynamicSource.listConnectionFormats.begin(), secondDynamicSource.listConnectionFormats.end(), sourceData.listConnectionFormats.begin())); + ASSERT_TRUE(std::equal(secondDynamicSource.listMainSoundProperties.begin(), secondDynamicSource.listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty)); + ASSERT_TRUE(std::equal(secondDynamicSource.listMainNotificationConfigurations.begin(), secondDynamicSource.listMainNotificationConfigurations.end(), sourceData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); + ASSERT_TRUE(std::equal(secondDynamicSource.listNotificationConfigurations.begin(), secondDynamicSource.listNotificationConfigurations.end(), sourceData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); +} + +TEST_F(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY, listCrossfaders[0].crossfaderID); + ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0); +} + +TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY, listCrossfaders[0]); + +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest, peekSource) +{ + std::vector listSourceTypes; + 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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.empty()); + ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); + + //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_FALSE(listSources.empty()); + ASSERT_TRUE(listSources.at(0).sourceID==sourceID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_FALSE(listSourceTypes.empty()); + ASSERT_TRUE(listSourceTypes.at(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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.size()==1); + ASSERT_TRUE(listSourceTypes.at(0).sourceID==source3ID); + ASSERT_EQ(source3ID, source2ID); +} + +TEST_F(CAmMapHandlerTest, peekSourceDouble) +{ + std::vector listSourceTypes; + 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, DYNAMIC_ID_BOUNDARY); + 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.size()==1); + ASSERT_TRUE(listSources[0].sourceID==sourceID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.size()==1); + ASSERT_TRUE(listSourceTypes[0].sourceID==source3ID); +} + +TEST_F(CAmMapHandlerTest, peekSink) +{ + std::vector listSinkTypes; + 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, DYNAMIC_ID_BOUNDARY); + 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); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_FALSE(listSinkTypes.empty()); + ASSERT_TRUE(listSinkTypes.at(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); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_TRUE(listSinkTypes.size()==1); + ASSERT_TRUE(listSinkTypes.at(0).sinkID==sink3ID); +} + +TEST_F(CAmMapHandlerTest, peekSinkDouble) +{ + std::vector listSinkTypes; + 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, DYNAMIC_ID_BOUNDARY); + 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); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_TRUE(listSinkTypes.size()==1); + ASSERT_TRUE(listSinkTypes[0].sinkID==sink3ID); +} + +TEST_F(CAmMapHandlerTest,changeConnectionTimingInformationCheckMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector connectionList; + std::vector mainList; + + //prepare the test, it is one mainconnection, so we expect one callback + createMainConnectionSetup(mainConnectionID, mainConnection); + + //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->connectionID,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); + 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, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); + 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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); + 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, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,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"; + + std::vector::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); + } + + } +} + +TEST_F(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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); + } + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB({property.type, 34},sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, 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); + } + + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB({property.type, 34},sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, changeSourceSoundProperty) +{ + std::vector listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_SoundProperty_s property; + property.type = SP_GENIVI_MID; + property.value = 33; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB(property,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + + std::vector::iterator listIterator = listSources[0].listSoundProperties.begin(); + for (; listIterator < listSources[0].listSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB({property.type, 34},sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, changeSinkSoundProperty) +{ + std::vector listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_SoundProperty_s property; + property.type = SP_GENIVI_MID; + property.value = 33; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB(property,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + std::vector::iterator listIterator = listSinks[0].listSoundProperties.begin(); + for (; listIterator < listSinks[0].listSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB({property.type, 34},sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, 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, DYNAMIC_ID_BOUNDARY); + 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, changeMainConnectionState) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector listMainConnections; + createMainConnectionSetup(mainConnectionID, mainConnection); + + 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,changeMainConnectionRoute) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector originalList; + std::vector newList; + createMainConnectionSetup(mainConnectionID, mainConnection); + + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector listConnectionID; + + uint16_t i = 1; + for (; 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(mainConnectionID,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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"; + 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) + { + ASSERT_TRUE(pCF.compareSinkMainSink(listIterator, listSinks)); + } +} + +TEST_F(CAmMapHandlerTest,getVisibleMainConnections) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); + + 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(CAmMapHandlerTest,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 = DYNAMIC_ID_BOUNDARY; + 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(DYNAMIC_ID_BOUNDARY,sourceList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty()); +} + +TEST_F(CAmMapHandlerTest,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 = DYNAMIC_ID_BOUNDARY; + 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(DYNAMIC_ID_BOUNDARY+1,sinkList)) + << "ERROR: database error";ASSERT_TRUE(sinkList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(DYNAMIC_ID_BOUNDARY,sinkList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty()); +} + +TEST_F(CAmMapHandlerTest,getListGatewaysOfDomain) +{ + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID1, gatewayID2; + am_domainID_t domainID; + am_Domain_s domain; + std::vector gatewayList, gatewayCheckList; + + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + pCF.createGateway(gateway); + gateway.gatewayID = 1; + gateway.name = "testGateway"; + gateway.controlDomainID = domainID; + gateway.sourceID = 1; + gateway.sinkID = 1; + gateway.domainSinkID = 1; + gateway.domainSourceID = 1; + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(true, gatewayID1==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; + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(true, gatewayID2==2); + gatewayCheckList.push_back(gatewayID1); + + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList)) + << "ERROR: database error"; + ASSERT_TRUE(gatewayList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(domainID,gatewayList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty()); +} + +TEST_F(CAmMapHandlerTest,getListConvertersOfDomain) +{ + am_Converter_s converter, converter2; + am_converterID_t converterID1, converterID2; + am_domainID_t domainID; + am_Domain_s domain; + std::vector converterList, converterCheckList; + + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + pCF.createConverter(converter); + converter.converterID = 1; + converter.name = "testGateway"; + converter.sourceID = 1; + converter.sinkID = 1; + converter.domainID = domainID; + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID1)) + << "ERROR: database error"; + ASSERT_EQ(true, converterID1==1); + + pCF.createConverter(converter2); + converter2.converterID = 2; + converter2.name = "testGateway2"; + converter2.domainID = 4; + converter2.sourceID = 1; + converter2.sinkID = 1; + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter2,converterID2)) + << "ERROR: database error"; + ASSERT_EQ(true, converterID2==2); + converterCheckList.push_back(converterID1); + + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(4,converterList)) + << "ERROR: database error"; + ASSERT_TRUE(converterList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(domainID,converterList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(converterList.begin(),converterList.end(),converterCheckList.begin()) && !converterList.empty()); +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,removeConverter) +{ + am_Converter_s converter; + am_converterID_t converterID; + std::vector listConverters; + pCF.createConverter(converter); + 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.enterConverterDB(converter,converterID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(converterID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(listConverters)) + << "ERROR: database error"; + ASSERT_TRUE(listConverters.empty()); +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest, removeMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); + + ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentMainConnectionFail) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentSource) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentSink) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentGateway) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentConverter) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(12)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); + } + + if (listIterator->gatewayID == gatewayID1) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); + } + + if (listIterator->gatewayID == gatewayID2) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); + } + } +} + +TEST_F(CAmMapHandlerTest,registerConverterCorrect) +{ + //initialize gateway + std::vector returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(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.enterConverterDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->converterID == gatewayID) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); + } + + if (listIterator->converterID == gatewayID1) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); + } + + if (listIterator->converterID == gatewayID2) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); + } + } +} + +TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); + } + + if (listIterator->gatewayID == gatewayID1) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); + } + + if (listIterator->gatewayID == gatewayID2) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); + } + } + + am_Gateway_s gatewayInfo; + ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo)); + ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo)); + +} + +TEST_F(CAmMapHandlerTest,getConverterInfo) +{ + //initialize gateway + std::vector returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(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.enterConverterDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); + std::vector::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->converterID == gatewayID) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); + } + + if (listIterator->converterID == gatewayID1) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); + } + + if (listIterator->converterID == gatewayID2) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); + } + } + + am_Converter_s gatewayInfo; + ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo)); + ASSERT_TRUE(pCF.compareConverter1(gateway1,gatewayInfo)); + +} + +TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,registerDomainPredefined) +{ + //initialize domain + std::vector returnList; + am_Domain_s domain; + am_domainID_t domainID = 10; + pCF.createDomain(domain); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_NE(10,domainID) + << "ERROR: domainID not predefined one"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); + std::vector::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->domainID == domainID) + { + ASSERT_EQ(0, listIterator->name.compare(domain.name)); + ASSERT_EQ(0, listIterator->busname.compare(domain.busname)); + ASSERT_EQ(domain.complete, listIterator->complete); + ASSERT_EQ(domain.early, listIterator->early); + ASSERT_EQ(domain.state, listIterator->state); + } + } +} + +TEST_F(CAmMapHandlerTest,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)); + std::vector::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->connectionID == connectionID) + { + ASSERT_EQ(connection.sourceID, listIterator->sourceID); + ASSERT_EQ(connection.sinkID, listIterator->sinkID); + ASSERT_EQ(connection.delay, listIterator->delay); + ASSERT_EQ(connection.connectionFormat, listIterator->connectionFormat); + } + } +} + +TEST_F(CAmMapHandlerTest,enterMainConnectionCorrect) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); +} + +TEST_F(CAmMapHandlerTest,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"; + + std::vector::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); + } + } +} + +TEST_F(CAmMapHandlerTest,enterNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData, readoutData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + testSinkData.listNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].type,notify.type); + + ASSERT_EQ(E_OK,pDatabaseHandler.getSinkInfoDB(testSinkData.sinkID,readoutData)) + << "ERROR: database error"; + + ASSERT_EQ(readoutData.listNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(readoutData.listNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(readoutData.listNotificationConfigurations[2].type,notify.type); + +} + +TEST_F(CAmMapHandlerTest,enterMainNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); +} + +TEST_F(CAmMapHandlerTest,removeNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); + + //now we remove the sink + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)); +} + +TEST_F(CAmMapHandlerTest,removeNotificationsSource) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector listSources; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) + << "ERROR: database error"; + + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].type,notify.type); + + //now we remove the sink + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)); +} + +TEST_F(CAmMapHandlerTest,getMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + std::vectorreturnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_UNKNOWN; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSinkData.listMainNotificationConfigurations.push_back(notify1); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + +} + +TEST_F(CAmMapHandlerTest,getMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector listSources; + std::vectorreturnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_UNKNOWN; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSourceData.listMainNotificationConfigurations.push_back(notify1); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + std::equal(testSourceData.listMainNotificationConfigurations.begin(),testSourceData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + +} + +TEST_F(CAmMapHandlerTest,changeMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector listSources; + std::vectorreturnList,returnList1; + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(true, std::equal(testSourceData.listMainNotificationConfigurations.begin(), + testSourceData.listMainNotificationConfigurations.end(), + returnList.begin(), + equalNotificationConfiguration)); + + //change notification which is not available + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=10; + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); + //change a setting + notify.type=NT_TEST_2; + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); + + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].parameter,notify.parameter); + ASSERT_EQ(returnList1[1].status,notify.status); + ASSERT_EQ(returnList1[1].type,notify.type); + +} + +TEST_F(CAmMapHandlerTest,changeMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + std::vectorreturnList,returnList1; + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + + //change notification which is not available + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=27; + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) + << "ERROR: database error"; + //change a setting + notify.type=NT_TEST_2; + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) + << "ERROR: database error"; + + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].parameter,notify.parameter); + ASSERT_EQ(returnList1[1].status,notify.status); + ASSERT_EQ(returnList1[1].type,notify.type); +} + +TEST_F(CAmMapHandlerTest, peekDomain_2) +{ + 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, DYNAMIC_ID_BOUNDARY); + + domain.name = "anotherdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); + + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 + bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { + return ref.domainID==domainID; + })!=listDomains.end(); + ASSERT_TRUE(containsDomainID); +} + +TEST_F(CAmMapHandlerTest, connectionIDBoundary) +{ + am_Sink_s sink; + am_Source_s source; + am_Connection_s connection; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = 0; + source.name = "source" + int2string(i); + source.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); + connection.sinkID = forgetSink; + connection.sourceID = forgetSource; + if( i < TEST_MAX_CONNECTION_ID ) + { + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(i, connectionID); + } + } + std::vector connectionList; + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast(connectionList.size())); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + logInfo("here"); + ASSERT_EQ(0, connectionID); + + ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(12)); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(10, connectionID); + connection.sinkID = 77; + connection.sourceID = 77; + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(12, connectionID); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(0, connectionID); +} + +TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) +{ + am_Sink_s sink; + am_Source_s source; + am_Connection_s connection; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + std::vector connectionIDList; + for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = 0; + source.name = "source" + int2string(i); + source.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); + connection.sinkID = forgetSink; + connection.sourceID = forgetSource; + if( i < TEST_MAX_CONNECTION_ID ) + { + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(i, connectionID); + connectionIDList.push_back(i); + } + } + std::vector connectionList; + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast(connectionList.size())); + + //create a mainConnection + + am_MainConnection_s mainConnection; + am_mainConnectionID_t mainConnectionID; + mainConnection.listConnectionID = connectionIDList; + mainConnection.mainConnectionID = 0; + mainConnection.connectionState = CS_CONNECTED; + mainConnection.delay = -1; + + for (uint16_t i = 1; i < TEST_MAX_MAINCONNECTION_ID; i++) + { + mainConnection.sinkID = DYNAMIC_ID_BOUNDARY + i; + mainConnection.sourceID = DYNAMIC_ID_BOUNDARY + i; + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(i, mainConnectionID); + } + ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(12)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(10, mainConnectionID); + mainConnection.sinkID = 77; + mainConnection.sourceID = 77; + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(12, mainConnectionID); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(0, mainConnectionID); +} + +TEST_F(CAmMapHandlerTest, increaseID) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + for (uint16_t i = 0; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+i, sinkID); + } + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+12)); + + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); +} + + +CAmMapHandlerObserverCallbacksTest::CAmMapHandlerObserverCallbacksTest() : + mMockObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&mMockObserver); +} + +CAmMapHandlerObserverCallbacksTest::~CAmMapHandlerObserverCallbacksTest() +{ +} + +MATCHER_P(IsDomainDataEqualTo, value, "") { + auto lh = arg; + return lh.domainID == value.domainID && + lh.name == value.name && + lh.nodename == value.nodename && + lh.early == value.early && + lh.complete == value.complete && + lh.state == value.state; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_removeDomain) +{ + 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, DYNAMIC_ID_BOUNDARY); + + domain.name = "anotherdomain"; + const am_Domain_s expDomain1 = {DYNAMIC_ID_BOUNDARY+1, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain1))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); + domain.name = "newdomain"; + const am_Domain_s expDomain2 = {DYNAMIC_ID_BOUNDARY, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 + bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { + return ref.domainID==domainID; + })!=listDomains.end(); + ASSERT_TRUE(containsDomainID); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeDomain(domainID)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSource) +{ + 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, DYNAMIC_ID_BOUNDARY); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY+2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(source3ID, DYNAMIC_ID_BOUNDARY+2); + + 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 + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source3ID); + bool containsSourceID = std::find_if(listSources.begin(), listSources.end(), [&](const am_Source_s & ref) { + return ref.sourceID==sourceID; + })!=listSources.end(); + ASSERT_TRUE(containsSourceID); + + std::vector listSoundProperties; + std::vector listConnectionFormats; + std::vector listMainSoundProperties; +#ifndef WITH_DATABASE_CHANGE_CHECK + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#else + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(0); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of class id + source.sourceClassID++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, source.sourceClassID, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of main sound properties + am_MainSoundProperty_s mainSoundProperties; + mainSoundProperties.type = MSP_GENIVI_TREBLE; + mainSoundProperties.value = 0; + listMainSoundProperties.push_back(mainSoundProperties); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#endif + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSource(sourceID, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSink) +{ + 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, DYNAMIC_ID_BOUNDARY); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY+2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(sink3ID, DYNAMIC_ID_BOUNDARY+2); + + 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 + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink3ID); + bool containsSourceID = std::find_if(listSinks.begin(), listSinks.end(), [&](const am_Sink_s & ref) { + return ref.sinkID==sinkID; + })!=listSinks.end(); + ASSERT_TRUE(containsSourceID); + + std::vector listSoundProperties; + std::vector listConnectionFormats; + std::vector listMainSoundProperties; +#ifndef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#else + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(0); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of class id + sink.sinkClassID++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, sink.sinkClassID, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of main sound properties + am_MainSoundProperty_s mainSoundProperties; + mainSoundProperties.type = MSP_GENIVI_TREBLE; + mainSoundProperties.value = 0; + listMainSoundProperties.push_back(mainSoundProperties); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#endif + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(sinkID, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) +{ + 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 + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); + 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(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) +{ + 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 + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); + 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(CAmMapHandlerObserverCallbacksTest, enter_removeGateway) +{ + //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; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, 20))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))<< "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY+1))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeGateway(gatewayID2)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID2))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter) +{ + //initialize gateway + std::vector returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(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; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 20))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))<< "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY+1))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeConverter(gatewayID2)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID2))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader) +{ + 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); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + 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; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newCrossfader(Field(&am_Crossfader_s::crossfaderID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeCrossfader(crossfaderID)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeCrossfaderDB(crossfaderID))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_update_removeMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(9); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(9); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(Field(&am_MainConnectionType_s::mainConnectionID, 1))).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, CS_CONNECTED)).Times(1); +#ifndef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(1); +#else + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(0); +#endif + createMainConnectionSetup(mainConnectionID, mainConnection); + + //change delay of first connection + am_timeSync_t delay = 20; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 20)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); +#endif + + //change delay of route + delay = 40; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 40)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); +#endif + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(1)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, 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; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); + 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); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); + availability.availability = A_AVAILABLE; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, 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; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); + 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); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); + availability.availability = A_AVAILABLE; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest,changeMainSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_mainVolume_t newVol = 20; + std::vector listSinks; + pCF.createSink(sink); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged(sinkID, newVol)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].mainVolume, newVol); + +#ifdef WITH_DATABASE_CHANGE_CHECK + am_mainVolume_t incVol = 21; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged( sinkID, incVol)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(incVol,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkMuteState) +{ + std::vector listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MuteState_e muteState = MS_MUTED; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, muteState)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(muteState, listSinks[0].muteState); + +#ifdef WITH_DATABASE_CHANGE_CHECK + am_MuteState_e newMuteState = MS_UNMUTED; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, newMuteState)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(newMuteState,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, 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; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); + 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); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); + systemProperty.value = 33; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector listSinks; + std::vectorreturnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_TEST_1; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_TEST_1; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSinkData.listMainNotificationConfigurations.push_back(notify1); + + am_NotificationConfiguration_s notify2; + notify2.type=NT_TEST_2; + notify2.status=NS_CHANGE; + notify2.parameter=27; + + testSinkData.listMainNotificationConfigurations.push_back(notify2); + + //enter the sink in the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID, returnList)) + << "ERROR: database error"; + ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; + + //change a setting + notify2.parameter++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMainNotificationConfigurationChanged(sinkID, _)).Times(1); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify1)); +#endif + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSources) +{ + + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector listSources; + std::vectorreturnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_TEST_1; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_TEST_1; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSourceData.listMainNotificationConfigurations.push_back(notify1); + + am_NotificationConfiguration_s notify2; + notify2.type=NT_TEST_2; + notify2.status=NS_CHANGE; + notify2.parameter=10; + + testSourceData.listMainNotificationConfigurations.push_back(notify2); + + //enter the sink in the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; + + //change a setting + notify2.parameter++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceMainNotificationConfigurationChanged(sourceID, _)).Times(1); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify1)); +#endif + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2)); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("databse", "databasetest"); + logInfo("Database Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h new file mode 100644 index 0000000..e3cc0ef --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h @@ -0,0 +1,92 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MAPHANDLERTEST_H_ +#define MAPHANDLERTEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "CAmSocketHandler.h" +#include "CAmDatabaseHandlerMap.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 "MockDatabaseObserver.h" + +namespace am +{ + +class CAmMapBasicTest : public ::testing::Test +{ +public: + CAmMapBasicTest(); + ~CAmMapBasicTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmControlReceiver pControlReceiver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + void createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection); +}; + +class CAmMapHandlerTest: public CAmMapBasicTest +{ +public: + CAmMapHandlerTest(); + ~CAmMapHandlerTest(); + MockIAmCommandSend pMockInterface; + CAmDatabaseObserver pObserver; +}; + +class CAmMapHandlerObserverCallbacksTest : public CAmMapBasicTest +{ +public: + CAmMapHandlerObserverCallbacksTest(); + ~CAmMapHandlerObserverCallbacksTest(); + CAmDatabaseObserver mMockObserver; +}; + + +} + +#endif /* MAPHANDLERTEST_H_ */ diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp new file mode 100644 index 0000000..a035cee --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp @@ -0,0 +1,98 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmTestDatabaseObserver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmDatabaseObserver.h" +#include "MockDatabaseObserver.h" + +namespace am { + +CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : +mCommandSender(iCommandSender), // +mRoutingSender(iRoutingSender), // +mTelnetServer(NULL), // +mSerializer(iSocketHandler) // +{} + +CAmDatabaseObserver::~CAmDatabaseObserver() {} + + +void CAmDatabaseObserver::numberOfSinkClassesChanged() +{ MockDatabaseObserver::getMockObserverObject()->numberOfSinkClassesChanged(); } +void CAmDatabaseObserver::numberOfSourceClassesChanged() +{ MockDatabaseObserver::getMockObserverObject()->numberOfSourceClassesChanged(); } +void CAmDatabaseObserver::newSink(const am_Sink_s& sink) +{ MockDatabaseObserver::getMockObserverObject()->newSink(sink); } +void CAmDatabaseObserver::newSource(const am_Source_s& source) +{ MockDatabaseObserver::getMockObserverObject()->newSource(source); } +void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) +{ MockDatabaseObserver::getMockObserverObject()->newDomain(domain); } +void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) +{ MockDatabaseObserver::getMockObserverObject()->newGateway(gateway); } +void CAmDatabaseObserver::newConverter(const am_Converter_s& coverter) +{ MockDatabaseObserver::getMockObserverObject()->newConverter(coverter); } +void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) +{ MockDatabaseObserver::getMockObserverObject()->newCrossfader(crossfader); } +void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) +{ MockDatabaseObserver::getMockObserverObject()->newMainConnection(mainConnection); } +void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) +{ MockDatabaseObserver::getMockObserverObject()->removedMainConnection(mainConnection); } +void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->removedSink(sinkID, visible); } +void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->removedSource(sourceID, visible); } +void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) +{ MockDatabaseObserver::getMockObserverObject()->removeDomain(domainID); } +void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) +{ MockDatabaseObserver::getMockObserverObject()->removeGateway(gatewayID); } +void CAmDatabaseObserver::removeConverter(const am_converterID_t converterID) +{ MockDatabaseObserver::getMockObserverObject()->removeConverter(converterID); } +void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) +{ MockDatabaseObserver::getMockObserverObject()->removeCrossfader(crossfaderID); } +void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) +{ MockDatabaseObserver::getMockObserverObject()->mainConnectionStateChanged(connectionID, connectionState); } +void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) +{ MockDatabaseObserver::getMockObserverObject()->mainSinkSoundPropertyChanged(sinkID, SoundProperty); } +void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) +{ MockDatabaseObserver::getMockObserverObject()->mainSourceSoundPropertyChanged(sourceID, SoundProperty); } +void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) +{ MockDatabaseObserver::getMockObserverObject()->sinkAvailabilityChanged(sinkID, availability); } +void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) +{ MockDatabaseObserver::getMockObserverObject()->sourceAvailabilityChanged(sourceID, availability); } +void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ MockDatabaseObserver::getMockObserverObject()->volumeChanged(sinkID, volume); } +void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ MockDatabaseObserver::getMockObserverObject()->sinkMuteStateChanged(sinkID, muteState); } +void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) +{ MockDatabaseObserver::getMockObserverObject()->systemPropertyChanged(SystemProperty); } +void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) +{ MockDatabaseObserver::getMockObserverObject()->timingInformationChanged(mainConnection,time); } +void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->sinkUpdated(sinkID,sinkClassID,listMainSoundProperties, visible); } +void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->sourceUpdated(sourceID,sourceClassID,listMainSoundProperties, visible); } +void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ MockDatabaseObserver::getMockObserverObject()->sinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration); } +void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ MockDatabaseObserver::getMockObserverObject()->sourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration); } +} + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt new file mode 100644 index 0000000..6588710 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmMapHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS} +) + +file(GLOB DATABASE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "CAmTestDatabaseObserver.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmMapHandlerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmMapHandlerTest AudioManagerCore) + +INSTALL(TARGETS AmMapHandlerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ new file mode 100644 index 0000000..05d2a05 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ @@ -0,0 +1,54 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmMapHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${GMOCK_INCLUDE_DIRS} +) + +if(WITH_DLT) + INCLUDE_DIRECTORIES( + ${INCLUDE_DIRECTORIES} + ${DLT_INCLUDE_DIRS}) +endif(WITH_DLT) + +file(GLOB DATABASE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "CAmTestDatabaseObserver.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmMapHandlerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmMapHandlerTest AudioManagerCore) + +INSTALL(TARGETS AmMapHandlerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h new file mode 100644 index 0000000..da1b3b4 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h @@ -0,0 +1,120 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file MockDatabaseObserver.h + * For further information see http://www.genivi.org/. + * + */ + + +#ifndef MOCKDATABASEOBSERVER_H_ +#define MOCKDATABASEOBSERVER_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "CAmDatabaseObserver.h" + +class CAmCommandSender; +class CAmRoutingSender; +class CAmSocketHandler; +class CAmTelnetServer; + +namespace am { +using namespace testing; + +class IAmDatabaseObserver +{ +public: + IAmDatabaseObserver() {}; + virtual ~IAmDatabaseObserver() {}; + + virtual void numberOfSinkClassesChanged() = 0; + virtual void numberOfSourceClassesChanged() = 0; + virtual void newSink(const am_Sink_s& sink) = 0; + virtual void newSource(const am_Source_s& source) = 0; + virtual void newDomain(const am_Domain_s& domain) = 0; + virtual void newGateway(const am_Gateway_s& gateway) = 0; + virtual void newConverter(const am_Converter_s& coverter) = 0; + virtual void newCrossfader(const am_Crossfader_s& crossfader) = 0; + virtual void newMainConnection(const am_MainConnectionType_s& mainConnection) = 0; + virtual void removedMainConnection(const am_mainConnectionID_t mainConnection) = 0; + virtual void removedSink(const am_sinkID_t sinkID, const bool visible) = 0; + virtual void removedSource(const am_sourceID_t sourceID, const bool visible) = 0; + virtual void removeDomain(const am_domainID_t domainID) = 0; + virtual void removeGateway(const am_gatewayID_t gatewayID) = 0; + virtual void removeConverter(const am_converterID_t converterID) = 0; + virtual void removeCrossfader(const am_crossfaderID_t crossfaderID) = 0; + virtual void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) = 0; + virtual void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) = 0; + virtual void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) = 0; + virtual void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) = 0; + virtual void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) = 0; + virtual void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) = 0; + virtual void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) = 0; + virtual void systemPropertyChanged(const am_SystemProperty_s& SystemProperty) = 0; + virtual void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) = 0; + virtual void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) = 0; + virtual void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) = 0; + virtual void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + virtual void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + +}; + +class MockDatabaseObserver : public IAmDatabaseObserver{ + public: + MOCK_METHOD0(numberOfSinkClassesChanged, void()); + MOCK_METHOD0(numberOfSourceClassesChanged, void()); + MOCK_METHOD1(newSink, void(const am_Sink_s& sink)); + MOCK_METHOD1(newSource, void(const am_Source_s& source)); + MOCK_METHOD1(newDomain, void(const am_Domain_s& domain)); + MOCK_METHOD1(newGateway, void(const am_Gateway_s& gateway)); + MOCK_METHOD1(newConverter, void(const am_Converter_s& converter)); + MOCK_METHOD1(newCrossfader, void(const am_Crossfader_s& crossfader)); + MOCK_METHOD1(newMainConnection, void(const am_MainConnectionType_s & mainConnection)); + MOCK_METHOD1(removedMainConnection, void(const am_mainConnectionID_t mainConnection)); + MOCK_METHOD2(removedSink, void(const am_sinkID_t sinkID, const bool visible)); + MOCK_METHOD2(removedSource, void(const am_sourceID_t sourceID, const bool visible)); + MOCK_METHOD1(removeDomain, void(const am_domainID_t domainID)); + MOCK_METHOD1(removeGateway, void(const am_gatewayID_t gatewayID)); + MOCK_METHOD1(removeConverter, void(const am_converterID_t converterID)); + MOCK_METHOD1(removeCrossfader, void(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD2(mainConnectionStateChanged, void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); + MOCK_METHOD2(mainSinkSoundPropertyChanged, void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty)); + MOCK_METHOD2(mainSourceSoundPropertyChanged, void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty)); + MOCK_METHOD2(sinkAvailabilityChanged, void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(sourceAvailabilityChanged, void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(volumeChanged, void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); + MOCK_METHOD2(sinkMuteStateChanged, void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD1(systemPropertyChanged, void(const am_SystemProperty_s& SystemProperty)); + MOCK_METHOD2(timingInformationChanged, void(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)); + MOCK_METHOD4(sinkUpdated, void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible)); + MOCK_METHOD4(sourceUpdated, void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible)); + MOCK_METHOD2(sinkMainNotificationConfigurationChanged, void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + MOCK_METHOD2(sourceMainNotificationConfigurationChanged, void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + + static MockDatabaseObserver *getMockObserverObject() + { + static MockDatabaseObserver glMockObserverObject; + return &glMockObserverObject; + } +}; + + + +} // namespace am +#endif /* MOCKDATABASEOBSERVER_H_ */ diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp new file mode 100644 index 0000000..f95a24a --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -0,0 +1,3183 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 + * + * For further information see http://www.genivi.org/. + * + */ + +#include +#include +#include "CAmRouterMapTest.h" +#include +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + + +using namespace am; +using namespace testing; + +CAmRouterMapTest::CAmRouterMapTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pControlSender(), // + pDatabaseHandler(), + 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); +} + +CAmRouterMapTest::~CAmRouterMapTest() +{ + +} + +void CAmRouterMapTest::SetUp() +{ + logInfo("Routing Test started "); +} + +void CAmRouterMapTest::TearDown() +{ +} + +ACTION(returnConnectionFormat){ + arg4=arg3; +} + +void CAmRouterMapTest::enterDomainDB(const std::string & domainName, am_domainID_t & domainID) +{ + am_Domain_s domain1; + domain1.domainID = 0; + domain1.name = domainName; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID)); +} + +void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID) +{ + am_Source_s source; + source.domainID = domainID; + source.name = sourceName; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); +} + +void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID) +{ + am_Sink_s sink; + sink.domainID = domainID; + sink.name = sinkName; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); +} + +void CAmRouterMapTest::enterGatewayDB(const std::string & gwName, + const am_domainID_t domainSourceID, + const am_domainID_t domainSinkID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, + const std::vector & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_gatewayID_t & gatewayID) +{ + am_Gateway_s gateway; + gateway.controlDomainID = domainSourceID; + gateway.gatewayID = 0; + gateway.sinkID = sinkID; + gateway.sourceID = sourceID; + gateway.domainSourceID = domainSourceID; + gateway.domainSinkID = domainSinkID; + gateway.listSinkFormats = sinkConnectionFormats; + gateway.listSourceFormats = sourceConnectionFormats; + gateway.convertionMatrix = matrix; + gateway.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); +} + +void CAmRouterMapTest::enterConverterDB(const std::string & gwName, + const am_domainID_t domainID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, + const std::vector & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_converterID_t & converterID) +{ + am_Converter_s converter; + converter.converterID = 0; + converter.sinkID = sinkID; + converter.sourceID = sourceID; + converter.domainID = domainID; + converter.listSinkFormats = sinkConnectionFormats; + converter.listSourceFormats = sourceConnectionFormats; + converter.convertionMatrix = matrix; + converter.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter,converterID)); +} + +void CAmRouterMapTest::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, aSource, aSink, listRoutes)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getRoute did find " << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; + std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, sourceID, sinkID, returnList)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getRoute by id did find " << returnList.size() <<" routes from " << sourceID << " to " << sinkID; + std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector & resultPath, + std::vector> & resultNodesPath, + const bool includeCycles) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getAllPaths(aSource, aSink, resultPath, resultNodesPath, includeCycles)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getAllPaths did find " << resultPath.size() + << " routes from " << aSource.getData().data.source->sourceID + << " to " << aSink.getData().data.sink->sinkID; + std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +TEST_F(CAmRouterMapTest,checkInsertedDomain) +{ + std::vector domains; + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60)); +} + +//test that checks just sinks and source in a domain but connectionformats do not match +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); +} + +//test that checks just sinks and source in a domain +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + + getRoute(true,sourceID,sinkID,listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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)); + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, with gateway for each direction (possible circular route) +TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) +{ + 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, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID2; + + 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); + + gwSource2.domainID = domainID1; + gwSource2.name = "gwsource2"; + gwSource2.sourceState = SS_ON; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.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(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID2; + + 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); + + gwSink2.domainID = domainID2; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID, 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"; + + gateway2.controlDomainID = domainID1; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID1; + gateway2.domainSinkID = domainID2; + 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(gateway2,gatewayID2)); + + 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::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { + return pCF.compareRoute(compareRoute, ref); + })!=listRoutes.end(); + bool containsRoute2 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { + return pCF.compareRoute(compareRoute1, ref); + })!=listRoutes.end(); + + ASSERT_TRUE(containsRoute1); + ASSERT_TRUE(containsRoute2); +} + +//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); +} +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); + } + +//test that checks 3 domains, one sink one source. +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 4 domains, one sink and one source. +TEST_F(CAmRouterMapTest,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; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,getAllowedFormatsFromConvMatrix) +{ + std::vector convertionMatrix; + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + convertionMatrix.push_back(0); + convertionMatrix.push_back(1); + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + + std::vector listSourceFormats; + listSourceFormats.push_back(CF_GENIVI_ANALOG); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + std::vector listSinkFormats; + listSinkFormats.push_back(CF_GENIVI_MONO); + listSinkFormats.push_back(CF_GENIVI_AUTO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + std::vector sourceFormats; + std::vector sinkFormats; + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + ASSERT_TRUE(sourceFormats.size()==3); + ASSERT_TRUE(sinkFormats.size()==3); + ASSERT_TRUE(sourceFormats.at(0)==CF_GENIVI_ANALOG); + ASSERT_TRUE(sourceFormats.at(1)==CF_GENIVI_STEREO); + ASSERT_TRUE(sourceFormats.at(2)==CF_GENIVI_ANALOG); + ASSERT_TRUE(sinkFormats.at(0)==CF_GENIVI_MONO); + ASSERT_TRUE(sinkFormats.at(1)==CF_GENIVI_AUTO); + ASSERT_TRUE(sinkFormats.at(2)==CF_GENIVI_STEREO); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + listSourceFormats.push_back(CF_GENIVI_STEREO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_ANALOG); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + std::vector cf2; + cf2.push_back(CF_GENIVI_ANALOG); + cf2.push_back(CF_GENIVI_MONO); + enterSinkDB("sink1", domainID1, cf2, sinkID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sourceID = sourceID; + hopp1.sinkID = sinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = cf2[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_AUTO); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID1, sinkID2; + std::vector cf2; + cf2.push_back(CF_GENIVI_MONO); + cf2.push_back(CF_GENIVI_ANALOG); + enterSinkDB("sink1", domainID1, cf2, sinkID1); + enterSinkDB("sink2", domainID1, cf2, sinkID2); + + am_sourceID_t gwSourceID; + std::vector cf3; + cf3.push_back(CF_GENIVI_MONO); + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID1, cf3, gwSourceID); + + am_sinkID_t gwSinkID; + std::vector cf4; + cf4.push_back(CF_GENIVI_STEREO); + cf4.push_back(CF_GENIVI_ANALOG); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + + am_converterID_t converterID; + std::vector matrix; + matrix.resize(4, false); + matrix[0]=(true); + matrix[1]=(true); + enterConverterDB("converter", domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, converterID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID1, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = CF_GENIVI_STEREO; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = sinkID1; + hopp2.domainID = domainID1; + hopp2.connectionFormat = CF_GENIVI_MONO; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID1; + compareRoute.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + std::vector cf2; + cf2.push_back(CF_GENIVI_MONO); + std::vector cf3; + cf3.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cf3, sinkID); + + am_sourceID_t gwSourceID; + enterSourceDB("gwSource1", domainID1, cf2, gwSourceID); + am_sinkID_t gwSinkID; + enterSinkDB("gwSink1", domainID1, cf1, gwSinkID); + am_converterID_t converterID; + std::vector matrix; + matrix.push_back(true); + enterConverterDB("converter1", domainID1, cf2, cf1, matrix, gwSourceID, gwSinkID, converterID); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource2", domainID1, cf2, gwSourceID1); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink2", domainID1, cf1, gwSinkID1); + am_converterID_t converterID1; + enterConverterDB("converter2", domainID1, cf2, cf1, matrix, gwSourceID1, gwSinkID1, converterID1); + + am_sourceID_t gwSourceID2; + enterSourceDB("gwSource3", domainID1, cf3, gwSourceID2); + am_sinkID_t gwSinkID2; + enterSinkDB("gwSink3", domainID1, cf2, gwSinkID2); + am_converterID_t converterID2; + enterConverterDB("converter3", domainID1, cf3, cf2, matrix, gwSourceID2, gwSinkID2, converterID2); + + am::am_Source_s source; + am::am_Sink_s sink; + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + + std::vector listRoutes; + std::vector listRoutingElements1; + std::vector listRoutingElements2; + am_RoutingElement_s hopp11; + am_RoutingElement_s hopp12; + am_RoutingElement_s hopp13; + am_RoutingElement_s hopp21; + am_RoutingElement_s hopp22; + + hopp11.sourceID = sourceID; + hopp11.sinkID = gwSinkID; + hopp11.domainID = domainID1; + hopp11.connectionFormat = CF_GENIVI_STEREO; + + hopp12.sourceID = gwSourceID; + hopp12.sinkID = gwSinkID2; + hopp12.domainID = domainID1; + hopp12.connectionFormat = CF_GENIVI_MONO; + + hopp21.sourceID = sourceID; + hopp21.sinkID = gwSinkID1; + hopp21.domainID = domainID1; + hopp21.connectionFormat = CF_GENIVI_STEREO; + + hopp22.sourceID = gwSourceID1; + hopp22.sinkID = gwSinkID2; + hopp22.domainID = domainID1; + hopp22.connectionFormat = CF_GENIVI_MONO; + + hopp13.sourceID = gwSourceID2; + hopp13.sinkID = sinkID; + hopp13.domainID = domainID1; + hopp13.connectionFormat = CF_GENIVI_AUTO; + + listRoutingElements1.push_back(hopp11); + listRoutingElements1.push_back(hopp12); + listRoutingElements1.push_back(hopp13); + + listRoutingElements2.push_back(hopp21); + listRoutingElements2.push_back(hopp22); + listRoutingElements2.push_back(hopp13); + + am_Route_s compareRoute1; + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(2), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); + + am_Route_s compareRoute2; + compareRoute2.route = listRoutingElements2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])||pCF.compareRoute(compareRoute2,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + std::vector cf2; + cf2.push_back(CF_GENIVI_ANALOG); + enterSinkDB("sink1", domainID2, cf2, sinkID); + + am_sourceID_t gwSourceID; + std::vector cf3; + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID2, cf3, gwSourceID); + + am_sinkID_t gwSinkID; + std::vector cf4; + cf4.push_back(CF_GENIVI_STEREO); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + + am_gatewayID_t gatewayID; + std::vector matrix; + matrix.push_back(true); + enterGatewayDB("gateway", domainID2, domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, gatewayID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + std::vector listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID, sinkID, domainID2, CF_GENIVI_ANALOG}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + + std::vector matrix; + matrix.push_back(true); + + am_gatewayID_t gatewayID; + enterGatewayDB("gateway", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); + + am_sourceID_t gwSourceID2; + enterSourceDB("gwSource2", domainID3, cfStereo, gwSourceID2); + + am_sinkID_t gwSinkID2; + enterSinkDB("gwSink2", domainID2, cfMono, gwSinkID2); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); + + am_gatewayID_t gatewayID1; + enterGatewayDB("gateway", domainID3, domainID2, cfStereo, cfMono, matrix, gwSourceID2, gwSinkID2, gatewayID1); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID1, gwSinkID2, domainID2, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID2, sinkID, domainID3, CF_GENIVI_STEREO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID1, cfStereo, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID1, cfMono, coSourceID21); + + am_converterID_t converterID1; + enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource21", domainID2, cfAuto, gwSourceID1); + + am_gatewayID_t gatewayID; + enterGatewayDB("gateway1", domainID2, domainID1, cfAuto, cfMono, matrix, gwSourceID1, gwSinkID1, gatewayID); + + am_sinkID_t sinkID1; + enterSinkDB("sink1", domainID2, cfAuto, sinkID1); + + am_sinkID_t sinkID2; + enterSinkDB("sink2", domainID1, cfAuto, sinkID2); + + am::am_Source_s source; + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sinkID1, sink1); + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(sinkID2, sink2); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + + getRoute(false, source, sink1, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID1; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, coSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({coSourceID21, gwSinkID1, domainID1, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID1, sinkID1, domainID2, CF_GENIVI_AUTO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + + listRoutes.clear(); + getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); + am_sourceID_t gwSourceID11; + enterSourceDB("gwSource11", domainID2, cfAnalog, gwSourceID11); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID11, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfAnalog, gwSinkID21); + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfAnalog, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfAnalog, sink2ID); + + std::vector listRoutes; + + am::am_Source_s source; + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + getRoute(false, source, sink1, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); + + getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID11, sink2ID, domainID2, CF_GENIVI_ANALOG}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); + + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfStereo, sink2ID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sink1ID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); + getRoute(false, source, sink1, listRoutes); + + ASSERT_EQ(static_cast(1), listRoutes.size()); + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + compareRoute1.route.push_back({coSourceID21, sink2ID, domainID2, CF_GENIVI_STEREO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + std::vector cfFuture1; + cfFuture1.push_back(5); + std::vector cfFuture2; + cfFuture2.push_back(6); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t coSinkID11; + enterSinkDB("coSink11", domainID1, cfStereo, coSinkID11); + am_sourceID_t coSourceID11; + enterSourceDB("coSource11", domainID1, cfFuture1, coSourceID11); + am_converterID_t converterID11; + enterConverterDB("converter11", domainID1, cfFuture1, cfStereo, matrix, coSourceID11, coSinkID11, converterID11); + + am_sinkID_t coSinkID12; + enterSinkDB("coSink12", domainID1, cfStereo, coSinkID12); + am_sourceID_t coSourceID12; + enterSourceDB("coSource12", domainID1, cfFuture2, coSourceID12); + am_converterID_t converterID12; + enterConverterDB("converter12", domainID1, cfFuture2, cfStereo, matrix, coSourceID12, coSinkID12, converterID12); + + am_sinkID_t coSinkID13; + enterSinkDB("coSink13", domainID1, cfFuture2, coSinkID13); + am_sourceID_t coSourceID13; + enterSourceDB("coSource13", domainID1, cfFuture1, coSourceID13); + am_converterID_t converterID13; + enterConverterDB("converter13", domainID1, cfFuture1, cfFuture2, matrix, coSourceID13, coSinkID13, converterID13); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfFuture1, gwSinkID11); + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfFuture1, matrix, gwSourceID21, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + + + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cfAuto, sinkID); + + am::am_Source_s source; + am::am_Sink_s sink; + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); + pRouter.getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = coSinkID21; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, coSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({coSourceID11, gwSinkID11, domainID1, 5}); + compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + + am_Route_s compareRoute2; + compareRoute2.sinkID = coSinkID21; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back({sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO}); + compareRoute2.route.push_back({coSourceID12, coSinkID13, domainID1, 6}); + compareRoute2.route.push_back({coSourceID13, gwSinkID11, domainID1, 5}); + compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])||pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); +} + +TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domain1ID, domain2ID, domain3ID; + enterDomainDB("domain1", domain1ID); + enterDomainDB("domain2", domain2ID); + enterDomainDB("domain3", domain3ID); + + //just make so many cycles as possible + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog = cfStereo; + std::vector cfMono = cfStereo; + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t source1ID; + enterSourceDB("source1", domain1ID, cfStereo, source1ID); + am_sinkID_t gw1SinkID; + enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); + am_sinkID_t gw2SinkID; + enterSinkDB("gw2Sink", domain1ID, cfStereo, gw2SinkID); + am_sourceID_t gw3SourceID; + enterSourceDB("gw3Source", domain1ID, cfAnalog, gw3SourceID); + am_sourceID_t gw4SourceID; + enterSourceDB("gw4Source", domain1ID, cfAnalog, gw4SourceID); + am_sinkID_t gw5SinkID; + enterSinkDB("gw5Sink", domain1ID, cfAnalog, gw5SinkID); + + am_sourceID_t gw1SourceID; + enterSourceDB("gw1Source", domain2ID, cfMono, gw1SourceID); + am_sourceID_t gw2SourceID; + enterSourceDB("gw2Source", domain2ID, cfMono, gw2SourceID); + am_sinkID_t gw3SinkID; + enterSinkDB("gw3Sink", domain2ID, cfMono, gw3SinkID); + am_sinkID_t gw4SinkID; + enterSinkDB("gw4Sink", domain2ID, cfMono, gw4SinkID); + + am_sourceID_t gw5SourceID; + enterSourceDB("gw5Source", domain3ID, cfStereo, gw5SourceID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domain3ID, cfStereo, sink1ID); + + std::vector matrixT; + matrixT.push_back(true); + std::vector matrixF; + matrixF.push_back(false); + + am_gatewayID_t gateway1ID; + enterGatewayDB("gateway1", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); + am_gatewayID_t gateway2ID; + enterGatewayDB("gateway2", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw2SourceID, gw2SinkID, gateway2ID); + am_gatewayID_t gateway3ID; + enterGatewayDB("gateway3", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw3SourceID, gw3SinkID, gateway3ID); + am_gatewayID_t gateway4ID; + enterGatewayDB("gateway4", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw4SourceID, gw4SinkID, gateway4ID); + am_gatewayID_t gateway5ID; + enterGatewayDB("gateway5", domain3ID, domain1ID, cfStereo, cfAnalog, matrixT, gw5SourceID, gw5SinkID, gateway5ID); + + pRouter.load(false); + + CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); + CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); + + ASSERT_TRUE(sourceNode); + ASSERT_TRUE(sinkNode); + + std::vector listRoutes; + std::vector> resultNodesPath; + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink1ID; + compareRoute1.sourceID = source1ID; + +#define DO_ASSERT() \ + {\ + bool didMatch = false; \ + for(auto it = listRoutes.begin(); it!=listRoutes.end(); it++) \ + didMatch|=pCF.compareRoute(compareRoute1,*it); \ + ASSERT_TRUE(didMatch); \ + } + +#ifdef ROUTING_BUILD_CONNECTIONS + getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, true); + ASSERT_EQ(static_cast(9), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() +#else + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); +#endif + + listRoutes.clear(); + resultNodesPath.clear(); + getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, false); + ASSERT_EQ(static_cast(1), listRoutes.size()); + DO_ASSERT() +} + +TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID1, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + am_sinkID_t gwSinkID22; + enterSinkDB("gwSink22", domainID2, cfMono, gwSinkID22); + + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID3, cfAuto, gwSourceID21); + + am_sourceID_t gwSourceID22; + enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22); + am_sourceID_t gwSourceID5; + enterSourceDB("gwSource5", domainID3, cfStereo, gwSourceID5); + am_sinkID_t gwSinkID5; + enterSinkDB("gwSink5", domainID3, cfAnalog, gwSinkID5); + am_sourceID_t gwSourceID3; + enterSourceDB("gwSource3", domainID3, cfAnalog, gwSourceID3); + am_sinkID_t gwSinkID3; + enterSinkDB("gwSink3", domainID3, cfAuto, gwSinkID3); + am_sourceID_t gwSourceID4; + enterSourceDB("gwSource4", domainID3, cfStereo, gwSourceID4); + am_sinkID_t gwSinkID4; + enterSinkDB("gwSink4", domainID3, cfAnalog, gwSinkID4); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); + + std::vector matrix; + matrix.push_back(true); + am_gatewayID_t gatewayID; + enterGatewayDB("gateway1", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); + am_gatewayID_t gatewayID22; + enterGatewayDB("gateway22", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID22, gwSinkID22, gatewayID22); + am_gatewayID_t gatewayID21; + enterGatewayDB("gateway21", domainID3, domainID1, cfAuto, cfStereo, matrix, gwSourceID21, gwSinkID21, gatewayID21); + am_converterID_t converterID1; + enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, gwSourceID3, gwSinkID3, converterID1); + am_converterID_t converterID2; + enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, gwSourceID4, gwSinkID4, converterID2); + am_converterID_t converterID3; + enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, gwSourceID5, gwSinkID5, converterID3); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast(4), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute1.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute1.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute2.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); + compareRoute2.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute2.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute2.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute3; + compareRoute3.sinkID = sinkID; + compareRoute3.sourceID = sourceID; + compareRoute3.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute3.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute3.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute3.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute4; + compareRoute4.sinkID = sinkID; + compareRoute4.sourceID = sourceID; + compareRoute4.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute4.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute4.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute4.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| + pCF.compareRoute(compareRoute1,listRoutes[1])|| + pCF.compareRoute(compareRoute1,listRoutes[2])|| + pCF.compareRoute(compareRoute1,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])|| + pCF.compareRoute(compareRoute2,listRoutes[1])|| + pCF.compareRoute(compareRoute2,listRoutes[2])|| + pCF.compareRoute(compareRoute2,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])|| + pCF.compareRoute(compareRoute3,listRoutes[1])|| + pCF.compareRoute(compareRoute3,listRoutes[2])|| + pCF.compareRoute(compareRoute3,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[0])|| + pCF.compareRoute(compareRoute4,listRoutes[1])|| + pCF.compareRoute(compareRoute4,listRoutes[2])|| + pCF.compareRoute(compareRoute4,listRoutes[3])); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterMapTest"); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h new file mode 100644 index 0000000..65ff97b --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -0,0 +1,108 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MAPTEST_H_ +#define MAPTEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include +#include +#include +#include +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "CAmSocketHandler.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" + + +namespace am +{ + +class CAmRouterMapTest: public ::testing::Test +{ +public: + CAmRouterMapTest(); + ~CAmRouterMapTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmControlSender pControlSender; + CAmDatabaseHandlerMap pDatabaseHandler; + 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(); + + void enterDomainDB(const std::string & domainName, am_domainID_t & domainID); + void enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID); + void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID); + void enterGatewayDB(const std::string & gwName, + const am_domainID_t domainSourceID, + const am_domainID_t domainSinkID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, + const std::vector & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_gatewayID_t & gatewayID); + void enterConverterDB(const std::string & gwName, + const am_domainID_t domainID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, + const std::vector & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_converterID_t & converterID); + void getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); + void getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); + void getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector & resultPath, + std::vector> & resultNodesPath, + const bool includeCycles); +}; + +} + +#endif /* MAPTEST_H_ */ diff --git a/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt new file mode 100644 index 0000000..17689d9 --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRouterMapTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTINGMAP_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterMapTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterMapTest AudioManagerCore) + +INSTALL(TARGETS AmRouterMapTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ new file mode 100644 index 0000000..ec79082 --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRouterMapTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTINGMAP_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterMapTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterMapTest AudioManagerCore) + +INSTALL(TARGETS AmRouterMapTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp new file mode 100644 index 0000000..a64979e --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp @@ -0,0 +1,1967 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRouterTest.h" +#include +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +CAmRouterTest::CAmRouterTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pControlSender(), // + pDatabaseHandler(), + 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)); + source.sourceID=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)); + sink.sinkID=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(static_cast(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(static_cast(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; + + std::vector listConnections; + pDatabaseHandler.getListConnections(listConnections); + ASSERT_EQ(0, listConnections.size()); + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast(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(static_cast(0), listRoutes.size()); + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, with gateway for each direction (possible circular route) +TEST_F(CAmRouterTest,simpleRoute2DomainsCircularGWOnlyFree) +{ + + 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, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID2; + + 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); + + gwSource2.domainID = domainID1; + gwSource2.name = "gwsource2"; + gwSource2.sourceState = SS_ON; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.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(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID2; + + 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); + + gwSink2.domainID = domainID2; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID, 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"; + + gateway2.controlDomainID = domainID1; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID1; + gateway2.domainSinkID = domainID2; + 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(gateway2,gatewayID2)); + + 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(static_cast(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(static_cast(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(static_cast(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(static_cast(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(static_cast(2), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]) || pCF.compareRoute(compareRoute,listRoutes[1]) ); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1]) || pCF.compareRoute(compareRoute1,listRoutes[0]) ); +} + +//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(static_cast(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(static_cast(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(static_cast(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(static_cast(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)); + size_t size(1); + ASSERT_EQ(size, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest"); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h new file mode 100644 index 0000000..4a4e35b --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h @@ -0,0 +1,81 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef DATABASETEST_H_ +#define DATABASETEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include +#include +#include +#include +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "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; + CAmControlSender pControlSender; + CAmDatabaseHandlerMap pDatabaseHandler; + 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/AudioManagerCore/test/AmRouterTest/CMakeLists.txt b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt new file mode 100644 index 0000000..db05911 --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmRouterTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + +file(GLOB ROUTING_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterTest AudioManagerCore) + +INSTALL(TARGETS AmRouterTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ new file mode 100644 index 0000000..32e1206 --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmRouterTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + + +file(GLOB ROUTING_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterTest AudioManagerCore) + +INSTALL(TARGETS AmRouterTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp new file mode 100644 index 0000000..5978b6d --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -0,0 +1,383 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRoutingInterfaceTest.h" +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pDatabaseHandler(), // + 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 = DYNAMIC_ID_BOUNDARY; + + //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 = DYNAMIC_ID_BOUNDARY; + 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_GENIVI_TREBLE; + soundProperty.value = 23; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + 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(1).WillOnce(Return(E_NO_CHANGE)); + 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 = DYNAMIC_ID_BOUNDARY; + 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 = DYNAMIC_ID_BOUNDARY; + 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; + soundProperty.value=5; + soundProperty.type=SP_GENIVI_MID; + std::vector listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + 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,_)).WillOnce(Return(E_OK)); + soundProperty.value=10; + 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,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_CustomRampType_t 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 = DYNAMIC_ID_BOUNDARY; + 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,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_CustomRampType_t 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 = DYNAMIC_ID_BOUNDARY; + 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 = DYNAMIC_ID_BOUNDARY; + 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 = DYNAMIC_ID_BOUNDARY; + 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()); +} + + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest"); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h new file mode 100644 index 0000000..75a7511 --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h @@ -0,0 +1,71 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include +#include +#include +#include +#include "CAmDatabaseHandlerMap.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 "CAmSocketHandler.h" + +namespace am +{ + +class CAmRoutingInterfaceTest: public ::testing::Test +{ +public: + CAmRoutingInterfaceTest(); + ~CAmRoutingInterfaceTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandlerMap 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/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..dc5115d --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRoutingInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTING_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRoutingInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmRoutingInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ new file mode 100644 index 0000000..e8fbb29 --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRoutingInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + +file(GLOB ROUTING_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRoutingInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmRoutingInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp new file mode 100644 index 0000000..d3f7a11 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp @@ -0,0 +1,209 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include +#include +#include +#include + +#include "CAmTelnetServerTest.h" +#include "CAmCommandReceiver.h" +#include "CAmRoutingReceiver.h" +#include "CAmControlReceiver.h" +#include "audiomanagerconfig.h" + + +using namespace testing; +using namespace am; +using namespace std; + + +static std::string controllerPlugin = std::string(CONTROLLER_PLUGIN_DIR); +static unsigned short servPort = 6060; +static int staticSocket = -1; +static CAmSocketHandler* mpSocketHandler = NULL; + +void* startSocketHandler(void* data) +{ + CAmEnvironment* Env = static_cast(data); + Env->setSocketHandler(&Env->mSocketHandler); + Env->mSocketHandler.start_listenting(); + Env->setSocketHandler(NULL); + return (NULL); +} + +CAmEnvironment::CAmEnvironment() +: mlistRoutingPluginDirs() +, mlistCommandPluginDirs() +, mSocketHandler() +, mDatabasehandler() +, mRoutingSender(mlistRoutingPluginDirs) +, mCommandSender(mlistRoutingPluginDirs) +, 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() +{ + pthread_cancel(mSocketHandlerThread); +} + +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() +{ + +} + +void CAmTelnetServerTest::sendCmd(std::string & command ) +{ + ssize_t sizesent = send(staticSocket, command.c_str(), command.size(), 0); + ASSERT_EQ(static_cast(sizesent),command.size()); + + char buffer[1000]; + memset(buffer,0,sizeof(buffer)); + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); +} + +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 cmd("help"); + sendCmd(cmd); +} + +TEST_F(CAmTelnetServerTest,sendDumpCmdTelnetServer) +{ + std::string cmd1("info"); + std::string cmd3("dump"); + sendCmd(cmd1); + sendCmd(cmd3); +} + +TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) +{ + std::string cmd("exit"); + mpSocketHandler->stop_listening(); + sendCmd(cmd); + 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/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h new file mode 100644 index 0000000..02f98a3 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h @@ -0,0 +1,107 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CAMTELNETSERVERTEST_H_ +#define CAMTELNETSERVERTEST_H_ + +#include "gtest/gtest.h" +#include "CAmTelnetServer.h" +#include "CAmRoutingSender.h" +#include "CAmCommandSender.h" +#include "CAmControlSender.h" +#include "CAmRouter.h" +#include "audiomanagerconfig.h" +#include "CAmDatabaseHandlerMap.h" + + + + + +namespace am +{ + +class CAmSocketHandler; +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; + + CAmSocketHandler mSocketHandler; + CAmDatabaseHandlerMap 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() ; + void sendCmd(std::string & command ); + //int mSocket; +}; + +} + + + + +#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt new file mode 100644 index 0000000..8dcb0a3 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +PROJECT(AmTelnetServerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB TELNET_SRCS_CXX + "*.cpp" +) + +ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmTelnetServerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) +add_test(AmTelnetServerTest AmTelnetServerTest) + +ADD_DEPENDENCIES(AmTelnetServerTest AudioManagerCore) + +INSTALL(TARGETS AmTelnetServerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + + diff --git a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ new file mode 100644 index 0000000..51e92b8 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ @@ -0,0 +1,46 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +PROJECT(AmTelnetServerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + +file(GLOB TELNET_SRCS_CXX + "*.cpp" +) + +ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmTelnetServerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmTelnetServerTest AudioManagerCore) + +INSTALL(TARGETS AmTelnetServerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + + diff --git a/AudioManagerCore/test/CAmCommonFunctions.cpp b/AudioManagerCore/test/CAmCommonFunctions.cpp new file mode 100644 index 0000000..22331d4 --- /dev/null +++ b/AudioManagerCore/test/CAmCommonFunctions.cpp @@ -0,0 +1,383 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#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 controlSender->mController == newController; +} + +//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 equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b) +{ + return (a.parameter == b.parameter && a.status == b.status && a.type == b.type); +} + +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::compareConverter(std::vector::iterator listIterator, const am_Converter_s& gatewayData) +{ + return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->domainID == gatewayData.domainID) && 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::compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData) +{ + return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.domainID == gatewayData.domainID) && 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_GENIVI_BASS; + soundProperty.value = 23; + soundPropertyList.push_back(soundProperty); + soundProperty.type = SP_GENIVI_MID; + soundProperty.value = 2; + soundPropertyList.push_back(soundProperty); + return soundPropertyList; +} + +std::vector CAmCommonFunctions::getStandardMainSoundPropertyList() +{ + std::vector mainSoundPropertyList; + am_MainSoundProperty_s mainSoundProperty; + mainSoundProperty.type = MSP_GENIVI_BASS; + 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.listNotificationConfigurations = getStandardNotificationConfigurationList(); + sink.listMainNotificationConfigurations = getStandardNotificationConfigurationList(); + 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.listMainNotificationConfigurations=getStandardNotificationConfigurationList(); + source.listNotificationConfigurations=getStandardNotificationConfigurationList(); + 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::createConverter(am_Converter_s & converter) const +{ + converter.name = "AnyConverter"; + converter.sinkID = 1; + converter.sourceID = 2; + converter.domainID = 1; + converter.convertionMatrix = getStandardConvertionMatrix(); + converter.listSourceFormats = getStandardConnectionFormatList(); + converter.listSinkFormats = getStandardConnectionFormatList(); + converter.converterID = 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; +} + +std::vector am::CAmCommonFunctions::getStandardNotificationConfigurationList() +{ + std::vector listNotificationConfigurations; + am_NotificationConfiguration_s tempNotificationConfiguration; + tempNotificationConfiguration.type=NT_TEST_1; + tempNotificationConfiguration.parameter=12; + tempNotificationConfiguration.status=NS_PERIODIC; + listNotificationConfigurations.push_back(tempNotificationConfiguration); + + tempNotificationConfiguration.type=NT_TEST_2; + tempNotificationConfiguration.parameter=16; + tempNotificationConfiguration.status=NS_CHANGE; + listNotificationConfigurations.push_back(tempNotificationConfiguration); + + return (listNotificationConfigurations); +} + +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/AudioManagerCore/test/CAmCommonFunctions.h b/AudioManagerCore/test/CAmCommonFunctions.h new file mode 100644 index 0000000..9dbdc8f --- /dev/null +++ b/AudioManagerCore/test/CAmCommonFunctions.h @@ -0,0 +1,96 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef COMMONHEADERS_H_ +#define COMMONHEADERS_H_ + +#include "audiomanagertypes.h" + +namespace am +{ + +static const am_CustomNotificationType_t NT_TEST_1 = 1; +static const am_CustomNotificationType_t NT_TEST_2 = 2; + + +class CAmCommonFunctions +{ +public: + + static std::vector getStandardConnectionFormatList(); + static std::vector getStandardSoundPropertyList(); + static std::vector getStandardMainSoundPropertyList(); + static std::vector getStandardConvertionMatrix(); + static std::vector getStandardNotificationConfigurationList(); + 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 compareConverter(std::vector::iterator listIterator, const am_Converter_s& gatewayData); + bool compareConverter1(const am_Converter_s gateway1, const am_Converter_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 createConverter(am_Converter_s & converter) 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_CustomAvailabilityReason_t & a, const am_CustomAvailabilityReason_t & 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/AudioManagerCore/test/CMakeLists.txt b/AudioManagerCore/test/CMakeLists.txt new file mode 100644 index 0000000..9dd9007 --- /dev/null +++ b/AudioManagerCore/test/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + + +set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) + +#make aunt google stop complaining +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager -Wno-unused-local-typedefs -lz -ldl") + +add_subdirectory (AmControlInterfaceTest) +add_subdirectory (AmMapHandlerTest) +add_subdirectory (AmRouterTest) +add_subdirectory (AmRouterMapTest) +add_subdirectory (AmRoutingInterfaceTest) + +IF(WITH_TELNET) + add_subdirectory (AmTelnetServerTest) +ENDIF(WITH_TELNET) + diff --git a/AudioManagerCore/test/IAmCommandBackdoor.h b/AudioManagerCore/test/IAmCommandBackdoor.h new file mode 100644 index 0000000..b7d2b20 --- /dev/null +++ b/AudioManagerCore/test/IAmCommandBackdoor.h @@ -0,0 +1,47 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#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/AudioManagerCore/test/IAmControlBackdoor.h b/AudioManagerCore/test/IAmControlBackdoor.h new file mode 100644 index 0000000..b5ba3ef --- /dev/null +++ b/AudioManagerCore/test/IAmControlBackdoor.h @@ -0,0 +1,44 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CONTROLINTERFACEBACKDOOR_H_ +#define CONTROLINTERFACEBACKDOOR_H_ + +#include "IAmControl.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/AudioManagerCore/test/IAmRoutingBackdoor.h b/AudioManagerCore/test/IAmRoutingBackdoor.h new file mode 100644 index 0000000..cbdb070 --- /dev/null +++ b/AudioManagerCore/test/IAmRoutingBackdoor.h @@ -0,0 +1,46 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#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/AudioManagerCore/test/MockIAmCommandSend.h b/AudioManagerCore/test/MockIAmCommandSend.h new file mode 100644 index 0000000..36bc1cb --- /dev/null +++ b/AudioManagerCore/test/MockIAmCommandSend.h @@ -0,0 +1,94 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKCOMMANDINTERFACE_H_ +#define MOCKCOMMANDINTERFACE_H_ + +#include "IAmCommand.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmCommandSend : public IAmCommandSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + 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_METHOD3(cbSinkUpdated, + void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties)); + MOCK_METHOD3(cbSourceUpdated, + void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties)); + MOCK_METHOD2(cbSinkNotification, + void(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification)); + MOCK_METHOD2(cbSourceNotification, + void(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification)); + MOCK_METHOD2(cbMainSinkNotificationConfigurationChanged, + void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); + MOCK_METHOD2(cbMainSourceNotificationConfigurationChanged, + void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); + + + +}; + +} // namespace am +#endif /* MOCKCOMMANDINTERFACE_H_ */ diff --git a/AudioManagerCore/test/MockIAmControlSend.h b/AudioManagerCore/test/MockIAmControlSend.h new file mode 100644 index 0000000..e628068 --- /dev/null +++ b/AudioManagerCore/test/MockIAmControlSend.h @@ -0,0 +1,160 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKCONTROLINTERFACE_H_ +#define MOCKCONTROLINTERFACE_H_ + +#include "IAmControl.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmControlSend : public IAmControlSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(startupController, + am_Error_e(IAmControlReceive* controlreceiveinterface)); + MOCK_METHOD0(setControllerReady, + void()); + MOCK_METHOD1(setControllerRundown, + void(const int16_t signal)); + 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(hookSystemRegisterConverter, + am_Error_e(const am_Converter_s& converterData, am_converterID_t& converterID)); + MOCK_METHOD2(hookSystemRegisterGateway, + am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); + MOCK_METHOD1(hookSystemDeregisterConverter, + am_Error_e(const am_converterID_t converterID)); + 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_METHOD1(confirmCommandReady, + void(const am_Error_e error)); + MOCK_METHOD1(confirmRoutingReady, + void(const am_Error_e error)); + MOCK_METHOD1(confirmCommandRundown, + void(const am_Error_e error)); + MOCK_METHOD1(confirmRoutingRundown, + void(const am_Error_e error)); + MOCK_METHOD5(hookSystemUpdateSink, + am_Error_e(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties)); + MOCK_METHOD5(hookSystemUpdateSource, + am_Error_e(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties)); + MOCK_METHOD4(hookSystemUpdateConverter, + am_Error_e(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix)); + MOCK_METHOD4(hookSystemUpdateGateway, + am_Error_e(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix)); + MOCK_METHOD3(cbAckSetVolumes, + void(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkNotificationConfiguration, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceNotificationConfiguration, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(hookSinkNotificationDataChanged, + void(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload)); + MOCK_METHOD2(hookSourceNotificationDataChanged, + void(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload)); + MOCK_METHOD2(hookUserSetMainSinkNotificationConfiguration, + am_Error_e(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(hookUserSetMainSourceNotificationConfiguration, + am_Error_e(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(hookSystemSingleTimingInformationChanged, + void(const am_connectionID_t connectionID, const am_timeSync_t time)); +}; + + +} // namespace am +#endif /* MOCKCONTROLINTERFACE_H_ */ diff --git a/AudioManagerCore/test/MockIAmRoutingSend.h b/AudioManagerCore/test/MockIAmRoutingSend.h new file mode 100644 index 0000000..748e64e --- /dev/null +++ b/AudioManagerCore/test/MockIAmRoutingSend.h @@ -0,0 +1,83 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKROUTINGINTERFACE_H_ +#define MOCKROUTINGINTERFACE_H_ + +#include "IAmRouting.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmRoutingSend : public IAmRoutingSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + 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_CustomAvailabilityReason_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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_METHOD2(asyncSetVolumes, + am_Error_e(const am_Handle_s handle, const std::vector& listVolumes)); + MOCK_METHOD3(asyncSetSinkNotificationConfiguration, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD3(asyncSetSourceNotificationConfiguration, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(resyncConnectionState, + am_Error_e(const am_domainID_t domainID, std::vector& listOfExistingConnections)); + + +}; + +} // namespace am + + +#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt index d044ed8..acc5c2b 100644 --- a/AudioManagerDaemon/CMakeLists.txt +++ b/AudioManagerDaemon/CMakeLists.txt @@ -15,89 +15,12 @@ # For further information see http://www.genivi.org/. # -cmake_minimum_required(VERSION 2.8.8) - -project (AudioManagerDeamon) - -set(DOC_OUTPUT_PATH ${DOC_OUTPUT_PATH}/AudioManager) - -set(AM_MAP_CAPACITY 10 - CACHE INTEGER "Number of preallocations for datastorage") - -set(AM_MAX_CONNECTIONS 0x1000 - CACHE INTEGER "Number of max connections before rollover") - -set(AM_MAX_CONNECTIONS SHRT_MAX - CACHE INTEGER "Number of max Mainconnections before rollover") - -set(INCLUDE_FOLDER "include") - -if (WITH_DATABASE_STORAGE) - pkg_check_modules(SQLITE REQUIRED sqlite3) -endif (WITH_DATABASE_STORAGE) - -if(WITH_DBUS_WRAPPER) - pkg_check_modules (DBUS "dbus-1 >= 1.4") -endif(WITH_DBUS_WRAPPER) - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -if(WITH_CAPI_WRAPPER) - find_package(CommonAPI 3.1.3 REQUIRED) - string(REPLACE "." "" COMMONAPI_VERSION_NUMBER ${CommonAPI_VERSION}) - SET(COMMONAPI_VERSION_NUMBER ${COMMONAPI_VERSION_NUMBER} CACHE INTERNAL "hide this!" FORCE) - SET(CommonAPI_VERSION ${CommonAPI_VERSION} PARENT_SCOPE) -endif(WITH_CAPI_WRAPPER) +cmake_minimum_required(VERSION 3.0) +project (AudioManagerDeamon LANGUAGES CXX VERSION ${DAEMONVERSION}) set(AUDIOMAN_SRCS_CXX - src/main.cpp - src/CAmCommandReceiver.cpp - src/CAmCommandSender.cpp - src/CAmControlReceiver.cpp - src/CAmControlSender.cpp - src/CAmDatabaseObserver.cpp - src/CAmRoutingReceiver.cpp - src/CAmRoutingSender.cpp - src/CAmRouter.cpp - src/CAmLog.cpp -) - -if(WITH_TELNET) - set (AUDIOMAN_SRCS_CXX - ${AUDIOMAN_SRCS_CXX} - src/CAmTelnetServer.cpp - src/CAmTelnetMenuHelper.cpp) -endif(WITH_TELNET) - -if(WITH_DBUS_WRAPPER) - set (AUDIOMAN_SRCS_CXX - ${AUDIOMAN_SRCS_CXX} - "${AUDIOMANAGER_UTILITIES_SRC}/CAmDbusWrapper.cpp") - set (AM_LINK_LIBS ${AM_LINK_LIBS} ${DBUS_LIBRARIES}) -endif(WITH_DBUS_WRAPPER) - -if(WITH_CAPI_WRAPPER) - set(LINK_LIBRARIES -Wl,--as-needed CommonAPI) - set (AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} "${AUDIOMANAGER_UTILITIES_SRC}/CAmCommonAPIWrapper.cpp") - set (AM_LINK_LIBS ${AM_LINK_LIBS} ${LINK_LIBRARIES}) -endif(WITH_CAPI_WRAPPER) - -if(WITH_DATABASE_STORAGE) - set (AUDIOMAN_SRCS_CXX - ${AUDIOMAN_SRCS_CXX} - src/CAmDatabaseHandlerSQLite.cpp) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${SQLITE_LIBRARIES}) -else(WITH_DATABASE_STORAGE) - set (AUDIOMAN_SRCS_CXX - ${AUDIOMAN_SRCS_CXX} - src/CAmDatabaseHandlerMap.cpp) -endif(WITH_DATABASE_STORAGE) + src/main.cpp) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} @@ -105,34 +28,16 @@ INCLUDE_DIRECTORIES( ${AUDIO_INCLUDE_FOLDER} ${AUDIOMANAGER_INCLUDE_FOLDER} ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${AUDIOMANAGER_CORE_INCLUDE} ${INCLUDE_FOLDER} ${TCLAP_INCLUDE_DIR} ) -if(WITH_CAPI_WRAPPER) - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} - ${COMMONAPI_INCLUDE_DIRS} - ) -endif(WITH_CAPI_WRAPPER) - -if(WITH_DLT) - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -if(WITH_DBUS_WRAPPER) - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} - ${DBUS_INCLUDE_DIRS}) -endif(WITH_DBUS_WRAPPER) - ADD_EXECUTABLE(AudioManager ${AUDIOMAN_SRCS_CXX}) -TARGET_LINK_LIBRARIES(AudioManager ${AM_LINK_LIBS}) +TARGET_LINK_LIBRARIES(AudioManager AudioManagerCore ${AUDIO_MANAGER_CORE_LIBS}) -ADD_DEPENDENCIES(AudioManager AudioManagerUtilities) +ADD_DEPENDENCIES(AudioManager AudioManagerCore) INSTALL(TARGETS AudioManager RUNTIME DESTINATION bin @@ -143,9 +48,4 @@ INSTALL(DIRECTORY "${AUDIO_INCLUDE_FOLDER}/" DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${LIB_INSTALL_SUFFIX} COMPONENT dev) -if(WITH_TESTS) - add_subdirectory (test) -endif(WITH_TESTS) - - diff --git a/AudioManagerDaemon/docx/01_mainpage.dox b/AudioManagerDaemon/docx/01_mainpage.dox deleted file mode 100644 index ad0848b..0000000 --- a/AudioManagerDaemon/docx/01_mainpage.dox +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\mainpage - -\image html genivilogo.png - -\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. - -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/02_license.dox b/AudioManagerDaemon/docx/02_license.dox deleted file mode 100644 index d7fc220..0000000 --- a/AudioManagerDaemon/docx/02_license.dox +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page lic License -\section proj Open Source Projects in the source tree -The AudioManger comes with some open source software distributed in the source tree: -- Google Mock (in \googleMock), licensed under MIT license -- Tclap ( in \tclap-1.2.1), licensed under MIT license -\section split License Split -The licenses of this project are split into two parts:\n -1. the AudioManagerDaemon, licensed under MPL 2.0\n -2. all other parts that serve as example code that can be taken to build up an own project with it these parts are licensed -\section mpl Mozilla Public License, v. 2.0 -http://mozilla.org/MPL/2.0/ -\section mit MIT 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. -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/02_x_dependecies.dox b/AudioManagerDaemon/docx/02_x_dependecies.dox deleted file mode 100644 index ff5c346..0000000 --- a/AudioManagerDaemon/docx/02_x_dependecies.dox +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - - /*! -\page dep Dependencies -\section deps Dependency Graph -\image html dependencies.png -\section deptest Depedency Graph for Tests -\image html dependencies_test.png -\section depgen Generated Dependency Graph -\image html dependency_created.png -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/02_y_versioning.dox b/AudioManagerDaemon/docx/02_y_versioning.dox deleted file mode 100644 index 864a04e..0000000 --- a/AudioManagerDaemon/docx/02_y_versioning.dox +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - - /*! -\page ver Versioning -\section new_ver New versioning scheme -Due to the unclearness in the versioning scheme, the versioning scheme changed with release 7.0. -Beginning with the 7.0 version, the versioning changed to the semantic versioning described here: http://semver.org/. -For every version that released for GENIVI (independent from the compliance), a stable branch will be created which will start with a minor number increase. On the masterbranch, no minor number increases are foreseen. -\image html versioning_new.png -\section ver_graph The versioning scheme until 7.0 -The versioning scheme was decided in the February face2face 2012. -\image html versioning.png -For the daemon the third number (for example 1.0.X) describes the patch version. The versions are automatically created by git during the build process. -The versioning scheme is used for the AudioManager daemon itself and for each of it's interfaces. The versioning of the Interfaces in EA is defined via the tag "version" and the name of the interfaceversion versionName, for example "CommandReceiveVersion". This information is generated into the interface header files and is used then by cmake to set the interface versions. -Whenever changes are done, the minor version of the interface needs to be incremented. -*/ diff --git a/AudioManagerDaemon/docx/03_architecture_overview.dox b/AudioManagerDaemon/docx/03_architecture_overview.dox deleted file mode 100644 index c38bb60..0000000 --- a/AudioManagerDaemon/docx/03_architecture_overview.dox +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page architecturepage 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 - -\image html AudioDomains.gif -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. -am::am_Domain_s describe the attribiutes of a domain. - -\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 Gateway - -\image html Gateway.gif - -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 -In principle, gateways have the ability to convert the connectionFormat of an audiostream, for example the sink could receive audio -in a digital form and output it as analog (sound card). In order to express the conversion capabilities of a gateway, a matrix of -all source/sink connectionFormats is given (details below). The sources and sinks of a gateway are registered like ordinary sources -and sinks where the domains have the responsibility to register "their" sinks and sources.\n -For every gateway, a controlDomain is defined, this is the domain that registered the gateway. At the time of registering, the ID of -the "other end" of the gateway might be unknown. To handle this situation, a domain can "peek" Domains, Sources and Sinks. When -something is peeked, it means that an ID is reserved for a unique name without registering it.\n -If a gateway is deregistered, the source or sink of the controlling domain is deregistered as well - not the one in the "other" domain. - -\section converter Converter - -Converters are very similar to gateways - the only difference is that they work inside a domain. The usage of gateways is analog to -gateways. - -*/ diff --git a/AudioManagerDaemon/docx/03_x_uml_model.dox b/AudioManagerDaemon/docx/03_x_uml_model.dox deleted file mode 100644 index 802d181..0000000 --- a/AudioManagerDaemon/docx/03_x_uml_model.dox +++ /dev/null @@ -1,49 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page uml UML Model auf the AudioManager -\section svn Audio Manager Branch -The SVN link to the AudioManager branch can be found here: https://svn.genivi.org/uml-model/genivi/branch/eg-mg-audiomanager -The last valid version that is compliant can be found on the trunk.\n -For more information about the EA model, please see here: https://collab.genivi.org/wiki/display/genivi/Audio+Management+UML+Model -After the EA Model is updated via "Get All latest", the relevant parts for Audio Management are:\n -- Requirements on System Level -\code -GENIVI Model -> Requirements View -> Media and Graphics -> Audio Management -\endcode -- Use Cases on System Level -\code -GENIVI Model -> Use Case View -> Audio Management -\endcode -- Requirements on Component Level -\code -GENIVI Model -> Logical View -> SW platform Requirements -> Multimedia -> AudioManagement -\endcode -- Use Cases on Component Level -\code -GENIVI Model -> Logical View -> Use Case Realizations -> AudioManagement -\endcode -- Component Diagram -\code -GENIVI Model -> Logical View -> SW Platform Components -> Audio Management -\endcode -- Implementation Class & Component diagrams: -\code -GENIVI Implementation -> Implementation View -> Audio Management -\endcode -*/ diff --git a/AudioManagerDaemon/docx/04_components.dox b/AudioManagerDaemon/docx/04_components.dox deleted file mode 100644 index 7c8f9b4..0000000 --- a/AudioManagerDaemon/docx/04_components.dox +++ /dev/null @@ -1,99 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - - /*! - \page audiomanagercomponentspage AudioManager Components - \image html AudioManagement.png - - 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 - - - \section audiomanagercomponents AudioManagerDaemon - - 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).\n - The AudioManagerDaemon is subject to this documentation. - \subsection daemonover Daemon Overview - Here is an class overview of the AudioManagerDaemon: - \image html daemon_insight.png - - \section commander AudioManagerCommandPlugin - - This describes the interface towards the Commanding 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. - This component is designed to be a dynamic linked library that will be loaded on the startup of the AudioManager. There can be more than one - CommandPlugin at a time. - Since the implementation of this component is project specific, only examples are included.\n - An example Dbus Implementation can be found in the folder PluginCommandInterfaceDbus. - - \subsection commandIface Interfaces - All commands that must be fulfilled by an AudioManagerCommandPlugin are described in am::IAmCommandSend.\n - All commands that are presented to AudioManagerCommandPlugin by the AudioManagerDaemon are described in am::IAmCommandReceive.\n - - \section controller AudioManagerController - The controller is the intelligent "heart" of the AudioManager and it is project specific. In principle, the controller gets commands from the command - interface or events from outside and reacts to them. For this purpose, some basic commands are in the "toolbox" of the Controller that he can use - to interact with the rest of the system.\n - Among this there are commands to read/write the database and to perform actions on the Audiodomains like connect or disconnect. There must be only one - Controller in the system at a time, like the AudioManagerCommandPlugins, the Controller is loaded at startup by the daemon\n - A simple example Implementation can be found in the folder PluginControlInterface. - - \subsection controlIface Interfaces - All commands that must be fulfilled by an AudioManagerController are described in am::IAmControlSend.\n - All commands that are presented to AudioManagerController by the AudioManagerDaemon are described in am::IAmControlReceive.\n - - \section router Routing AudioManagerRoutingPlugin - - The AudioManagerRoutingPlugins are used to abstract the actual Hard- and Software that does the routing. There can be more than one plugins at a - time, they are loaded at startup time like the commandplugins. \n - 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 is capable of addressing more than one adapter one each plug-in. The AudioManagerController does not have to - know anything about the real system plugins - he sends his commands to sources and sinks. The daemon does the dispatching of these commands. - The interface is mainly asynchronous.\ - Sample plugins can be found in the directory, for example PluginRoutingInterfaceAsync.\n - - \subsection routingIface Interfaces - All commands that must be fulfilled by an AudioManagerRoutingPlugin are described in am::IAmRoutingSend.\n - All commands that are presented to AudioManagerRoutingPlugins by the AudioManagerDaemon are described in am::IAmRoutingReceive.\n - - \subsection subrouter Bus topology - The AudioManagerDaemon expects a bus behind each of the plugins. On one of these buses there can be several domains. In order to - reflect this, a domain has always a bus(plugin) and a node that it belongs to. So if a message needs to be transmitted to a domain, - it will always be sent to a node on a bus. - Here is a diagram showing the topology from the view of the AudioManagerDaemon: - \image html bus_topology.png - \subsection busname Busname - Since a plugin represents a bus for the AudioManagerDaemon, each plugin it has its unique name, the busname that is returned by - am::IAmRoutingSend::returnBusName. The AudioManagerDaemon used this information to link a plugin with a domain. All other elements like - sinks, sources etc are linked to domains. This is how the hierarchy looks like that is used: - \image html routing_hierarchy.png - - \subsection CAPIplugins CommonAPI plugins - As "sample code" with MIT license, PluginCommandInterfaceCAPI and PluginRoutingInterfaceCAPI are provided with the source code. The FRANCA - fidls have been generated out of the Enterprise architect model, so they might be used to draw project specific behavior in sequences. - The sources in src-gen have been generated out of the provided fidl files. - - \image html PluginCommandInterfaceCAPI.png - - \image html PluginRoutingInterfaceCAPI.png - - There is no fixed domain associated with this plugin. So you have to implement the interface org::genivi::am::RoutingControlStub and report - busname and path to the routingplugin on the interface org::genivi::am::RoutingControlObserverStub like this: - - \image html Register_Domain.png - -*/ diff --git a/AudioManagerDaemon/docx/04_d_commonAPI.dox b/AudioManagerDaemon/docx/04_d_commonAPI.dox deleted file mode 100644 index 7e837dd..0000000 --- a/AudioManagerDaemon/docx/04_d_commonAPI.dox +++ /dev/null @@ -1,30 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - - /*! - \page comminAPI AudioManager and CommonAPI -The audiomanager supports CommonAPI in very comfortable way. It will register CommonAPI in the audiomanager mainloop (am::CAmSocketHandler) and make -threadsafe calls to the stubs registered via the factory provided by the wrapper. - If enabled (by default) via cmake, the am::CAmCommonAPIWrapper is created. It is instantiated as singleton -and every Plugin can use it. -First, you have to create the interfaces out of the FIDL data like usual. -Then, you can access the singletons via am::CAmCommonAPIWrapper::factory and am::CAmCommonAPIWrapper::runtime. - -More information about CommonAPI can be found here: -http://projects.genivi.org/commonapi/ - -*/ diff --git a/AudioManagerDaemon/docx/04_x_elements.dox b/AudioManagerDaemon/docx/04_x_elements.dox deleted file mode 100644 index 7990d37..0000000 --- a/AudioManagerDaemon/docx/04_x_elements.dox +++ /dev/null @@ -1,63 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page elementspage Elements of the AudioManagement - - \section cDiag Overview Class Diagram - This class diagram shows a logical overview of the relevant elements in the AudioManager with their relations. - \image html ClassDiagramm.png - - The audiomanagement in principle consists of the following elements: - - \section source Sources - This is where audio comes from, for examples tuner, mediaplayer. But sources can also be part of a building block that processes audio, examples - are here crossfaders or gateways. Several Sinks can be connected to one source.\n - \subsection sourceattributes Attributes - - am::am_SourceType_s describes the attributes that are accessible from the AudioManagerCommandPlugins.\n - - am::am_Source_s describes the general attributes.\n - - \section sinks Sinks - This is where audio flows to, for examples amplifier, headphones. But sources can also be part of a building block that processes audio, - examples are here crossfaders or gateways. Several Sources can be connected to one sink.\n - \subsection sinkattributes Attributes - - am::am_SinkType_s describes the attribiutes that are accessible form the AudioManagerCommandPlugins.\n - - am::am_Sink_s describes the general attributes.\n - - \section gw Gateways - Gateways are described here: \ref gateway - A specialitry of a gateways is the convertionmatrix. It indicates which sinksoundformats can be transferred in which sourcesoundformats. A convertion - matrix looks like this: - \image html GatewayMatrix.png - \subsection gwattributes Attributes - - am::am_Gateway_s describe the attribiutes of a gateway\n - - \section crossfaders Crossfaders - Cross-faders are special elements that can perform cross-fading between two sources connected to the sinks of the crossfader. The audio of either source - or both (mixed, during the fade) is put out at the source of the fader. Cross-fading within a source (for example from one song to another) is out of - scope audio management and must be performed in the source.\n - A crossfader has two sinks and one source, where one sink is the "hot" one. It is in the duty of the AudioManagerController to connect the correct - sources to the sinks in order to perform a cross-fade. When fading is started, the hotSink changes from either HS_SINKA or HS_SINKB to HS_INTERMEDIATE, - when the fading is finished, it changes to HS_SINKA or HS_SINKB (the sink that was "cold" before).Fading itself is done in the RoutingAdapters, the - implementation has to ensure the smooth and synchronous change of volumes. With different rampTypes, different kinds of cross-fade ramps can be supported. - The actual status of the "hot" sink is reported by the routingAdapter. Care has to be taken that the correct "hot" end of the crossfader is given - at registration time.\n - \subsection cfattributes Attributes - - am::am_Crossfader_s describes the attribiutes of a Crossfader - - -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox b/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox deleted file mode 100644 index fd0f1e3..0000000 --- a/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox +++ /dev/null @@ -1,92 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page sourcesink The relation of sources & sinks with the AudioManager - -\section claDi Class diagramm of the relation between sources, sinks and the AudioManager -In general, the relationship is defined as well as the interfaces that are used to communicate the informations back and forth. But since the -exchange of these informations is abstracted by the RoutingPlugins, the architecture cannot define explicit mechanisms here.\n -A lot of attributes that are part of sources and sinks belong logical to them and might be implemented by the RoutingPlugin. The relation between -sources, sinks and the AudioManagerDaemon is shown in this \ref cDiag . - -\section boil The REAL interaction -A lot of information is related to sources and sinks as can be seen here: \ref cDiag . But not all informations are actually communicated to the -sources and sinks since the routing adaptor will take care of handling some of these informations.\n -Here are some informations that is believed to be actually communicated to the sources and sinks: - - \section conFormats Connection Formats - The am::am_CustomAvailabilityReason_t formats for a connection are chosen when the connection is build up. So if there are more than one possbilities - that can be used for a connection (am::am_Sink_s::listConnectionFormats and am::am_Source_s::listConnectionFormats) the correct one is chosen - upon a connect. If this is relevant to the sources and sinks, the routingAdaptor must communicate to the sources and sinks accordingly. - \image html SettingConnectionFormats.png - - - \section sstates Source States - This diagrams shows the sequence that is used to set the sources states am::am_SourceState_e. Since the source states are set by the - AudioManagerController, the exact behavior is product specific. - \image html SourceStates.png - - \section avail Availability - This diagram shows the sequence that is used to communicate the availability am::am_Availability_s. from the sources. Please note that the availability reasons - am::am_CustomAvailabilityReason_t are product specific. - \image html AvailabilityofSources.png - Here is the same for the sinks: - \image html AvailabilityofSinks.png - - \section vol Volumes - Volumes am::am_volume_t are set to the sinks, mainly, but depending on the used audio routing system it might be that they can be set on the source level as well. - If this is not the case, proper measures must be taken to do this. - Changes of a source: - \image html VolumeChangesofSources.png - Changes of a sink: - \image html VolumeChangesofSinks.png - - \section SoundProperties - The am::am_SoundProperty_s are set to the sources and sinks. More information about SoundProperties can be found here: \ref prop. - Changes of a sink: - \image html SoundPropertyChangeofSink.png - Changes of a source: - \image html SoundPropertyChangeofSource.png - - \section in Interrupt States - The am::am_InterruptState_e are reported by low level interrupts from the sources to the AudioManagement. More details here: \ref interrupts . - \image html InterruptStatusChange.png - - - - - - - - - - - - - - - - - - - - - - - -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/05_unique.dox b/AudioManagerDaemon/docx/05_unique.dox deleted file mode 100644 index 5bf021a..0000000 --- a/AudioManagerDaemon/docx/05_unique.dox +++ /dev/null @@ -1,36 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ -/*! - \page uniquepage About unique IDs : Static vs Dynamic IDs - - \section why Why having two different kinds of ids? - The complexity of up-to-date IVI-systems demand to support sources and sinks dynamically added and removed in order to support the variety of CE products, - but parts of the system are never going to change - to start a dynamic registration here is a waste of system capacity.\n - \section setup The setup - The AudioManagement is capable of handling static, dynamic or mixed setups. In case of a dynamic setup, all elements of the system like domains, sinks, - sources, gateways etc are registered at system start-up. In a static setup, the IDs of the elements are known and fixed - no further registration is needed. - The start-up for static elements works as follows:\n - when a domain known as static (this is knowledge of the AudioManagerController, recognized by the unique name of the domain) registers, the - AudioManagerController enters all elements of this domain in the database. Still, this domain can register additional elements during runtime. - In case of static setups, the RoutingAdapter needs to ensure that all static elements are ready to be used when the domain registers.\n - In order to ensure the uniqueness of IDs, there exist two separate ID areas (for each of sources, sinks, gateways and crossfaders):\n\n - \image html unique.svg - In case of dynamic added elements, the audiomanagerdaemon ensures the uniqueness of the ID's, in case of the static setup, the project has to ensure the - uniqueness by assigning the IDs wisely. The knowledge of the static IDs need to be in the AudioManagerController, the RoutingAdapters and in the HMI - (optional because IDs will be reported anyway).\n - Domains cannot be static because registering them is the trigger for the AudioManagerController to enter the static values into the database. -*/ diff --git a/AudioManagerDaemon/docx/06_classification.dox b/AudioManagerDaemon/docx/06_classification.dox deleted file mode 100644 index 0fb72cd..0000000 --- a/AudioManagerDaemon/docx/06_classification.dox +++ /dev/null @@ -1,32 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ -/*! - \page classficationpage Classification of Sinks and Sources - \section classification Classification - The AudioManagement offers classification for sources and sinks. It can be used to group sources and sinks together and link certain behaviors to these groups. - An example for such a use is to group all interrupt sources in a class together and let the AudioManagerController react different for this class.\n - Elements can only have one class at a time. The AudioManagerDaemon will take care of registration of sourceClasses, sinkClasses and will assign unique IDs, - but the parameters of the Classes itself are product specific and have to be interpreted by the AudioManagerController. This concept allows for very individual - implementations of system behaviors.\n - Since Classes are held in the database, Classes can be registered and deregistered during runtime, it is recommended that the AudioManagerController enters - all source & sink classes at start-up into the database.A ClassProperty exists out of an enumeration (am_CustomClassProperty_t, project specific) and a corresponding - value (integer) that is interpreted by the AudioManagerController according to am_CustomClassProperty_t.\n - There is no restriction to the number of properties a class can have and how many classes can exist in a system.\n - \section attributes Attributes - - am::am_SourceClass_s describes the attributes of a source class\n - - am::am_SinkClass_s describes the attributes of a sink class\n -*/ diff --git a/AudioManagerDaemon/docx/07_interrupts.dox b/AudioManagerDaemon/docx/07_interrupts.dox deleted file mode 100644 index 0e26b88..0000000 --- a/AudioManagerDaemon/docx/07_interrupts.dox +++ /dev/null @@ -1,36 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! - - \page interrupts Interrups & Low Level Interrupts - \section diff Differences - The only difference between a "normal" interrupt and a source for the audioManagement may lie in it's classification, so playing a "normal" interrupt is not - different to changing a source. An exception here are the so called "low level interrupts".\n - \section crit Criterias - These are special sources that fulfill the following criteria: - - direct connection to a sink that is "always on", so no extra actions and communications need to be done in order to play audio - - no dependencies to the current system state need to be checked before playing. This means that the source knows if it is allowed to play at the moment it - wants to play - - all information for the source that is needed to judge if it is allowed to play or not is either directly retrieved by the source or set static via a property. - - This becomes very handy for implementing such things like park distance control. When the source is informed that it needs to output signals - (due to an emerging wall for example) it outputs the beeps directly to the amplifier that then overlays the sound to the current active source.\n - Settings that influence the behavior of low level interrupts like for example volume offset for park distance control or sound on/off for it need to be done via - sourceProperties on the source level, so that the judgment and the adoptions that need to be taken can be taken by the source without system interaction. - In order to give the AudioManagerController the chance to react on a low level interrupt (by lowering the main volume for example), a feedback path is provided - and the AudioManagerController is informed about the current state of the low level interrupt (via hooklInterruptStatusChange).\n -*/ diff --git a/AudioManagerDaemon/docx/08_connections.dox b/AudioManagerDaemon/docx/08_connections.dox deleted file mode 100644 index fd8a194..0000000 --- a/AudioManagerDaemon/docx/08_connections.dox +++ /dev/null @@ -1,33 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! - \page connpage Connections & MainConnections - \section con Connections - A connection connects a source to a sink to let audio data flow. The direction of the flow is always source to sink. For each connection the connectionFormat - must be defined when the connection is demanded, if source or sink is not capable of supporting this format, the connection cannot be established. - ConnectionFormats are product specific, also are some standard formats defined within GENIVI that can be enhanced in the product area. Examples of formats: - analog, autodefined, stereo 48khz 16bit PCM, .... - - \section maincon Mainconnections - is visible to the HMI and consists out of one or more connections. A MainConnection shall always connect a Source and a Sink visible to the HMI. - In contradiction to connections, the MainConnection does not know about connectionFormat. MainConnections are demanded by the commandInterface. - This picture demonstrates the relation between MainConnections and connections: - \image html Levels.png - - \section att Attributes - - am::am_Connection_s describes the attributes of a conenction - - */ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/09_lipsync.dox b/AudioManagerDaemon/docx/09_lipsync.dox deleted file mode 100644 index 6229198..0000000 --- a/AudioManagerDaemon/docx/09_lipsync.dox +++ /dev/null @@ -1,37 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! - \page lip Lipsync - - \section t The Task of the Audiomanager - 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 with the information provided by the AudioManager. - The time information is always reported by the routingadapters 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. - \section ex Example - \image html delay.jpg - - This graph shows how the delay is calculated: - - Connection 1 has a delay 2ms + 60ms that is added due to the gateway - - Connection 2 has a delay 0ms + 10ms due to sink - So the routing adapters report 62ms and 10ms, the audiomanager will add this to 72ms and report this value for the main connection from sink to source. - The videoplayer getting this information can now delay his video against the audio for 72ms and be in perfect lipsync.\n - After the buildup of a connection the first timing information needs to be sent within 5 seconds, the timing information from the routing adapters need to - be sent via 4 seconds. If the latency for a connection is variable and changes over lifetime of the connection, the routing adapters shall resend the value - and the audiomanager will correct the over all latency. -*/ diff --git a/AudioManagerDaemon/docx/10_early_audio.dox b/AudioManagerDaemon/docx/10_early_audio.dox deleted file mode 100644 index bdd72f5..0000000 --- a/AudioManagerDaemon/docx/10_early_audio.dox +++ /dev/null @@ -1,31 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! -\page early Early Audio -\section req The Requirement -The requirement reviews showed that one very important aspect of managing audio within GENIVI is the early/late phase where the Linux part of the system is -not available. This feature is addressed via special domains: EarlyDomains. These domains are acting "unmanaged" - meaning without the interaction with the -AudioManager - providing a simpler set of features until the AudioManager is up and running. When the Linux system is then fully operable a handover is done -from the EarlyDomains towards the AudioManager. In order to be able to operate without the Linux up and running, the EarlyDomains must be implemented on a -second fast-boot or always-on controller, e.g. the so called vehicle processor.\n -\section earlys Early Startup -This picture shows the principle of the early startup: -\image html early.png -\section late Late Rundown -This picture shows the principle of the late rundown: -\image html late.png -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/11_views.dox b/AudioManagerDaemon/docx/11_views.dox deleted file mode 100644 index 2dda7c9..0000000 --- a/AudioManagerDaemon/docx/11_views.dox +++ /dev/null @@ -1,33 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! -\page views The two views of the AudioManager -In general, there are two views of the system:\n -\section command The CommandInterface View View -This is an abstracted view that the HMI and other controlling Instances have of the system. Every Information (with some little exceptions) here is maintained -by the AudioManagerController, so that he can "fake" situations for the HMI. -So why is that? Depending on the actual project it might be - for example - that not the volume at the sink must be changed, but instead of the source. -The HMI does not know about sourceVolumes (and does not need to!) so the HMI would change the sink volume and the AudioManagerController can translate it to a -sourceVolumeChange. The metrics of the volumes are different as well. -It is the duty of the AudioManagementController to keep the commandInterface information consistent with the "real" situation. -\section route RoutingInterface View -Here are the "real" system states. All changes that are done on this interface are maintained by the AudioMangerDaemon and here is the actual situation always -consistent with the reality. All actions on this interface are either triggered by the AudioManagerController or by the domains itself, like registration for -example. -\section over Overview -\image html views.png -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/12_volumes.dox b/AudioManagerDaemon/docx/12_volumes.dox deleted file mode 100644 index 60603bc..0000000 --- a/AudioManagerDaemon/docx/12_volumes.dox +++ /dev/null @@ -1,29 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page vol Volumes & MainVolumes -\section mainVol MainVolumes -This is the volume at the CommanInterface level. The exact definition is project specific and can be adopted for each project since the AudioManagerController -and the HMI are the only ones who need to interfere with this volume. The actual value is an integer. -- am::am_mainVolume_t defines the mainvolume - -\section volv Volumes -These are the actual volumes that are set for sources and sinks. The unit is 0.1 db steps,The smallest value -3000 (=AM_MUTE). The minimum and maximum can be -limited by actual project. -- am::am_volume_t describes the volume -*/ diff --git a/AudioManagerDaemon/docx/13_properties.dox b/AudioManagerDaemon/docx/13_properties.dox deleted file mode 100644 index 2597fdf..0000000 --- a/AudioManagerDaemon/docx/13_properties.dox +++ /dev/null @@ -1,33 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ -/*! -\page prop Properties - \section soundprop SoundProperties & MainSoundProperties -SoundProperties are properties that are related to either a source or a sink. They are product specific and are used to set source or sink specific properties. -This could be for example: equalizer settings, relative volume offsets but also bool information "surround sound on/off". -A soundProperty is defined by its type (am_SoundProperty_e, a product specific enum) and a value (integer) that is interpreted according to the type. -There are not limits how many properties a sink or a source can have. SoundProperties in contradiction to MainSoundProperties are not visible to the -CommandInterface.\n -- am::am_SoundProperty_s describe the of the SoundProperties -- am::am_MainSoundProperty_s describe the attributes of MainSoundProperties - * -\section sys SystemProperties -are properties that apply to the whole system or parts of it but cannot be tight to a specific sink or source. They are product specific and could be used -for example to set general behavior like all interrupts on/off for example. The information is only exchanged between the commandInterface and the -AudioManagerController. The AudioManagerController has to interpret the value and react accordingly. -- am::am_SystemProperty_s describes the attributes of Systemproperties -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/13_x_notifications.dox b/AudioManagerDaemon/docx/13_x_notifications.dox deleted file mode 100644 index 135d4a5..0000000 --- a/AudioManagerDaemon/docx/13_x_notifications.dox +++ /dev/null @@ -1,64 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! -\page notifi Notifications -\section notifi_ex What are notifications? -The notification feature can be used to gather information from sources or sinks periodically or on certain thresholds.It can be used to implement a graphical spectrum for example or other information need to be passed back from sources or sinks. - -\section notifi_overview Overview -\image html Notifications.png - -\section notifi_command CommandInterface -all this methods have to do with MainNotifications (Information level between command and control) -- am::IAmCommandSend::cbSinkNotification -- am::IAmCommandSend::cbSourceNotification -- am::IAmCommandSend::cbMainSinkNotificationConfigurationChanged -- am::IAmCommandSend::cbMainSourceNotificationConfigurationChanged -- am::IAmCommandReceive::getListMainSourceNotificationConfigurations -- am::IAmCommandReceive::getListMainSinkNotificationConfigurations -- am::IAmCommandReceive::setMainSourceNotificationConfiguration -- am::IAmCommandReceive::setMainSinkNotificationConfiguration -\section notifi_control ControlInterface -all this methods have to do with MainNotifications (Information level between command and control) -- am::IAmControlSend::hookUserSetMainSinkNotificationConfiguration -- am::IAmControlSend::hookUserSetMainSourceNotificationConfiguration -- am::IAmControlReceive::changeMainSinkNotificationConfigurationDB -- am::IAmControlReceive::changeMainSourceNotificationConfigurationDB -- am::IAmControlReceive::sendMainSinkNotificationPayload -- am::IAmControlReceive::sendMainSourceNotificationPayload - -all this methods have to do with notifications (Information level between cotrol and routing) -- am::IAmControlSend::cbAckSetSinkNotificationConfiguration -- am::IAmControlSend::cbAckSetSourceNotificationConfiguration -- am::IAmControlSend::hookSinkNotificationDataChanged -- am::IAmControlSend::hookSourceNotificationDataChanged -- am::IAmControlReceive::setSinkNotificationConfiguration -- am::IAmControlReceive::setSourceNotificationConfiguration -\section notifi_routing RoutingInterface -all this methods have to do with notifications (Information level between cotrol and routing) -- am::IAmRoutingSend::asyncSetSinkNotificationConfiguration -- am::IAmRoutingSend::asyncSetSourceNotificationConfiguration -- am::IAmRoutingReceive::ackSinkNotificationConfiguration -- am::IAmRoutingReceive::ackSourceNotificationConfiguration -- am::IAmRoutingReceive::hookSinkNotificationDataChange -- am::IAmRoutingReceive::hookSourceNotificationDataChange - -\section notifi_levels Notification Levels -For notifications it's the same as for the soundproperties: there are two levels of information. One is between the Command Interface and the Control Interface -here it is in the duty of the controller to handle the notification data. The other one is between Control and Routing Interface. This could be used for example -to route the information from a source to the command interface. -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/14_misc.dox b/AudioManagerDaemon/docx/14_misc.dox deleted file mode 100644 index 8ae15c2..0000000 --- a/AudioManagerDaemon/docx/14_misc.dox +++ /dev/null @@ -1,39 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ -/*! -\page misc Miscellaneous - -\section misc_connfor Connection Formats -Every flow of audio is using a format to exchange data. The format that the source and the sink uses must match together in order to have an undisturbed -experience. It is common that sources and sinks are capable of supporting more than one audioformat.\n -So all sources and sinks register with a list of connectionFormats that they support and for each connection a format must be chosen that is then used -to transport the audio data. Gateways (and Soundconverters) have the information which connectionFormat can be transformed into another one. -am::am_CustomAvailabilityReason_t has all formats listed.\n -There is a special usecase that is worth showing as an example in this regard: the change of a connectionFormat when switching from one song to another. Here is an -example of how the project specific parts could handle this: -\image html ChangeofAudioformatduringplaytime.png - - -\section misc_pers Persistence -The persistence client library is defined as an abstract component with a c-like library interface. Since the AudioManagerController is the only one to know -what is to be made persistent, he is the one interfacing with that library. This is the reason why there is no specific interface for the persistence here. - -\section misc_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. The interface in not yet defined !\n -Turning speed controlled volume on/off and possible settings are achieved via SinkSoundProperty settings. -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/14_u_last_user_mode.dox b/AudioManagerDaemon/docx/14_u_last_user_mode.dox deleted file mode 100644 index 0c90f89..0000000 --- a/AudioManagerDaemon/docx/14_u_last_user_mode.dox +++ /dev/null @@ -1,37 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page luc Last User Mode -\section luc_concept Last User Mode concept -In general last user modes are project specific. So it is not mandatory to do it like described here - it is just a suggestion how it could be implemented -together with the LUC handler (Last User Concept). The LUC handler is a part of the NSC (Node State Controller) which is a GENIVI component. More information can be -found within GENIVI.\n -For implementing the suggested method here, the AudioManagerController has to take care of communicating with the LUC handler. The AudioManager is the -component that knows the last heard source that should be started earlier than others in order to reduce the timespan until the customer can hear it's last -source.\n -In order to fullfull this, the controller has to keep a map that links sources to unit files. The sequence that shall be an example of how it could be realized.\n - -\section luc_rundown The handling in the rundown context: -\image html LastUserModeHandlingExample.png - -\section luc_startup The next startup: -\image html StartupWithLastUserMode.png - - - - */ diff --git a/AudioManagerDaemon/docx/14_x_mainloop.dox b/AudioManagerDaemon/docx/14_x_mainloop.dox deleted file mode 100644 index 8f112bc..0000000 --- a/AudioManagerDaemon/docx/14_x_mainloop.dox +++ /dev/null @@ -1,49 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page mainl Mainloop concept -\section mconcept Mainloop -The AudioManager comes with a build in mainloop that can be utilized by the plug-ins to serve their needs of communication and thread-safe calling. -The mainloop, implemented in CAmSocketHandler works like this:\n -\image html Mainloop.png - -\section sec Using the Mainloop -Adding and removing callbacks and timers work via the am::CAmSocketHandler.\n -To add a callback, use am::CAmSocketHandler::addFDPoll, to remove one, use am::CAmSocketHandler::removeFDPoll.\n -To add a timer callback, use am::CAmSocketHandler::addTimer, use am::CAmSocketHandler::removeTimer and am::CAmSocketHandler::restartTimer and -am::CAmSocketHandler::stopTimer.\n -The mainloop is started via am::CAmSocketHandler::start_listenting and stopped via am::CAmSocketHandler::stop_listening. -Example code can be found in am::CAmDbusWrapper. - -\section util Utilizing The Mainloop as Threadsafe Call Method -The AudioManager itself is singlethreaded, so any calls from other threads inside the plugins directly to the interfaces is forbidden, the -behavior is undefined. The reason for this is that communication and routing plugins are often only communication interfaces that can are ideally used -with the am::CAmSocketHandler.\n -am::CAmSerializer creates an intermediate object on the heap holding all informations of the function to be called and a pointer to the object to be called. -After that, the class writes to a pipe witch triggers the mainloop to call the callback am::CAmSerializer::receiverCallback from the maincontext. The -callback uses the intermediate object to do the actual call. \n -\warning asynchronous calls can be used within the main thread, but synchronous not -> the call would block forever !\n -For each thread that needs to use synchronous calls independent an own instance of am::CAmSerializer needs to be used. -\subsection async Asynchronous calls -\image html Deferred_Call_async.png -\subsection sync Synchronous calls -\image html Deferred_Call_sync.png - - - - */ diff --git a/AudioManagerDaemon/docx/14_y_watchdog.dox b/AudioManagerDaemon/docx/14_y_watchdog.dox deleted file mode 100644 index a1facc5..0000000 --- a/AudioManagerDaemon/docx/14_y_watchdog.dox +++ /dev/null @@ -1,44 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page watchd The watchdog -\section watchdconcept The watchdog concept -The watchdog concept of the audiomanger is based on systemd. When systemd is configured via the unit file to use a watchdog and watchdog support is activated -in the audiomanager, the audiomanager will reset the watchdog via the mainloop in the given interval to prevent systemd from restarting the audiomanager.\n -If the audiomanager is stuck for whatever reason, systemd will not get this update and restart the audiomanager. - - -\section configwatch Watchdog configuration -By default, the watchdog is enabled in the audiomanager, you can disable the watchdog functionality by setting the cmake build option "WITH_SYSTEMD_WATCHDOG" to -OFF, either by modifying the cmake cache with ccache or by passing -DWITH_SYSTEMD_WATCHDOG=OFF to cmake.\n -The interval for checking the watchdog can be set in the unitfile of systemd by setting "WatchdogSec". The other settings need to be done as well: -\code -Restart=always -WatchdogSec=2 -NotifyAccess=main -\endcode -The intervall for pinging systemd is set to the half of "WatchdogSec". - -\section winteg Integration with systemd -The audiomanager will use the library proviced by "libsystemd-daemon" if it is available on the system. If this library is not available, the files sd-daemon.c and sd-daemon.h -that are provided with the audiomanager and released under MIT licence by Lennard Poettering will be used to connect to systemd. - -more information can be found here: am::CAmWatchdog and sd-daemon.h . - - - */ diff --git a/AudioManagerDaemon/docx/14_zz_Startup_Rundown.dox b/AudioManagerDaemon/docx/14_zz_Startup_Rundown.dox deleted file mode 100644 index 88f8dc6..0000000 --- a/AudioManagerDaemon/docx/14_zz_Startup_Rundown.dox +++ /dev/null @@ -1,30 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - -/*! -\page start Startup and Rundown -\section start_Start Startup -This flow describes the startup of the AudioManager: -\image html Startup.png -\section start_Rundown Rundown -This flow describes the rundown of the AudioManager: -\image html Rundown.png -\section start_Cancel Cancelled Rundown -This flow describes the cancel rundown of the AudioManager: -\image html CancelRundown.png - - */ diff --git a/AudioManagerDaemon/docx/15_a_CommandLineParsing.dox b/AudioManagerDaemon/docx/15_a_CommandLineParsing.dox deleted file mode 100644 index 74dd2e0..0000000 --- a/AudioManagerDaemon/docx/15_a_CommandLineParsing.dox +++ /dev/null @@ -1,45 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! -\page cmdline CommandLineParsing -\section tclap TCLAP -Commandline parsing is accomplished via a template library that is added to the source tree of the Audiomanager: TCLAP. -The license of this libraty is MIT. -It manages commandline parsing in a handy way. More information can be found here: -http://tclap.sourceforge.net -\section cmdplugins CommandLine Parsing in the Plugins -The commandline Class that parses the commandline can be accessed via am::CAmCommandLineSingleton . This factory creates -a commandline object that can be accessed everywhere in the Audiomanager. -In the constructor of a plugin, the plugins can add commandline arguments they hold as member. -Here the member, in this case of type TCLAP::ValueArg mCommandLineArg; - -\code -mCommandLineArg("K","controllerPluginArg","a test argument for the controller",false,"bla","string") -\endcode - -In the constructor, add the argument to the commandline like this -\code -CAmCommandLineSingleton::instance()->add(mCommandLineArg); -\endcode -And then in the startup controller routine (or later) you can get the value of the argument, like -\code -mCommandLineArg.getValue() -\endcode - -An example can be found in the plugins repository in the test controller. - -*/ diff --git a/AudioManagerDaemon/docx/15_dlt_support.dox b/AudioManagerDaemon/docx/15_dlt_support.dox deleted file mode 100644 index ca34896..0000000 --- a/AudioManagerDaemon/docx/15_dlt_support.dox +++ /dev/null @@ -1,23 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - /*! -\page dlt Dlt support -\section compile Compilerswitch -The AudioManager can be compiled with or without DLT support, in case that DLT is not compiled in (cmake option WITH_DLT), logging is switched off. -You can log to the commandline by starting the Audiomanager with the option -V.\n -If you want to log to the commandline and you have dlt compiled in, use the environment variable of the dlt to log to the command line. -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/15_x_eclipse.dox b/AudioManagerDaemon/docx/15_x_eclipse.dox deleted file mode 100644 index 95c8e9f..0000000 --- a/AudioManagerDaemon/docx/15_x_eclipse.dox +++ /dev/null @@ -1,91 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ - - -/*! -\page eclip Download Compile Debug -\section dw Get the source -For compiling the source, you need to use git and the following packages:\n -\code -sudo apt-get install libdbus-1-dev libsqlite3-dev doxygen libgtest-dev google-mock git cmake build-essential python2.6-dev -\endcode -Getting the source got works with following command -\code -git clone https://:@git.genivi.org/srv/git/AudioManager -\endcode -\section build Compile -In order to build the project (out of source build), please follow these instructions on the commandline: -\code -mkdir /build -cd build -cmake .. -\endcode -if you want to influence the build options, you can use ccmake for example (apt-get install ccmake) -\code -ccmake .. -\endcode -You will get a menue that let's you select different options for the build. Compiling with a simple -\code -make -\endcode -after the script finished, you should have: -- a bin/ folder which contains all executables and the libraries: -- a build/ folder which has all build objects (erase that if you need a clean build) -- a doc/ folder in case you turned the documentation on - -in order to install the AudioManager, you can do -\code -sudo make install -\endcode -package generation is supported via CPack. To build packages, you have to -\code -make genivi_package -\endocde -this will create one package if your CMake version is < 2.8.5 (all binaries stripped): -\code -AudioManager--Linux.deb -\endcode -if your version is above, you will get 4 packages (all binaries stripped) : -\code -AudioManager--Linux-bin.deb [AudioManager binary] -AudioManager--Linux-dev.deb [header files needed to compile plugins] -AudioManager--Linux-sampleplugins.deb [sample plugins] -AudioManager--Linux-tests.deb [tests including tests for sample plugins, -installed in the ~/AudioMAnagerTests] -\endcode -to create a tar.gz file of all sources (not including .git, build and bin folder,config files), you can do: -\code -make package_source -\endcode -This will create the following package: -\code -AudioManager--Source.tar.gz -\endcode -All packages will be placed in a folder called packages -\section ec Using Eclipse -First you need to get eclipse, for example by downloading it from http://www.eclipse.org/ use the C++ CDT version. -Import the project with\n -File-> import project\n -Select "existing code as makefile project" and choose the root folder auf the AudioManager\n -In order to build with eclipse you need to tell eclipse where the makefile can be found:\n -In project properties enter as build command: -\code -"make -j4 -C build" as build command -\endcode -\section deb Debugging with eclipse -For debugging you need to modify debug configurations, choose the audiomanager as binary, the debugging should work. -*/ diff --git a/AudioManagerDaemon/docx/16_readme.dox b/AudioManagerDaemon/docx/16_readme.dox deleted file mode 100644 index 7798fee..0000000 --- a/AudioManagerDaemon/docx/16_readme.dox +++ /dev/null @@ -1,20 +0,0 @@ - /* - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * \\author Christian Linke (christian.linke@bmw.de) - * - */ -/*! -\page comp Compiling & Co - README -*/ \ No newline at end of file diff --git a/AudioManagerDaemon/docx/Doxyfile.in b/AudioManagerDaemon/docx/Doxyfile.in deleted file mode 100644 index 8cd141f..0000000 --- a/AudioManagerDaemon/docx/Doxyfile.in +++ /dev/null @@ -1,268 +0,0 @@ -# Doxyfile 1.6.3 - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = AudioManager -PROJECT_NUMBER = @DAEMONVERSION@ -OUTPUT_DIRECTORY = @DOC_OUTPUT_PATH@ -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = -SHORT_NAMES = YES -JAVADOC_AUTOBRIEF = YES -QT_AUTOBRIEF = YES -MULTILINE_CPP_IS_BRIEF = YES -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 8 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -OPTIMIZE_FOR_FORTRAN = NO -OPTIMIZE_OUTPUT_VHDL = NO -EXTENSION_MAPPING = -BUILTIN_STL_SUPPORT = YES -CPP_CLI_SUPPORT = YES -SIP_SUPPORT = NO -IDL_PROPERTY_SUPPORT = YES -DISTRIBUTE_GROUP_DOC = NO -SUBGROUPING = YES -TYPEDEF_HIDES_STRUCT = NO -SYMBOL_CACHE_SIZE = 0 -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = YES -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = YES -EXTRACT_ANON_NSPACES = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = NO -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -FORCE_LOCAL_INCLUDES = NO -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_MEMBERS_CTORS_1ST = YES -SORT_GROUP_NAMES = YES -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = NO -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = YES -SHOW_FILES = YES -SHOW_NAMESPACES = YES -FILE_VERSION_FILTER = -LAYOUT_FILE = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = YES -WARNINGS = NO -WARN_IF_UNDOCUMENTED = NO -WARN_IF_DOC_ERROR = NO -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text " -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = @CMAKE_CURRENT_SOURCE_DIR@ -INPUT_ENCODING = UTF-8 -FILE_PATTERNS = *.h *.cpp *.dox -RECURSIVE = YES -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = */test/* */build*/* */cmake/* */googleMock/* */tclap*/* -EXCLUDE_SYMBOLS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = @CMAKE_SOURCE_DIR@/AudioManagerDaemon/docx/images -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = YES -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = YES -REFERENCES_RELATION = YES -REFERENCES_LINK_SOURCE = YES -USE_HTAGS = NO -VERBATIM_HEADERS = YES -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = YES -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_COLORSTYLE_HUE = 220 -HTML_COLORSTYLE_SAT = 100 -HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = YES -HTML_ALIGN_MEMBERS = YES -HTML_DYNAMIC_SECTIONS = YES -GENERATE_DOCSET = YES -DOCSET_FEEDNAME = "AudioManager docs" -DOCSET_BUNDLE_ID = org.genivi.AudioManager.Doxygen -DOCSET_PUBLISHER_ID = org.genivi.AudioManager.Publisher -DOCSET_PUBLISHER_NAME = genivi -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -CHM_INDEX_ENCODING = -BINARY_TOC = NO -TOC_EXPAND = NO -GENERATE_QHP = NO -QCH_FILE = -QHP_NAMESPACE = org.doxygen.Project -QHP_VIRTUAL_FOLDER = doc -QHP_CUST_FILTER_NAME = -QHP_CUST_FILTER_ATTRS = -QHP_SECT_FILTER_ATTRS = -QHG_LOCATION = -GENERATE_ECLIPSEHELP = NO -ECLIPSE_DOC_ID = org.genivi.AudioManager -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = YES -USE_INLINE_TREES = YES -TREEVIEW_WIDTH = 250 -EXT_LINKS_IN_WINDOW = YES -FORMULA_FONTSIZE = 10 -SEARCHENGINE = YES -SERVER_BASED_SEARCH = NO -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = YES -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -LATEX_SOURCE_CODE = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = @CMAKE_SOURCE_DIR@/man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = NO -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = YES -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = NO -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -MSCGEN_PATH = -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -DOT_FONTNAME = FreeSans.ttf -DOT_FONTSIZE = 10 -DOT_FONTPATH = -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -TEMPLATE_RELATIONS = YES -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = YES -CALLER_GRAPH = YES -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -DOT_GRAPH_MAX_NODES = 50 -MAX_DOT_GRAPH_DEPTH = 0 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = YES -GENERATE_LEGEND = YES -DOT_CLEANUP = YES diff --git a/AudioManagerDaemon/docx/images/AudioDomains.gif b/AudioManagerDaemon/docx/images/AudioDomains.gif deleted file mode 100644 index d3f1c8d..0000000 Binary files a/AudioManagerDaemon/docx/images/AudioDomains.gif and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/AudioManagement.png b/AudioManagerDaemon/docx/images/AudioManagement.png deleted file mode 100755 index f3b4cdd..0000000 Binary files a/AudioManagerDaemon/docx/images/AudioManagement.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/AvailabilityofSinks.png b/AudioManagerDaemon/docx/images/AvailabilityofSinks.png deleted file mode 100644 index c912cdf..0000000 Binary files a/AudioManagerDaemon/docx/images/AvailabilityofSinks.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/AvailabilityofSources.png b/AudioManagerDaemon/docx/images/AvailabilityofSources.png deleted file mode 100644 index 543a9f7..0000000 Binary files a/AudioManagerDaemon/docx/images/AvailabilityofSources.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/CancelRundown.png b/AudioManagerDaemon/docx/images/CancelRundown.png deleted file mode 100755 index 889ed56..0000000 Binary files a/AudioManagerDaemon/docx/images/CancelRundown.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/ChangeofAudioformatduringplaytime.png b/AudioManagerDaemon/docx/images/ChangeofAudioformatduringplaytime.png deleted file mode 100755 index 2fa30a1..0000000 Binary files a/AudioManagerDaemon/docx/images/ChangeofAudioformatduringplaytime.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/ClassDiagramm.png b/AudioManagerDaemon/docx/images/ClassDiagramm.png deleted file mode 100755 index 63f048b..0000000 Binary files a/AudioManagerDaemon/docx/images/ClassDiagramm.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Deferred_Call_async.png b/AudioManagerDaemon/docx/images/Deferred_Call_async.png deleted file mode 100644 index 30ad24e..0000000 Binary files a/AudioManagerDaemon/docx/images/Deferred_Call_async.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Deferred_Call_sync.png b/AudioManagerDaemon/docx/images/Deferred_Call_sync.png deleted file mode 100644 index 51c46dc..0000000 Binary files a/AudioManagerDaemon/docx/images/Deferred_Call_sync.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Gateway.gif b/AudioManagerDaemon/docx/images/Gateway.gif deleted file mode 100644 index 45badf9..0000000 Binary files a/AudioManagerDaemon/docx/images/Gateway.gif and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/GatewayMatrix.png b/AudioManagerDaemon/docx/images/GatewayMatrix.png deleted file mode 100644 index dcc0682..0000000 Binary files a/AudioManagerDaemon/docx/images/GatewayMatrix.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Interaction_with_sourcessinks.png b/AudioManagerDaemon/docx/images/Interaction_with_sourcessinks.png deleted file mode 100644 index 653da90..0000000 Binary files a/AudioManagerDaemon/docx/images/Interaction_with_sourcessinks.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Interacton_Overview.png b/AudioManagerDaemon/docx/images/Interacton_Overview.png deleted file mode 100644 index 023b1c0..0000000 Binary files a/AudioManagerDaemon/docx/images/Interacton_Overview.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/InterruptStatusChange.png b/AudioManagerDaemon/docx/images/InterruptStatusChange.png deleted file mode 100755 index b38cf21..0000000 Binary files a/AudioManagerDaemon/docx/images/InterruptStatusChange.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/LastUserModeHandlingExample.png b/AudioManagerDaemon/docx/images/LastUserModeHandlingExample.png deleted file mode 100755 index fd34b4a..0000000 Binary files a/AudioManagerDaemon/docx/images/LastUserModeHandlingExample.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Levels.png b/AudioManagerDaemon/docx/images/Levels.png deleted file mode 100644 index 9ba0886..0000000 Binary files a/AudioManagerDaemon/docx/images/Levels.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Lifecylerequest.png b/AudioManagerDaemon/docx/images/Lifecylerequest.png deleted file mode 100755 index f6a67fc..0000000 Binary files a/AudioManagerDaemon/docx/images/Lifecylerequest.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Mainloop.png b/AudioManagerDaemon/docx/images/Mainloop.png deleted file mode 100644 index 979c133..0000000 Binary files a/AudioManagerDaemon/docx/images/Mainloop.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/NodeStateManagementRelations.png b/AudioManagerDaemon/docx/images/NodeStateManagementRelations.png deleted file mode 100755 index 52c25c6..0000000 Binary files a/AudioManagerDaemon/docx/images/NodeStateManagementRelations.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Notifications.png b/AudioManagerDaemon/docx/images/Notifications.png deleted file mode 100755 index d938d61..0000000 Binary files a/AudioManagerDaemon/docx/images/Notifications.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/PluginCommandInterfaceCAPI.png b/AudioManagerDaemon/docx/images/PluginCommandInterfaceCAPI.png deleted file mode 100644 index 882be93..0000000 Binary files a/AudioManagerDaemon/docx/images/PluginCommandInterfaceCAPI.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/PluginRoutingInterfaceCAPI.png b/AudioManagerDaemon/docx/images/PluginRoutingInterfaceCAPI.png deleted file mode 100644 index 0ae79f5..0000000 Binary files a/AudioManagerDaemon/docx/images/PluginRoutingInterfaceCAPI.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Register_Domain.png b/AudioManagerDaemon/docx/images/Register_Domain.png deleted file mode 100644 index 09a1251..0000000 Binary files a/AudioManagerDaemon/docx/images/Register_Domain.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Registrations.png b/AudioManagerDaemon/docx/images/Registrations.png deleted file mode 100755 index b3abae9..0000000 Binary files a/AudioManagerDaemon/docx/images/Registrations.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Rundown.png b/AudioManagerDaemon/docx/images/Rundown.png deleted file mode 100755 index daa8470..0000000 Binary files a/AudioManagerDaemon/docx/images/Rundown.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/SettingConnectionFormats.png b/AudioManagerDaemon/docx/images/SettingConnectionFormats.png deleted file mode 100755 index 7e52c66..0000000 Binary files a/AudioManagerDaemon/docx/images/SettingConnectionFormats.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/SoundPropertyChangeofSink.png b/AudioManagerDaemon/docx/images/SoundPropertyChangeofSink.png deleted file mode 100644 index 5381bdc..0000000 Binary files a/AudioManagerDaemon/docx/images/SoundPropertyChangeofSink.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/SoundPropertyChangeofSource.png b/AudioManagerDaemon/docx/images/SoundPropertyChangeofSource.png deleted file mode 100644 index 6dd8328..0000000 Binary files a/AudioManagerDaemon/docx/images/SoundPropertyChangeofSource.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/SourceStates.png b/AudioManagerDaemon/docx/images/SourceStates.png deleted file mode 100755 index bf4a6ec..0000000 Binary files a/AudioManagerDaemon/docx/images/SourceStates.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/Startup.png b/AudioManagerDaemon/docx/images/Startup.png deleted file mode 100755 index 6fa84a5..0000000 Binary files a/AudioManagerDaemon/docx/images/Startup.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/StartupWithLastUserMode.png b/AudioManagerDaemon/docx/images/StartupWithLastUserMode.png deleted file mode 100755 index a42ac2e..0000000 Binary files a/AudioManagerDaemon/docx/images/StartupWithLastUserMode.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/VolumeChangesofSinks.png b/AudioManagerDaemon/docx/images/VolumeChangesofSinks.png deleted file mode 100755 index 5870a80..0000000 Binary files a/AudioManagerDaemon/docx/images/VolumeChangesofSinks.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/VolumeChangesofSources.png b/AudioManagerDaemon/docx/images/VolumeChangesofSources.png deleted file mode 100644 index b8cf682..0000000 Binary files a/AudioManagerDaemon/docx/images/VolumeChangesofSources.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/bus_topology.png b/AudioManagerDaemon/docx/images/bus_topology.png deleted file mode 100644 index 44486ff..0000000 Binary files a/AudioManagerDaemon/docx/images/bus_topology.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/daemon_insight.png b/AudioManagerDaemon/docx/images/daemon_insight.png deleted file mode 100755 index 341e3ab..0000000 Binary files a/AudioManagerDaemon/docx/images/daemon_insight.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/delay.jpg b/AudioManagerDaemon/docx/images/delay.jpg deleted file mode 100644 index 6b645b7..0000000 Binary files a/AudioManagerDaemon/docx/images/delay.jpg and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/dependencies.png b/AudioManagerDaemon/docx/images/dependencies.png deleted file mode 100644 index 30d272f..0000000 Binary files a/AudioManagerDaemon/docx/images/dependencies.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/dependencies_test.png b/AudioManagerDaemon/docx/images/dependencies_test.png deleted file mode 100644 index 870bc26..0000000 Binary files a/AudioManagerDaemon/docx/images/dependencies_test.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/dependency_created.png b/AudioManagerDaemon/docx/images/dependency_created.png deleted file mode 100644 index 7eabbf8..0000000 Binary files a/AudioManagerDaemon/docx/images/dependency_created.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/early.png b/AudioManagerDaemon/docx/images/early.png deleted file mode 100644 index 016cad7..0000000 Binary files a/AudioManagerDaemon/docx/images/early.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/example_system.png b/AudioManagerDaemon/docx/images/example_system.png deleted file mode 100644 index 6019c22..0000000 Binary files a/AudioManagerDaemon/docx/images/example_system.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/genivilogo.png b/AudioManagerDaemon/docx/images/genivilogo.png deleted file mode 100644 index d016ec8..0000000 Binary files a/AudioManagerDaemon/docx/images/genivilogo.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/late.png b/AudioManagerDaemon/docx/images/late.png deleted file mode 100644 index 76753a8..0000000 Binary files a/AudioManagerDaemon/docx/images/late.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/routing_hierarchy.png b/AudioManagerDaemon/docx/images/routing_hierarchy.png deleted file mode 100644 index d9586e9..0000000 Binary files a/AudioManagerDaemon/docx/images/routing_hierarchy.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/unique.svg b/AudioManagerDaemon/docx/images/unique.svg deleted file mode 100644 index c957a1c..0000000 --- a/AudioManagerDaemon/docx/images/unique.svg +++ /dev/null @@ -1,209 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - ID 1 - ID 100 - ID 101 - Fixed Area - Dynamic Area - - diff --git a/AudioManagerDaemon/docx/images/versioning.png b/AudioManagerDaemon/docx/images/versioning.png deleted file mode 100644 index 9b587ba..0000000 Binary files a/AudioManagerDaemon/docx/images/versioning.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/versioning_new.png b/AudioManagerDaemon/docx/images/versioning_new.png deleted file mode 100755 index f5de375..0000000 Binary files a/AudioManagerDaemon/docx/images/versioning_new.png and /dev/null differ diff --git a/AudioManagerDaemon/docx/images/views.png b/AudioManagerDaemon/docx/images/views.png deleted file mode 100644 index d036ef4..0000000 Binary files a/AudioManagerDaemon/docx/images/views.png and /dev/null differ diff --git a/AudioManagerDaemon/include/CAmCommandReceiver.h b/AudioManagerDaemon/include/CAmCommandReceiver.h deleted file mode 100644 index 0f30d81..0000000 --- a/AudioManagerDaemon/include/CAmCommandReceiver.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmCommandReceiver.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef COMMANDRECEIVER_H_ -#define COMMANDRECEIVER_H_ - -#include "IAmCommand.h" - -namespace am -{ - -class IAmDatabaseHandler; -class CAmControlSender; -class CAmDbusWrapper; -class CAmSocketHandler; - -/** - * This class realizes the command Interface - */ -class CAmCommandReceiver: public IAmCommandReceive -{ -public: - CAmCommandReceiver(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iControlSender, CAmSocketHandler* iSocketHandler); - CAmCommandReceiver(IAmDatabaseHandler* 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 getVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const; - 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 confirmCommandReady(const uint16_t handle, const am_Error_e error); - void confirmCommandRundown(const uint16_t handle, const am_Error_e error); - void getInterfaceVersion(std::string& version) const; - am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) const ; - am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) const ; - am_Error_e setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; - am_Error_e setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; - - 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: - IAmDatabaseHandler* 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 - am_Error_e mLastErrorStartup; - am_Error_e mLastErrorRundown; -}; - -} - -#endif /* COMMANDRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmCommandSender.h b/AudioManagerDaemon/include/CAmCommandSender.h deleted file mode 100644 index 82363de..0000000 --- a/AudioManagerDaemon/include/CAmCommandSender.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmCommandSender.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef COMMANDSENDER_H_ -#define COMMANDSENDER_H_ - -#ifdef UNIT_TEST -#include "../test/IAmCommandBackdoor.h" //we need this for the unit test -#endif - -#include "IAmCommand.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; - void cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties); - void cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties); - void cbSinkNotification(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification); - void cbSourceNotification(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification); - void cbSinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration); - void cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration); - -#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 deleted file mode 100644 index 3f39189..0000000 --- a/AudioManagerDaemon/include/CAmControlReceiver.h +++ /dev/null @@ -1,156 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmControlReceiver.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CONTRONLRECEIVER_H_ -#define CONTRONLRECEIVER_H_ - -#include "IAmControl.h" - -namespace am -{ - -class CAmSocketHandler; -class IAmDatabaseHandler; -class CAmRoutingSender; -class CAmCommandSender; -class CAmRouter; -class CAmNodeStateCommunicator; - -/** - * This class is used to receive all commands from the control interface - */ -class CAmControlReceiver: public IAmControlReceive -{ -public: - CAmControlReceiver(IAmDatabaseHandler *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_CustomConnectionFormat_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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 enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID); - 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 removeConverterDB(const am_converterID_t converterID); - 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 getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) 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 getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConverterID) 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 getListConverters(std::vector& listConverters) 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(const am_Error_e error); - void confirmControllerRundown(const am_Error_e error); - am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler); - void getInterfaceVersion(std::string& version) const; - am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) ; - am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); - am_Error_e setVolumes(am_Handle_s& handle, const std::vector& listVolumes) ; - am_Error_e setSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) ; - am_Error_e setSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) ; - void sendMainSinkNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s& notificationPayload) ; - void sendMainSourceNotificationPayload(const am_sourceID_t sourceID, const am_NotificationPayload_s& notificationPayload) ; - am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; - am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) ; - am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; - am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const; - am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; - am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const; - am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e resyncConnectionState(const am_domainID_t domainID, std::vector& listOfExistingConnections); - -private: - IAmDatabaseHandler* 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 - CAmNodeStateCommunicator* mNodeStateCommunicator; -}; - -} - -#endif /* CONTRONLRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmControlSender.h b/AudioManagerDaemon/include/CAmControlSender.h deleted file mode 100644 index 40ab379..0000000 --- a/AudioManagerDaemon/include/CAmControlSender.h +++ /dev/null @@ -1,154 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmControlSender.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CONTROLSENDER_H_ -#define CONTROLSENDER_H_ - -#ifdef UNIT_TEST -#include "../test/IAmControlBackdoor.h" -#endif - -#include "IAmControl.h" -#include "CAmSocketHandler.h" -#include "unistd.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,CAmSocketHandler* sockethandler); - CAmControlSender(); - ~CAmControlSender(); - am_Error_e startupController(IAmControlReceive* controlreceiveinterface) ; - void setControllerReady() ; - void setControllerRundown(const int16_t signal) ; - 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 hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID); - am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ; - am_Error_e hookSystemDeregisterConverter(const am_converterID_t converterID) ; - 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 confirmCommandReady(const am_Error_e error) ; - void confirmRoutingReady(const am_Error_e error) ; - void confirmCommandRundown(const am_Error_e error) ; - void confirmRoutingRundown(const am_Error_e error) ; - void getInterfaceVersion(std::string& version) const ; - am_Error_e hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - am_Error_e hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - am_Error_e hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) ; - am_Error_e hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix); - void cbAckSetVolume(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error) ; - void cbAckSetSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; - void cbAckSetSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; - void hookSinkNotificationDataChanged(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) ; - void hookSourceNotificationDataChanged(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) ; - am_Error_e hookUserSetMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) ; - am_Error_e hookUserSetMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) ; - void hookSystemSingleTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t time); - - void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - bool checkerCallback(const sh_pollHandle_t handle, void* userData); - bool dispatcherCallback(const sh_pollHandle_t handle, void* userData); - - void setControllerRundownSafe(int16_t signal) - { - int16_t p(signal); - ssize_t result(-1); - result = write(mPipe[1], &p, sizeof(p)); - } - - TAmShPollFired receiverCallbackT; - TAmShPollCheck checkerCallbackT; - TAmShPollDispatch dispatcherCallbackT; - - - //we need this here to call the rundown from the signal handler. In case everything screwed up - static void CallsetControllerRundown(int16_t signal) - { - if (mInstance) - mInstance->setControllerRundown(signal); - } - - //this static callback is used from the signal handler. It is used when a normal rundown is assumed and the mainloop is used to call rundown. - static void CallsetControllerRundownSafe(int16_t signal) - { - if (mInstance) - { - mInstance->setControllerRundownSafe(signal); - } - } - -#ifdef UNIT_TEST - friend class IAmControlBackdoor; -#endif -private: - int mPipe[2]; - void* mlibHandle; //!< pointer to the loaded control plugin interface - IAmControlSend* mController; //!< pointer to the ControlSend interface - static CAmControlSender* mInstance; - int16_t mSignal; -}; - -} - -#endif /* CONTROLSENDER_H_ */ diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h deleted file mode 100644 index cf319f7..0000000 --- a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h +++ /dev/null @@ -1,495 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file CAmDatabaseHandlerMap.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MAPHANDLER_H_ -#define MAPHANDLER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "IAmDatabaseHandler.h" - -namespace am -{ -#ifndef AM_MAP_CAPACITY - #define AM_MAP_CAPACITY 0 -#endif - -#ifndef AM_MAX_CONNECTIONS - #define AM_MAX_CONNECTIONS 0x1000 -#endif - -#ifndef AM_MAX_MAIN_CONNECTIONS - #define AM_MAX_MAIN_CONNECTIONS SHRT_MAX -#endif - - - -//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 CAmDatabaseHandlerMap : public IAmDatabaseHandler -{ - bool mFirstStaticSink; //!< bool for dynamic range handling - bool mFirstStaticSource; //!< bool for dynamic range handling - bool mFirstStaticGateway; //!< bool for dynamic range handling - bool mFirstStaticConverter; //!< bool for dynamic range handling - bool mFirstStaticSinkClass; //!< bool for dynamic range handling - bool mFirstStaticSourceClass; //!< bool for dynamic range handling - bool mFirstStaticCrossfader; //!< bool for dynamic range handling - -public: - CAmDatabaseHandlerMap(); - virtual ~CAmDatabaseHandlerMap(); - 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 enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID); - 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 removeConverterDB(const am_converterID_t converterID); - 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 getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) 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 getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) 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_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; - am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) 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 getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) 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 getListConverters(std::vector & listConverters) 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 getDomainOfCrossfader(const am_converterID_t crossfader, 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 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); - am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); - am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); - am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations); - am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations); - am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); - am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); - am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); - am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); - am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration); - am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration); - - bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const; - bool existCrossFader(const am_crossfaderID_t crossfaderID) const; - bool existConnection(const am_Connection_s & connection) const; - bool existConnectionID(const am_connectionID_t connectionID) const; - bool existSource(const am_sourceID_t sourceID) const; - bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const; - bool existSourceName(const std::string& name) const; - bool existSink(const am_sinkID_t sinkID) const; - bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const; - bool existSinkName(const std::string& name) const; - bool existDomain(const am_domainID_t domainID) const; - bool existGateway(const am_gatewayID_t gatewayID) const; - bool existConverter(const am_converterID_t converterID) const; - bool existSinkClass(const am_sinkClass_t sinkClassID) const; - bool existSourceClass(const am_sourceClass_t sourceClassID) const; - void registerObserver(CAmDatabaseObserver *iObserver); - bool sourceVisible(const am_sourceID_t sourceID) const; - bool sinkVisible(const am_sinkID_t sinkID) const; - bool isComponentConnected(const am_Gateway_s & gateway) const; - bool isComponentConnected(const am_Converter_s & converter) const; - void dump( std::ostream & output ) const; - am_Error_e enumerateSources(std::function cb) const; - am_Error_e enumerateSinks(std::function cb) const; - am_Error_e enumerateGateways(std::function cb) const; - am_Error_e enumerateConverters(std::function cb) const; - /** - * The following structures extend the base structures with the field 'reserved'. - */ - -#define AM_SUBCLASS_BEGIN(Subclass, Class) \ - typedef struct Subclass : public Class\ - { - -#define AM_SUBCLASS_CONSTR(Subclass, Class) \ - Subclass():Class() - -#define AM_SUBCLASS_CONSTR_BODY()\ - {}; - -#define AM_SUBCLASS_COPY_OP_START(Subclass, Class) \ - Subclass & operator=(const Subclass & anObject)\ - {\ - if (this != &anObject)\ - {\ - Class::operator=(anObject); - -#define AM_SUBCLASS_COPY_OP_END()\ - }\ - return *this;\ - }; - -#define AM_SUBCLASS_OP(Subclass, Class) \ - Subclass & operator=(const Class & anObject)\ - {\ - if (this != &anObject)\ - Class::operator=(anObject);\ - return *this;\ - }; - -#define AM_SUBCLASS_END(Typedef) \ - void getDescription (std::string & outString) const;\ - } Typedef; - -#define AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(Subclass, Class)\ - AM_SUBCLASS_BEGIN(Subclass, Class)\ - bool reserved;\ - AM_SUBCLASS_CONSTR(Subclass, Class)\ - ,reserved(false)\ - AM_SUBCLASS_CONSTR_BODY()\ - AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ - reserved = anObject.reserved;\ - AM_SUBCLASS_COPY_OP_END()\ - AM_SUBCLASS_OP(Subclass, Class)\ - -#define AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(Subclass, Class)\ - AM_SUBCLASS_BEGIN(Subclass, Class)\ - bool reserved;\ - std::unordered_map cacheSoundProperties;\ - std::unordered_map cacheMainSoundProperties;\ - AM_SUBCLASS_CONSTR(Subclass, Class)\ - ,reserved(false), cacheSoundProperties(), cacheMainSoundProperties()\ - AM_SUBCLASS_CONSTR_BODY()\ - AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ - reserved = anObject.reserved;\ - cacheSoundProperties = anObject.cacheSoundProperties;\ - cacheMainSoundProperties = anObject.cacheMainSoundProperties;\ - AM_SUBCLASS_COPY_OP_END()\ - AM_SUBCLASS_OP(Subclass, Class)\ - -#define AM_TYPEDEF_SUBCLASS_BEGIN(Subclass, Class)\ - AM_SUBCLASS_BEGIN(Subclass, Class)\ - AM_SUBCLASS_COPY_OP_START(Subclass, Class)\ - AM_SUBCLASS_COPY_OP_END()\ - AM_SUBCLASS_OP(Subclass, Class)\ - - - AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Domain_Database_s,am_Domain_s) - AM_SUBCLASS_END(CAmDomain) - - AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Sink_Database_s,am_Sink_s) - void getSinkType(am_SinkType_s & sinkType) const;\ - AM_SUBCLASS_END(CAmSink) - - AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Source_Database_s,am_Source_s) - void getSourceType(am_SourceType_s & sourceType) const;\ - AM_SUBCLASS_END(CAmSource) - - AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Connection_Database_s,am_Connection_s) - AM_SUBCLASS_END(CAmConnection) - - /** - * The following structures extend the base structures with print capabilities. - */ - AM_TYPEDEF_SUBCLASS_BEGIN(am_MainConnection_Database_s, am_MainConnection_s) - void getMainConnectionType(am_MainConnectionType_s & connectionType) const;\ - AM_SUBCLASS_END(CAmMainConnection) - - AM_TYPEDEF_SUBCLASS_BEGIN(am_SourceClass_Database_s, am_SourceClass_s) - AM_SUBCLASS_END(CAmSourceClass) - - AM_TYPEDEF_SUBCLASS_BEGIN(am_SinkClass_Database_s, am_SinkClass_s) - AM_SUBCLASS_END(CAmSinkClass) - - AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s) - AM_SUBCLASS_END(CAmGateway) - - AM_TYPEDEF_SUBCLASS_BEGIN(am_Converter_Database_s, am_Converter_s) - AM_SUBCLASS_END(CAmConverter) - - AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s) - AM_SUBCLASS_END(CAmCrossfader) - - private: - typedef std::unordered_map CAmMapDomain; - typedef std::unordered_map CAmMapSourceClass; - typedef std::unordered_map CAmMapSinkClass; - typedef std::unordered_map CAmMapSink; - typedef std::unordered_map CAmMapSource; - typedef std::unordered_map CAmMapGateway; - typedef std::unordered_map CAmMapConverter; - typedef std::unordered_map CAmMapCrossfader; - typedef std::unordered_map CAmMapConnection; - typedef std::unordered_map CAmMapMainConnection; - typedef std::vector CAmVectorSystemProperties; - /** - * The following structure groups the map objects needed for the implementation. - * Every map object is coupled with an identifier, which hold the current value. - * DYNAMIC_ID_BOUNDARY is used as initial value everywhere a dynamic id is considered . - * The IDs can be increased through the method increaseID(...), which follows the AudioManager logic. - * For more information about the static and dynamic IDs, please see the documentation. - */ - typedef struct CAmMappedData - { - /** - * The structure encapsulates the id boundary and the current id value. - * It defines a range within the id can vary. - */ - struct am_Identifier_s - { - int16_t mMin; //!< min possible value - int16_t mMax; //!< max possible value - int16_t mCurrentValue; //!< current value - - am_Identifier_s():mMin(DYNAMIC_ID_BOUNDARY), mMax(SHRT_MAX), mCurrentValue(mMin){}; - am_Identifier_s(const int16_t & min, const int16_t & max):mMin(min), mMax(max), mCurrentValue(mMin){assert(min static void print (const TPrintObject & t, std::ostream & output) - { - std::string description; - t.getDescription( description ); - output << description; - } - template static void printMap (const std::unordered_map & t, std::ostream & output) - { - typename std::unordered_map::const_iterator iter = t.begin(); - for(; iter!=t.end(); iter++) - CAmMappedData::print(iter->second, output); - } - private: - template bool getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, - const std::unordered_map & map); - } CAmMappedData; - /* - * Helper methods. - */ - am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; //!< calculates a new main connection delay - int16_t calculateDelayForRoute(const std::vector& listConnectionID); - bool insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID); - bool insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID); - bool insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID); - bool insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID); - bool insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID); - bool insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID); - bool insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass); - const am_Sink_Database_s * sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const; - const am_Source_Database_s * sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const; - template bool isConnected(const Component & comp) const - { - return std::find_if(mMappedData.mConnectionMap.begin(), mMappedData.mConnectionMap.end(),[&](const std::pair& rConnection){ - return (rConnection.second.sinkID == comp.sinkID ||rConnection.second.sourceID ==comp.sourceID);})!=mMappedData.mConnectionMap.end(); - } - void filterDuplicateNotificationConfigurationTypes(std::vector & list) - { - std::vector oldList(list); - list.clear(); - std::for_each(oldList.begin(), oldList.end(), [&](am_NotificationConfiguration_s & provided) { - std::vector::iterator found = - std::find_if(list.begin(), list.end(), [&](am_NotificationConfiguration_s & stored) { - if (provided.type == stored.type) { - stored = provided; - return true; - } - return false; - } ); - if (found == list.end()) - list.push_back(provided); - } ); - } - - CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer - ListConnectionFormat mListConnectionFormat; //!< list of connection formats - CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class -#ifdef UNIT_TEST - public: - void setConnectionIDRange(const int16_t & min, const int16_t & max) - { - mMappedData.mCurrentConnectionID.mMin = min; - mMappedData.mCurrentConnectionID.mMax = max; - } - void setMainConnectionIDRange(const int16_t & min, const int16_t & max) - { - mMappedData.mCurrentMainConnectionID.mMin = min; - mMappedData.mCurrentMainConnectionID.mMax = max; - } - void setSinkIDRange(const int16_t & min, const int16_t & max) - { - mMappedData.mCurrentSinkID.mMin = min; - mMappedData.mCurrentSinkID.mMax = max; - } -#endif -}; - -} - -#endif /* MAPHANDLER_H_ */ diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h b/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h deleted file mode 100644 index c9005e3..0000000 --- a/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h +++ /dev/null @@ -1,208 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseHandlerSQLite.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASEHANDLER_H_ -#define DATABASEHANDLER_H_ - -#include "IAmDatabaseHandler.h" -#include -#include - -namespace am -{ - -class CAmDatabaseObserver; -class CAmRoutingTree; -class CAmRoutingTreeItem; - -//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 CAmDatabaseHandlerSQLite : public IAmDatabaseHandler -{ -private: - am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; //!< calculates a new main connection delay - - CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer - bool mFirstStaticSink; //!< bool for dynamic range handling - bool mFirstStaticSource; //!< bool for dynamic range handling - bool mFirstStaticGateway; //!< bool for dynamic range handling - bool mFirstStaticConverter; //!< bool for dynamic range handling - bool mFirstStaticSinkClass; //!< bool for dynamic range handling - bool mFirstStaticSourceClass; //!< bool for dynamic range handling - bool mFirstStaticCrossfader; //!< bool for dynamic range handling - ListConnectionFormat mListConnectionFormat; //!< list of connection formats - sqlite3 *mpDatabase; //!< pointer to the database - std::string mPath; //!< path to the database - bool sqQuery(const std::string& query); //!< queries the database - bool openDatabase(); //!< opens the database - void createTables(); //!< creates all tables from the static table -public: - CAmDatabaseHandlerSQLite(); - CAmDatabaseHandlerSQLite(std::string databasePath); - virtual ~CAmDatabaseHandlerSQLite(); - 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 enterConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID); - 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 removeConverterDB(const am_converterID_t converterID); - 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 getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) 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 getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) 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 getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const; - am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const; - am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) 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 getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) 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 getListConverters(std::vector & listConverters) 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 getListConverterConnectionFormats(const am_converterID_t converterID, 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 getDomainOfCrossfader(const am_crossfaderID_t crossfader, 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 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); - am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); - am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties); - am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations); - am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations); - am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); - am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); - am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); - am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix); - am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration); - am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration); - - bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const; - bool existCrossFader(const am_crossfaderID_t crossfaderID) const; - bool existConnection(const am_Connection_s & connection) const; - bool existConnectionID(const am_connectionID_t connectionID) const; - bool existSource(const am_sourceID_t sourceID) const; - bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const; - bool existSourceName(const std::string& name) const; - bool existSink(const am_sinkID_t sinkID) const; - bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const; - bool existSinkName(const std::string& name) const; - bool existDomain(const am_domainID_t domainID) const; - bool existGateway(const am_gatewayID_t gatewayID) const; - bool existConverter(const am_converterID_t converterID) const; - bool existSinkClass(const am_sinkClass_t sinkClassID) const; - bool existSourceClass(const am_sourceClass_t sourceClassID) const; - void registerObserver(CAmDatabaseObserver *iObserver); - bool sourceVisible(const am_sourceID_t sourceID) const; - bool sinkVisible(const am_sinkID_t sinkID) const; - bool isComponentConnected(const am_Gateway_s & gateway) const; - bool isComponentConnected(const am_Converter_s & converter) const; - //todo: Implement dump for SQLite database handler - void dump( std::ostream & output) const { output << __FUNCTION__ << " not implemented!"; }; - am_Error_e enumerateSources(std::function cb) const; - am_Error_e enumerateSinks(std::function cb) const; - am_Error_e enumerateGateways(std::function cb) const; - am_Error_e enumerateConverters(std::function cb) const; -}; - -} - -#endif /* DATABASEHANDLER_H_ */ diff --git a/AudioManagerDaemon/include/CAmDatabaseObserver.h b/AudioManagerDaemon/include/CAmDatabaseObserver.h deleted file mode 100644 index 7d18be4..0000000 --- a/AudioManagerDaemon/include/CAmDatabaseObserver.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseObserver.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASEOBSERVER_H_ -#define DATABASEOBSERVER_H_ - -#include "audiomanagertypes.h" -#include -#include "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 newConverter(const am_Converter_s& coverter); - 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 removeConverter(const am_converterID_t converterID); - 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); - void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible); - void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible); - void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); - void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); - -private: - CAmCommandSender *mCommandSender; //!< pointer to the comandSender - CAmRoutingSender* mRoutingSender; //!< pointer to the routingSender - CAmTelnetServer* mTelnetServer; //!< pointer to the telnetserver - CAmSerializer mSerializer; //!< serializer to handle the CommandInterface via the mainloop -}; - -} - -#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmGraph.h b/AudioManagerDaemon/include/CAmGraph.h deleted file mode 100644 index ff4a09c..0000000 --- a/AudioManagerDaemon/include/CAmGraph.h +++ /dev/null @@ -1,630 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2014 - * - * \file CAmGraph.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef GRAPH_H -#define GRAPH_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace am -{ - /** - * Graph element status. - */ - typedef enum:uint8_t - { - GES_NOT_VISITED, - GES_IN_PROGRESS, - GES_VISITED - }am_GraphElementStatus_e; - - /** - * Callback parameter telling on which position in the path we are. - */ - typedef enum:uint8_t - { - GRAPH_PATH_START, //at the beginning of the path - GRAPH_PATH_MIDDLE, //in middle of the path - GRAPH_PATH_END //at the end of the path - }am_GraphPathPosition_e; - - - /** - * This class is base class for nodes and vertices. - */ - class CAmGraphElement - { - am_GraphElementStatus_e mStatus; //!< item status - public: - CAmGraphElement(): mStatus(GES_NOT_VISITED) { }; - ~CAmGraphElement() { }; - /** - * Setter and getter. - */ - void setStatus(const am_GraphElementStatus_e s) { mStatus = s; }; - am_GraphElementStatus_e getStatus() const { return mStatus; }; - }; - - template class CAmNode : public CAmGraphElement - { - uint16_t mIndex; //!< uint16_t index used for direct access - NodeData mData; //!< NodeData user data - public: - CAmNode(const NodeData & in):CAmGraphElement(), mIndex(0), mData(in) { }; - CAmNode(const NodeData & in, const uint16_t index):CAmGraphElement(), mIndex(index), mData(in) { }; - ~CAmNode() { }; - /** - * Setters and getters. - */ - NodeData & getData() { return mData; } - uint16_t getIndex() const { return mIndex; } - void setIndex(uint16_t index) { mIndex = index; } - }; - - template class CAmVertex : public CAmGraphElement - { - CAmNode* mpNode; //!< CAmNode* pointer to a node - VertexData mVertexData; //!< VertexData vertex user data - uint16_t mWeight; //!< uint16_t a positive value used in the shortest path algorithms - public: - CAmVertex(CAmNode *aNode, const VertexData & vertexData, const uint16_t weight):CAmGraphElement(), - mpNode(aNode), mVertexData(vertexData), mWeight(weight) { }; - ~CAmVertex() { }; - /** - * Setters and getters. - */ - CAmNode* getNode() const { return mpNode; } - VertexData & getData() { return mVertexData; } - uint16_t getWeight() const { return mWeight; } - void setWeight(const uint16_t weight) { mWeight=weight; } - }; - - /** - * Class representing a directed or undirected graph. It contains nodes and connections. - * T, V are types for custom user data. - */ - template class CAmGraph - { - typedef typename std::vector*> CAmListNodePtrs; - typedef typename std::list> CAmListVertices; - typedef typename std::list>::iterator CAmListVerticesItr; - typedef typename std::list>::const_iterator CAmListVerticesItrConst; - typedef typename std::list CAmNodesAdjList; - typedef typename std::list::iterator CAmNodesAdjListItr; - typedef typename std::list::const_iterator CAmNodesAdjListItrConst; - typedef typename std::list> CAmListNodes; - typedef typename std::list>::iterator CAmListNodesItr; - typedef typename std::list>::const_iterator CAmListNodesItrConst; - typedef typename std::vector*> CAmNodeReferenceList; - typedef typename std::vector CAmVertexReferenceList; - - CAmListNodes mStoreNodes; //!< CAmListNodes list with all nodes - CAmNodesAdjList mStoreAdjList; //!< CAmNodesAdjList adjacency list - CAmNodeReferenceList mPointersNodes; //!< CAmNodeReferenceList vector with pointers to nodes for direct access - CAmVertexReferenceList mPointersAdjList; //!< CAmVertexReferenceList vector with pointers to vertices for direct access - bool mIsCyclic; //!< bool the graph has cycles or not - - /** - * Updates the node indexes after adding or removing nodes. - * - * @param fromIndex updates all nodes from given index. - */ - void updateIndexes(const int16_t fromIndex) - { - if( fromIndexsetIndex(iter-mPointersNodes.begin()); - } - } - - - /** - * Finds the shortest path and the minimal weights from given node. - * - * @param node start node. - * @param minDistance vector with all result distances. - * @param previous vector with previous nodes. - */ - - typedef uint16_t vertex_t; - typedef uint16_t weight_t; - - void findShortestsPathsFromNode(const CAmNode & node, std::vector &minDistance, std::vector *> &previous) - { - typename CAmListVertices::const_iterator nIter; - CAmListVertices * neighbors; - weight_t dist, weight, v, distanceThroughU; - CAmNode* pU; - CAmVertex * pVertex; - CAmNode *pDstNode; - - size_t n = mPointersAdjList.size(); - std::set*> > vertexQueue; - - minDistance.clear(); - minDistance.resize(n, std::numeric_limits::max()); - minDistance[node.getIndex()] = 0; - previous.clear(); - previous.resize(n, NULL); - - vertexQueue.insert(std::make_pair(minDistance[node.getIndex()], (CAmNode*)&node)); - - while (!vertexQueue.empty()) - { - dist = vertexQueue.begin()->first; - pU = vertexQueue.begin()->second; - vertexQueue.erase(vertexQueue.begin()); - //todo: terminate the search at this position if you want the path to a target node ( if(pU==target)break; ) - - // Visit each edge exiting u - neighbors = mPointersAdjList[pU->getIndex()]; - nIter = neighbors->begin(); - for (; nIter != neighbors->end(); nIter++) - { - pVertex = (CAmVertex *)&(*nIter); - pDstNode = pVertex->getNode(); - - v = pDstNode->getIndex(); - weight = pVertex->getWeight(); - distanceThroughU = dist + weight; - if (distanceThroughU < minDistance[pDstNode->getIndex()]) - { - vertexQueue.erase(std::make_pair(minDistance[v], pDstNode)); - minDistance[v] = distanceThroughU; - previous[v] = pU; - vertexQueue.insert(std::make_pair(minDistance[v], pDstNode)); - } - } - } - } - - /** - * Constructs a path to given node after findShortestsPathsFromNode has been called. - * - * @param node end node. - * @param previous vector with previous nodes. - * @param result result path. - */ - void constructShortestPathTo(const CAmNode & node, const std::vector *> &previous, CAmListNodePtrs & result) - { - CAmNode * vertex = (CAmNode *)&node; - - int i=0; - while ( (vertex = previous[vertex->getIndex()])!=NULL ) - { - result.insert(result.begin(), vertex); - i++; - } - if(i) - result.push_back((CAmNode *)&node); - } - - /** - * Calls a function with every node from this path after findShortestsPathsFromNode has been called. - * The construction of the path is delegated to the caller. - * - * @param node end node. - * @param previous vector with previous nodes. - * @param cb callback which is mostly used for constructing. - */ - void constructShortestPathTo(const CAmNode & node, const std::vector *> &previous, std::function &)> cb) - { - CAmNode * vertex = (CAmNode *)&node; - CAmNode * prev = vertex; - int i=0; - while ( (vertex = previous[vertex->getIndex()])!=NULL ) - { - cb(i==0?GRAPH_PATH_START:GRAPH_PATH_MIDDLE, *prev); - prev = vertex; - i++; - } - if(i) - cb(GRAPH_PATH_END, *prev); - } - - /** - * Generates list with all possible paths to given destination node after findShortestsPathsFromNode has been called. - * Finding paths is observed through the callback. The caller is informed after a new path has been found. - * - * @param dst end node. - * @param visited vector with current path. - * @param cb callback which is mostly used for constructing. - */ - void goThroughAllPaths(const CAmNode & dst, std::vector*> & visited, std::function cb) - { - CAmListVertices * nodes = mPointersAdjList[visited.back()->getIndex()]; - CAmListVerticesItrConst vItr(nodes->begin()); - for (; vItr != nodes->end(); ++vItr) - { - const CAmVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED) - continue; - if (vertex.getNode()==&dst) - { - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - //notify observer - cb(visited); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - vertex.getNode()->setStatus(GES_NOT_VISITED); - break; - } - } - vItr = nodes->begin(); - //bfs like loop - for (; vItr != nodes->end(); ++vItr) - { - const CAmVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED||vertex.getNode()==&dst) - continue; - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - goThroughAllPaths(dst, visited, cb); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - vertex.getNode()->setStatus(GES_NOT_VISITED); - } - } - - public: - explicit CAmGraph(const std::vector &v):mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList() - { - typedef typename std::vector::const_iterator inItr; - inItr itr(v.begin()); - - for (; itr != v.end(); ++itr) - { - addNode(*itr); - } - - mIsCyclic = false; - }; - CAmGraph():mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList(), mIsCyclic(false){}; - ~CAmGraph(){} - - const CAmListNodes & getNodes() const - { - return mStoreNodes; - } - - const CAmVertexReferenceList & getVertexList() const - { - return mPointersAdjList; - } - - /** - * Returns pointer to a node which data is equal to the given. - * @return pointer to a node or NULL. - */ - const CAmNode* findNode(const T & in) - { - typename CAmNodeReferenceList::const_iterator itr (mPointersNodes.begin()); - - for (; itr != mPointersNodes.end(); ++itr) - { - if ((*itr)->getData() == in) { - return (*itr); - } - } - return NULL; - } - - /** - * Returns pointer to a vertex which two ends are equal to the given nodes. - * @return pointer to a vertex or NULL. - */ - const CAmVertex* findVertex(const CAmNode & edge1, const CAmNode & edge2) const - { - const CAmNode * pEdge2 = (CAmNode *)&edge2; - const CAmListVertices * list = mPointersAdjList[edge1.getIndex()]; - CAmListVerticesItrConst result = std::find_if(list->begin(), list->end(), [&](const CAmVertex & refObject){ - return refObject.getNode()==pEdge2; - }); - if(result!=list->end()) - return (CAmVertex*)&(*result); - - return NULL; - } - - bool hasCycles() const - { - return mIsCyclic; - } - - - /** - * Adds a new node to the graph with given user data. - * @return reference to the newly inserted node. - */ - CAmNode & addNode(const T & in) - { - size_t index = mStoreNodes.size(); - mStoreNodes.emplace_back(in, index); - mStoreAdjList.emplace_back(); - mPointersNodes.push_back(&mStoreNodes.back()); - mPointersAdjList.push_back(&mStoreAdjList.back()); - return mStoreNodes.back(); - } - - /** - * Removes a vertex with two ends equal to the given nodes . - */ - void removeVertex(const CAmNode & edge1, const CAmNode & edge2) - { - const CAmListVertices * list = mPointersAdjList[edge1.getIndex()]; - CAmListVerticesItr iter = std::find_if(list->begin(), list->end(), [&edge2](const CAmVertex & refVertex){ - return (refVertex.getNode()==&edge2); - }); - if(iter!=list->end()) - list->erase(iter); - } - - /** - * Removes all vertices to given node . - */ - void removeAllVerticesToNode(const CAmNode & node) - { - auto comparator = [&node](const CAmVertex & refVertex){ - return (refVertex.getNode()==&node); - }; - auto itr = mPointersAdjList.begin(); - for(;itr!=mPointersAdjList.end();itr++) - { - CAmListVertices * vertices = *itr; - auto iterVert = std::find_if(vertices->begin(), vertices->end(), comparator); - if(iterVert!=vertices->end()) - vertices->erase(iterVert); - } - } - - /** - * Removes a node with given user data . - */ - void removeNode(const T & in) - { - CAmNode * node = findNode(in); - if(node!=NULL) - removeNode(*node); - } - - /** - * Removes the given node from the graph . - */ - void removeNode(const CAmNode & node) - { - uint16_t index = node.getIndex(); - removeAllVerticesToNode(node); - mPointersAdjList.erase(mPointersAdjList.begin()+index); - mPointersNodes.erase(mPointersNodes.begin()+index); - auto iter = std::find_if(mStoreNodes.begin(), mStoreNodes.end(), [&node](const CAmNode & otherNode){ - return &otherNode==&node; - }); - if(iter!=mStoreNodes.end()) - mStoreNodes.erase(iter); - updateIndexes(index); - } - - /** - * Connect first with last node and set user data and weight to the vertex. - */ - void connectNodes(const CAmNode & first, const CAmNode & last, const V & vertexData, const int16_t weight = 1) - { - CAmListVertices * list = mPointersAdjList[first.getIndex()]; - CAmNode * node = mPointersNodes[last.getIndex()]; - list->emplace_back(node, vertexData, weight); - } - - /** - * Exists any vertex with two given ends. - * @return TRUE on successfully changed ID. - */ - bool isAnyVertex(const CAmNode & edge1, const CAmNode & edge2) const - { - return findVertex(edge1, edge2)!=NULL; - } - - /** - * Sets the status of all nodes and vertices to GES_NOT_VISITED. - */ - void reset() - { - // set all nodes to GES_NOT_VISITED - std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [](CAmNode * refNode){ - if(refNode->getStatus()!= GES_NOT_VISITED) - refNode->setStatus(GES_NOT_VISITED); - }); - // set all vertices to GES_NOT_VISITED - auto action = [](CAmVertex & refVertex){ - if(refVertex.getStatus()!= GES_NOT_VISITED) - refVertex.setStatus(GES_NOT_VISITED); - }; - auto itr1(mPointersAdjList.begin()); - for (; itr1 != mPointersAdjList.end(); ++itr1) - { - CAmListVertices * vertices = *itr1; - std::for_each(vertices->begin(), vertices->end(), action); - } - } - - /** - * Clears all nodes and vertices. - */ - void clear() - { - mStoreNodes.clear(); - mStoreAdjList.clear(); - mPointersAdjList.clear(); - mPointersNodes.clear(); - mPointersAdjList.clear(); - } - - /** - * Goes through all nodes and vertices and calls the callback. - */ - void trace(std::function &, const std::vector*> &)> cb) - { - std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [&](CAmNode * refNode){ - CAmListVertices * vertices = this->mPointersAdjList[refNode->getIndex()]; - std::vector*> list; - std::for_each(vertices->begin(), vertices->end(), [&list](CAmVertex & refVertex){ - list.push_back(&refVertex); - }); - cb(*refNode, list); - }); - } - - /** - * Finds the shortest path from given node to all nodes in listTargets. - * - * @param source start node. - * @param listTargets destination nodes. - * @param resultPath list with all shortest paths. - */ - void getShortestPath(const CAmNode & source, const CAmListNodePtrs & listTargets, std::vector & resultPath ) - { - const size_t numberOfNodes = mPointersNodes.size(); - if(numberOfNodes==0) - return; - - std::vector min_distance; - std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); - - for(auto it=listTargets.begin(); it!=listTargets.end(); it++) - { - CAmNode *node = *it; - resultPath.emplace_back(); - CAmListNodePtrs & path = resultPath.back(); - constructShortestPathTo(*node, previous, path); - if(path.empty()) - { - typename std::vector::iterator iter = resultPath.end(); - resultPath.erase(--iter); - } - } - } - - /** - * Finds the shortest path between two nodes. - * - * @param source start node. - * @param destination destination node. - * @param resultPath list with the found shortest paths. - */ - void getShortestPath(const CAmNode & source, const CAmNode & destination, CAmListNodePtrs & resultPath ) - { - const size_t numberOfNodes = mPointersNodes.size(); - if(numberOfNodes==0) - return; - std::vector min_distance; - std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); - constructShortestPathTo(destination, previous, resultPath); - } - - /** - * Finds the shortest path from given node to all nodes in listTargets. - * Delegates the construction of the path to the caller. - * - * @param source start node. - * @param listTargets destination nodes. - * @param cb callabck. - */ - void getShortestPath(const CAmNode & source, - const CAmListNodePtrs & listTargets, - std::function &)> cb ) - { - const size_t numberOfNodes = mPointersNodes.size(); - if(numberOfNodes==0) - return; - - std::vector min_distance; - std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); - - for(auto it=listTargets.begin(); it!=listTargets.end(); it++) - { - CAmNode* node = *it; - constructShortestPathTo(*node, previous, cb); - } - } - - /** - * Finds the shortest path between two given nodes. - * Delegates the construction of the path to the caller. - * - * @param source start node. - * @param destination destination node. - * @param cb callabck. - */ - void getShortestPath(const CAmNode & source, - const CAmNode & destination, - std::function &)> cb ) - { - const size_t numberOfNodes = mPointersNodes.size(); - if(numberOfNodes==0) - return; - - std::vector min_distance; - std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); - constructShortestPathTo(destination, previous, cb); - } - - /** - * Finds all possible paths between two given nodes. - * Delegates the construction of the path to the caller. - * - * @param src start node. - * @param dst destination node. - * @param cb callabck. - */ - void getAllPaths(const CAmNode & src, const CAmNode & dst, std::function cb) - { - CAmNodeReferenceList visited; - visited.push_back((CAmNode*)&src); - ((CAmNode*)&src)->setStatus(GES_VISITED); - goThroughAllPaths(dst, visited, cb); - reset(); - } - }; - -} - -#endif diff --git a/AudioManagerDaemon/include/CAmLog.h b/AudioManagerDaemon/include/CAmLog.h deleted file mode 100644 index 35c6a41..0000000 --- a/AudioManagerDaemon/include/CAmLog.h +++ /dev/null @@ -1,129 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file CAmLog.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CAMLOG_H_ -#define CAMLOG_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * Implements a basic logging mechanism that can be used to print debug information into a file or to the console. - * It can be used either as singleton through the appropriate method getDefaultLog() or as independent instantiated object. - * The default initializer sets the console as output for newly created objects. - * Example: CAmLogger << "Text"; //to print out through the singleton object directly to the console - */ - -#define DEFAULT_LOG_FOLDER "/tmp/" -#define DEFAULT_LOGFILE_PREFIX "am_dump_" -#define DEFAULT_LOGFILE_EXT ".log" - -#define DEL( aPointer ) delete aPointer, aPointer = NULL; - -/* */ -typedef enum { eCAmLogNone = 0, eCAmLogStdout = 1, eCAmLogFile = 2 } eCAmLogType; - -class CAmLog -{ -private: - /** - * Private classes which usually own (wrap) a stream object. They are responsible for creating and deleting it. - */ - class CAmLogger - { - protected: - std::ostream* mOutputStream; - public: - CAmLogger ():mOutputStream(NULL) {}; - virtual ~CAmLogger () { }; - virtual void log(const std::string& _s) - { - (*mOutputStream) << _s; - mOutputStream->flush(); - } - template - CAmLogger & operator << (const T & t) - { - (*mOutputStream) << t; - return (*this); - } - }; - - class CAmFileLogger : public CAmLogger - { - std::string mFilename; - public: - static void generateLogFilename(std::string &result); - explicit CAmFileLogger(const std::string& _s) : CAmLogger() - { - mFilename = _s; - mOutputStream = new std::ofstream(mFilename.c_str()); - } - ~CAmFileLogger(); - }; - - class CAmStdOutLogger : public CAmLogger - { - public: - CAmStdOutLogger() - { - mOutputStream = &std::cout; - } - }; - -private: - eCAmLogType mLogType; - CAmLogger* mLogger; - -protected: - void releaseLogger(); - void instantiateLogger( const eCAmLogType type); -public: - CAmLog(const eCAmLogType type ); - CAmLog(); - ~CAmLog(); - - static CAmLog *getDefaultLog(); - - void setLogType( const eCAmLogType type); - eCAmLogType getLogType() const; - - template - CAmLog & operator << (const T & t) - { - assert(mLogger!=NULL); - (*mLogger) << t; - return (*this); - } - }; - -#define CAmLogger (*CAmLog::getDefaultLog()) - - -#endif /* CAMLOG_H_ */ diff --git a/AudioManagerDaemon/include/CAmRouter.h b/AudioManagerDaemon/include/CAmRouter.h deleted file mode 100644 index fe41049..0000000 --- a/AudioManagerDaemon/include/CAmRouter.h +++ /dev/null @@ -1,317 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014 - * - * \file CAmRouter.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef ROUTER_H_ -#define ROUTER_H_ - -#include -#include -#include -#include "audiomanagertypes.h" -#include "CAmGraph.h" -#include "IAmDatabaseHandler.h" - - -namespace am -{ -/** - * Optimal path search between a source and a sink is implemented with a graph which contains nodes - sinks, sources, gateways, converters. - * The nodes are identified by sinkID, sourceID, gatewayID, converterID. - * A possible connection between two nodes represents the facts that the nodes can be connected with one or more connectionFormats (Node[id=1] ---> Node[id=2]). - * It is assumption that the two nodes can be connected. The controller itself decides later whether the connection is possible or not. - * - */ - -/** - * Trace on/off. - */ -#if !defined(ROUTING_BUILD_CONNECTIONS) - #undef TRACE_GRAPH -#endif - -/** - * Default behavior is to do the search in one step without connections, which are identified during the search. - * Alternatively the search can be done in two steps. - */ -#if !defined(ROUTING_BUILD_CONNECTIONS) - #undef ROUTING_BUILD_CONNECTIONS -#endif - -#if defined(TRACE_GRAPH) -#if !defined(ROUTING_BUILD_CONNECTIONS) -#warning "You should define ROUTING_BUILD_CONNECTIONS in order to be able to see the connections in the trace." -#endif -#endif - -class CAmRouter; - -/** - * A structure used as user data in the graph nodes. - */ -struct am_RoutingNodeData_s -{ - typedef enum:uint8_t {SINK, SOURCE, GATEWAY, CONVERTER} am_NodeDataType_e; - am_NodeDataType_e type; //!< data type:sink, source, gateway or converter - union - { - am_Source_s *source; - am_Sink_s *sink; - am_Gateway_s *gateway; - am_Converter_s *converter; - } data; //!< union pointer to sink, source, gateway or converter - - am_RoutingNodeData_s():type(SINK) - {} - - bool operator==(const am_RoutingNodeData_s & anotherObject) const - { - bool result = false; - if(type==anotherObject.type) - { - result = true; - if(type==SINK) - result &= (data.sink->sinkID==anotherObject.data.sink->sinkID); - else if(type==SOURCE) - result &= (data.source->sourceID==anotherObject.data.source->sourceID); - else if(type==GATEWAY) - result &= (data.gateway->gatewayID==anotherObject.data.gateway->gatewayID); - else if(type==CONVERTER) - result &= (data.converter->converterID==anotherObject.data.converter->converterID); - } - return result; - }; - -#ifdef TRACE_GRAPH - void trace() const - { - if(type==SINK) - std::cout << "[SINK:" << data.sink->sinkID << ":" << data.sink->name << "(" << data.sink->domainID << ")" - << "]"; - else if(type==SOURCE) - std::cout << "[SOUR:" << data.source->sourceID << ":" << data.source->name << "(" << data.source->domainID << ")" - << "]"; - else if(type==GATEWAY) - std::cout << "[GATE:" << data.gateway->gatewayID << ":" << data.gateway->name << "(" << data.gateway->controlDomainID << ")" - << "]"; - else if(type==CONVERTER) - std::cout << "[CONV:" << data.converter->converterID << ":" << data.converter->name << "(" << data.converter->domainID << ")" - << "]"; - }; -#endif - - am_domainID_t domainID() const - { - if(type==SINK) - return data.sink->domainID; - else if(type==SOURCE) - return data.source->domainID; - else if(type==GATEWAY) - return data.gateway->controlDomainID; - else if(type==CONVERTER) - return data.converter->domainID; - return 0; - }; -}; - -typedef am_RoutingNodeData_s::am_NodeDataType_e CAmNodeDataType; -typedef CAmNode CAmRoutingNode; -typedef CAmGraph CAmRoutingGraph; -typedef CAmVertex CAmRoutingVertex; -typedef std::list CAmRoutingListVertices; -typedef std::vector CAmRoutingVertexReferenceList; - -class CAmControlSender; - - -/** - * Implements an autorouting algorithm for connecting sinks and sources via different audio domains. - */ -class CAmRouter -{ - IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler - CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route - bool mOnlyFreeConversionNodes; //!< bool flag whether only disconnected elements should be considered or not - CAmRoutingGraph mRoutingGraph; //!< graph object - std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access - std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access - std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access - std::map> mNodeListConverters;//!< map with pointers to nodes with converters, used for quick access - - am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes); - am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & route, - std::vector::iterator routingElementIterator, - std::vector::iterator routeIterator); - - - /** - * Check whether given converter or gateway has been connected. - * - * @param comp converter or gateway . - */ - template bool isComponentConnected(const Component & comp) - { - return mpDatabaseHandler->isComponentConnected(comp); - } - void generateAllPaths(const CAmRoutingNode & src, - const CAmRoutingNode & dst, - const bool includeCycles, - std::function & path)> cb); - void goThroughAllPaths(const CAmRoutingNode & dst, - std::vector & visited, - std::vector & visitedDomains, - std::function & path)> cb); - -#ifdef ROUTING_BUILD_CONNECTIONS - /** - * Connects all converters to its sink and sources if possible. - * - */ - void constructConverterConnections(); - - /** - * Connects all gateways to its sink and sources if possible. - * - */ - void constructGatewayConnections(); - - /** - * Connects all sources to the sinks if possible. - * - */ - void constructSourceSinkConnections(); -#else - /** - * Construct a list with all vertices - */ - void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct a list with all vertices from given source. - */ - void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct a list with all vertices from given sink. - */ - void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct a list with all vertices from given converter. - */ - void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct a list with all vertices from given gateway. - */ - void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list); -#endif - -public: - CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); - ~CAmRouter(); - - /** - * Finds all possible paths between given source and sink. - * - * @param onlyfree only disconnected elements should be included or not. - * @param sourceID starting point. - * @param sinkID ending point. - * @param returnList list with all possible paths - * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. - */ - am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - am_Error_e getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); - - am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, - std::vector & resultPath, std::vector> & resultNodesPath, -#if !defined(ROUTING_BUILD_CONNECTIONS) - __attribute__((unused)) -#endif - const bool includeCycles = false); -#ifdef ROUTING_BUILD_CONNECTIONS - void getShortestPath(const CAmRoutingNode & source, const CAmRoutingNode & destination, std::vector & resultPath); - void getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & resultPath, std::vector & resultNodesPath); -#endif - - static bool getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - std::vector & sourceFormats, - std::vector & sinkFormats); - static void listPossibleConnectionFormats(std::vector & inListSourceFormats, - std::vector & inListSinkFormats, - std::vector & outListFormats); - static bool getRestrictedOutputFormats(const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - const am_CustomConnectionFormat_t connectionFormat, - std::vector & listFormats); - static void getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, - std::vector::iterator iteratorSink, - std::vector & outConnectionFormats); - - static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); - - /** - * Returns a sink node with given sinkID. - * - * @param sinkID sink id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID); - CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID); - - /** - * Returns a source node with given sourceID. - * - * @param sourceID source id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID); - CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID); - - /** - * Returns a converter node for given sinkID. - * - * @param sinkID sink id. - * @param domainID domain id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID); - - /** - * Returns a gateway node for given sinkID. - * - * @param sinkID sink id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* gatewayNodeWithSinkID(const am_sinkID_t sinkID); - - void load(const bool onlyFree); - void clear(); -}; -} /* namespace am */ -#endif /* ROUTER_H_ */ - diff --git a/AudioManagerDaemon/include/CAmRoutingReceiver.h b/AudioManagerDaemon/include/CAmRoutingReceiver.h deleted file mode 100644 index 82626c6..0000000 --- a/AudioManagerDaemon/include/CAmRoutingReceiver.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmRoutingReceiver.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef ROUTINGRECEIVER_H_ -#define ROUTINGRECEIVER_H_ - -#include "IAmRouting.h" - -namespace am -{ - -class CAmSocketHandler; -class CAmDbusWrapper; -class IAmDatabaseHandler; -class CAmRoutingSender; -class CAmControlSender; - -/** - * Implements the Receiving side of the RoutingPlugins. - */ -class CAmRoutingReceiver: public IAmRoutingReceive -{ -public: - CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler); - CAmRoutingReceiver(IAmDatabaseHandler *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 registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID); - am_Error_e deregisterGateway(const am_gatewayID_t gatewayID); - am_Error_e deregisterConverter(const am_converterID_t converterID); - 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, const am_Error_e error); - void confirmRoutingRundown(const uint16_t handle, const am_Error_e error); - am_Error_e updateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) ; - am_Error_e updateConverter(const am_converterID_t converterID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix); - am_Error_e updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - am_Error_e updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) ; - void ackSetVolumes(const am_Handle_s handle, const std::vector& listvolumes, const am_Error_e error) ; - void ackSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; - void ackSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ; - void hookSinkNotificationDataChange(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) ; - void hookSourceNotificationDataChange(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) ; - am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const; - am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const; - am_Error_e getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const; - - 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: - IAmDatabaseHandler *mpDatabaseHandler; //!< pointer to the databaseHandler - CAmRoutingSender *mpRoutingSender; //!< pointer to the routingSender - CAmControlSender *mpControlSender; //!< pointer to the controlSender - CAmSocketHandler *mpSocketHandler; //!< pointer to sockethandler - CAmDbusWrapper *mpDBusWrapper; //!< pointer to dbuswrapper - - std::vector mListStartupHandles; //!< list of handles that wait for a confirm - std::vector mListRundownHandles; //!< list of handles that wait for a confirm - uint16_t handleCount; //!< counts all handles - 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 - - am_Error_e mLastStartupError; - am_Error_e mLastRundownError; - -}; - -} - -#endif /* ROUTINGRECEIVER_H_ */ diff --git a/AudioManagerDaemon/include/CAmRoutingSender.h b/AudioManagerDaemon/include/CAmRoutingSender.h deleted file mode 100644 index 4a23428..0000000 --- a/AudioManagerDaemon/include/CAmRoutingSender.h +++ /dev/null @@ -1,155 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmRoutingSender.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef ROUTINGSENDER_H_ -#define ROUTINGSENDER_H_ - -#include "IAmRouting.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(); - - am_Error_e removeHandle(const am_Handle_s& handle); - am_Error_e addDomainLookup(const am_Domain_s& domainData); - am_Error_e addSourceLookup(const am_Source_s& sourceData); - am_Error_e addSinkLookup(const am_Sink_s& sinkData); - am_Error_e addCrossfaderLookup(const am_Crossfader_s& crossfaderData); - am_Error_e removeDomainLookup(const am_domainID_t domainID); - am_Error_e removeSourceLookup(const am_sourceID_t sourceID); - am_Error_e removeSinkLookup(const am_sinkID_t sinkID); - am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID); - am_Error_e removeConnectionLookup(const am_connectionID_t connectionID); - - 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_CustomConnectionFormat_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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; - am_Error_e asyncSetVolumes(am_Handle_s& handle, const std::vector& listVolumes); - am_Error_e asyncSetSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration); - am_Error_e asyncSetSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration); - am_Error_e resyncConnectionState(const am_domainID_t domainID, std::vector& listOfExistingConnections); - - struct InterfaceNamePairs //!< is used to pair interfaces with busnames - { - IAmRoutingSend* routingInterface; //!< pointer to the routingInterface - std::string busName; //!< the busname - }; - - class am_handleData_c //!< is used to store data related to handles - { - public: - union - { - am_sinkID_t sinkID; - am_sourceID_t sourceID; - am_crossfaderID_t crossfaderID; - am_connectionID_t connectionID; - am_DataType_u volumeID; - }; - - union - { - am_SoundProperty_s soundPropery; - am_SourceState_e sourceState; - am_volume_t volume; - am_HotSink_e hotSink; - std::vector* soundProperties; - std::vector* listVolumes; - am_NotificationConfiguration_s* notificationConfiguration; - }; - - }; - - am_Error_e returnHandleData(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) const; //!< returns the handle data associated with a handle - am_Error_e returnHandleDataAndRemove(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData); //!< returns the handle data associated with a handle and removes the handle - -#ifdef UNIT_TEST //this is needed to test RoutingSender - friend class IAmRoutingBackdoor; -#endif - -private: - struct comparator //!< is needed to sort the handles in the map - { - bool operator()(const am_Handle_s& a, const am_Handle_s& b) const - { - return (a.handle 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 *mpRoutingReceiver; //!< pointer to routing receiver -}; - -} - -#endif /* ROUTINGSENDER_H_ */ diff --git a/AudioManagerDaemon/include/CAmTelnetMenuHelper.h b/AudioManagerDaemon/include/CAmTelnetMenuHelper.h deleted file mode 100644 index 7038cb3..0000000 --- a/AudioManagerDaemon/include/CAmTelnetMenuHelper.h +++ /dev/null @@ -1,204 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetMenuHelper.h - * For further information see http://www.genivi.org/. - * - */ - -// Local header -#ifndef CAMTELNETMENUHELPER_H_ -#define CAMTELNETMENUHELPER_H_ - -// Standard header -#include -#include -#include -#include -#include -#include -#include -#include "audiomanagertypes.h" - -namespace am -{ - -class CAmTelnetServer; -class IAmDatabaseHandler; -class CAmCommandSender; -class CAmRoutingSender; -class CAmControlSender; -class CAmCommandReceiver; -class CAmRoutingReceiver; -class CAmControlReceiver; - -class CAmRouter; -class CAmSocketHandler; - -/** - * helper class for CAmTelnetServer - */ -class CAmTelnetMenuHelper -{ -public: - - enum EMainState - { - eRootState = 0, eListState, eInfoState, eGetState, eSetState - }; - - CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer); - - ~CAmTelnetMenuHelper(); - - void newSocketConnection(int filedescriptor); - - void socketConnectionsClosed(int filedescriptor); - - void enterCmdQueue(std::queue &CmdQueue, int &filedescriptor); - -private: - - void createCommandMaps(); - void sendError(int & filedescriptor, std::string error_string); - void sendTelnetLine(int & filedescriptor, std::stringstream &line); - void sendCurrentCmdPrompt(int &filedescriptor); - - // COMMON commands - static void oneStepBackCommand(std::queue & CmdQueue, int & filedescriptor); - void oneStepBackCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void exitCommand(std::queue & CmdQueue, int & filedescriptor); - void exitCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void helpCommand(std::queue & CmdQueue, int & filedescriptor); - void helpCommandExec(std::queue & CmdQueue, int & filedescriptor); - - // ROOT commands - static void rootGetCommand(std::queue & CmdQueue, int & filedescriptor); - void rootGetCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void rootSetCommand(std::queue & CmdQueue, int & filedescriptor); - void rootSetCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void rootListCommand(std::queue & CmdQueue, int & filedescriptor); - void rootListCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void rootInfoCommand(std::queue & CmdQueue, int & filedescriptor); - void rootInfoCommandExec(std::queue & CmdQueue, int & filedescriptor); - - // LIST commands - static void listConnectionsCommand(std::queue & CmdQueue, int & filedescriptor); - void listConnectionsCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listSourcesCommand(std::queue & CmdQueue, int & filedescriptor); - void listSourcesCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listSinksCommands(std::queue & CmdQueue, int & filedescriptor); - void listSinksCommandsExec(std::queue & CmdQueue, int & filedescriptor); - static void listCrossfaders(std::queue & CmdQueue, int & filedescriptor); - void listCrossfadersExec(std::queue & CmdQueue, int & filedescriptor); - static void listDomainsCommand(std::queue & CmdQueue, int & filedescriptor); - void listDomainsCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listGatewaysCommand(std::queue & CmdQueue, int & filedescriptor); - void listGatewaysCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listPluginsCommand(std::queue & CmdQueue, int & filedescriptor); - void listPluginsCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listMainConnectionsCommand(std::queue & CmdQueue, int & filedescriptor); - void listMainConnectionsCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listMainSourcesCommand(std::queue & CmdQueue, int & filedescriptor); - void listMainSourcesCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void listMainSinksCommand(std::queue & CmdQueue, int & filedescriptor); - void listMainSinksCommandExec(std::queue & CmdQueue, int & filedescriptor); - - // SET commands - static void setRoutingCommand(std::queue & CmdQueue, int & filedescriptor); - void setRoutingCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void setConnection(std::queue & CmdQueue, int & filedescriptor); - void setConnectionExec(std::queue & CmdQueue, int & filedescriptor); - static void setDisconnectConnId(std::queue & CmdQueue, int & filedescriptor); - void setDisconnectConnIdExec(std::queue & CmdQueue, int & filedescriptor); - static void setSourceSoundProperties(std::queue & CmdQueue, int & filedescriptor); - void setSourceSoundPropertiesExec(std::queue & CmdQueue, int & filedescriptor); - static void setSinkSoundProperty(std::queue & CmdQueue, int & filedescriptor); - void setSinkSoundPropertyExec(std::queue & CmdQueue, int & filedescriptor); - static void setSinkVolume(std::queue & CmdQueue, int & filedescriptor); - void setSinkVolumeExec(std::queue & CmdQueue, int & filedescriptor); - static void setVolumeStep(std::queue & CmdQueue, int & filedescriptor); - void setVolumeStepExec(std::queue & CmdQueue, int & filedescriptor); - static void setSinkMuteState(std::queue & CmdQueue, int & filedescriptor); - void setSinkMuteStateExec(std::queue & CmdQueue, int & filedescriptor); - static void setSourceSoundProperty(std::queue & CmdQueue, int & filedescriptor); - void setSourceSoundPropertyExec(std::queue & CmdQueue, int & filedescriptor); - - // GET commands - static void getRoutingCommand(std::queue & CmdQueue, int & filedescriptor); - void getRoutingCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void getSenderversionCommand(std::queue & CmdQueue, int & filedescriptor); - void getSenderversionCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void getReceiverversionCommand(std::queue & CmdQueue, int & filedescriptor); - void getReceiverversionCommandExec(std::queue & CmdQueue, int & filedescriptor); - - // INFO commands - static void infoSystempropertiesCommand(std::queue & CmdQueue, int & filedescriptor); - void infoSystempropertiesCommandExec(std::queue & CmdQueue, int & filedescriptor); - static void infoDumpCommand(std::queue& CmdQueue, int& filedescriptor); - void infoDumpCommandExec(std::queue& CmdQueue, int& filedescriptor); - -private: - - typedef void (*pCommandPrototype)(std::queue& msg, int & filedescriptor); - - struct sCommandPrototypeInfo - { - std::string info; - pCommandPrototype CommandPrototype; - - // default contructor to set NULL - sCommandPrototypeInfo() : - info(""), CommandPrototype(NULL) - { - } - - // a small contructor - sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) : - info(MyInfo), CommandPrototype(MyCommandPrototype) - { - } - }; - - typedef std::map tCommandMap; - std::map mCurrentMainStateMap; //!< int filedescriptor of socket connection; EMainState state of current telnet session - - static CAmTelnetMenuHelper* instance; - CAmTelnetServer *mpTelenetServer; - CAmSocketHandler *mpSocketHandler; - CAmCommandSender *mpCommandSender; - CAmCommandReceiver *mpCommandReceiver; - CAmRoutingSender *mpRoutingSender; - CAmRoutingReceiver *mpRoutingReceiver; - CAmControlSender *mpControlSender; - CAmControlReceiver *mpControlReceiver; - IAmDatabaseHandler *mpDatabasehandler; - CAmRouter *mpRouter; - - tCommandMap mRootCommands; - tCommandMap mListCommands; - tCommandMap mGetCommands; - tCommandMap mSetCommands; - tCommandMap mInfoCommands; - -}; -// class CAmTelnetMenuHelper -}// namespace am - -#endif // CAMTELNETMENUHELPER_H_ diff --git a/AudioManagerDaemon/include/CAmTelnetServer.h b/AudioManagerDaemon/include/CAmTelnetServer.h deleted file mode 100644 index 0e4c510..0000000 --- a/AudioManagerDaemon/include/CAmTelnetServer.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetServer.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef TELNETSERVER_H_ -#define TELNETSERVER_H_ - -#include -#include -#include "CAmSocketHandler.h" -#include "CAmTelnetMenuHelper.h" - -namespace am -{ - -class IAmDatabaseHandler; -class CAmCommandSender; -class CAmRoutingSender; -class CAmControlSender; -class CAmCommandReceiver; -class CAmRoutingReceiver; -class CAmControlReceiver; -class CAmRouter; -class CAmTelnetMenuHelper; - -/** - * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugging purposes. - * For example, launch a telnet session on port 6060: - * \code telnet localhost 6060 \endcode - * more details can be found at the README - */ -class CAmTelnetServer -{ -public: - CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *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* mpInstance; - CAmSocketHandler *mpSocketHandler; - CAmCommandSender *mpCommandSender; - CAmCommandReceiver *mpCommandReceiver; - CAmRoutingSender *mpRoutingSender; - CAmRoutingReceiver *mpRoutingReceiver; - CAmControlSender *mpControlSender; - CAmControlReceiver *mpControlReceiver; - IAmDatabaseHandler *mpDatabasehandler; - CAmRouter *mpRouter; - sh_pollHandle_t mConnecthandle; - std::queue mListMessages; - std::vector mListConnections; - int mConnectFD; - unsigned int mServerPort; - unsigned int mMaxConnections; - CAmTelnetMenuHelper mTelnetMenuHelper; - -}; - -} /* namespace am */ -#endif /* TELNETSERVER_H_ */ diff --git a/AudioManagerDaemon/include/IAmDatabaseHandler.h b/AudioManagerDaemon/include/IAmDatabaseHandler.h deleted file mode 100644 index 30c1aaf..0000000 --- a/AudioManagerDaemon/include/IAmDatabaseHandler.h +++ /dev/null @@ -1,200 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file IAmDatabaseHandler.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASEHANDLERINTERFACE_H_ -#define DATABASEHANDLERINTERFACE_H_ - -#include "audiomanagertypes.h" -#include -#include -#include -#include -#include -#include "audiomanagerconfig.h" - -namespace am -{ - -class CAmDatabaseObserver; -class CAmRoutingTree; -class CAmRoutingTreeItem; - - -//enum { 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 - -typedef std::map > ListConnectionFormat; //!< type for list of connection formats - -/** - * This class handles and abstracts the database - */ - -class IAmDatabaseHandler -{ -public: - IAmDatabaseHandler () {}; - virtual ~IAmDatabaseHandler () {}; - virtual am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID) = 0; - virtual am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID) = 0; - virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) = 0; - virtual am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) = 0; - virtual am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) = 0; - virtual am_Error_e enterConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID) = 0; - virtual am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID) = 0; - virtual am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID) = 0; - virtual am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID) = 0; - virtual am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass) = 0; - virtual am_Error_e enterSystemProperties(const std::vector& listSystemProperties) = 0; - virtual am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) = 0; - virtual am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) = 0; - virtual am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) = 0; - virtual am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID) = 0; - virtual am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) = 0; - virtual am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) = 0; - virtual am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID) = 0; - virtual am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID) = 0; - virtual am_Error_e changeSourceSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sourceID_t sourceID) = 0; - virtual am_Error_e changeSinkSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sinkID_t sinkID) = 0; - virtual am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID) = 0; - virtual am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property) = 0; - virtual am_Error_e changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) = 0; - virtual am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) = 0; - virtual am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) = 0; - virtual am_Error_e changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) = 0; - virtual am_Error_e changeConnectionFinal(const am_connectionID_t connectionID) = 0; - virtual am_Error_e changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) = 0; - virtual am_Error_e changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) = 0; - virtual am_Error_e changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) = 0; - virtual am_Error_e changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) = 0; - virtual am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) = 0; - virtual am_Error_e removeSinkDB(const am_sinkID_t sinkID) = 0; - virtual am_Error_e removeSourceDB(const am_sourceID_t sourceID) = 0; - virtual am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID) = 0; - virtual am_Error_e removeConverterDB(const am_converterID_t converterID) = 0; - virtual am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID) = 0; - virtual am_Error_e removeDomainDB(const am_domainID_t domainID) = 0; - virtual am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID) = 0; - virtual am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID) = 0; - virtual am_Error_e removeConnection(const am_connectionID_t connectionID) = 0; - virtual am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const = 0; - virtual am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const = 0; - virtual am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const = 0; - virtual am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const = 0; - virtual am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const = 0; - virtual am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const = 0; - virtual am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const = 0; - virtual am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const = 0; - virtual am_Error_e getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const = 0; - virtual am_Error_e getSinkVolume(const am_sinkID_t sinkID, am_volume_t& volume) const = 0; - virtual am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const = 0; - virtual am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; - virtual am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; - virtual am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const =0; - virtual am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const =0; - virtual am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; - virtual am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; - virtual am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector& listSinkID) const = 0; - virtual am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector& listSourceID) const = 0; - virtual am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const = 0; - virtual am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector& listGatewaysID) const = 0; - virtual am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) const = 0; - virtual am_Error_e getListMainConnections(std::vector& listMainConnections) const = 0; - virtual am_Error_e getListDomains(std::vector& listDomains) const = 0; - virtual am_Error_e getListConnections(std::vector& listConnections) const = 0; - virtual am_Error_e getListSinks(std::vector& listSinks) const = 0; - virtual am_Error_e getListSources(std::vector& lisSources) const = 0; - virtual am_Error_e getListSourceClasses(std::vector& listSourceClasses) const = 0; - virtual am_Error_e getListCrossfaders(std::vector& listCrossfaders) const = 0; - virtual am_Error_e getListGateways(std::vector& listGateways) const = 0; - virtual am_Error_e getListConverters(std::vector & listConverters) const = 0; - virtual am_Error_e getListSinkClasses(std::vector& listSinkClasses) const = 0; - virtual am_Error_e getListVisibleMainConnections(std::vector& listConnections) const = 0; - virtual am_Error_e getListMainSinks(std::vector& listMainSinks) const = 0; - virtual am_Error_e getListMainSources(std::vector& listMainSources) const = 0; - virtual am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundProperties) const = 0; - virtual am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSourceProperties) const = 0; - virtual am_Error_e getListSystemProperties(std::vector& listSystemProperties) const = 0; - virtual am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const = 0; - virtual am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const = 0; - virtual am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector & listConnectionFormat) const = 0; - virtual am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const = 0; - virtual am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const = 0; - virtual am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const = 0; - virtual am_Error_e getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const = 0; - virtual am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const = 0; - virtual am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const = 0; - virtual am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID) = 0; - virtual am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID) = 0; - virtual am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID) = 0; - virtual am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) = 0; - virtual am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) = 0; - virtual am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) = 0; - virtual am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) = 0; - virtual am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) = 0; - virtual am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) = 0; - virtual am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; - virtual am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; - virtual am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) = 0; - virtual am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) = 0; - virtual am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration) = 0; - virtual am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration) = 0; - - virtual bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const = 0; - virtual bool existCrossFader(const am_crossfaderID_t crossfaderID) const = 0; - virtual bool existConnection(const am_Connection_s & connection) const = 0; - virtual bool existConnectionID(const am_connectionID_t connectionID) const = 0; - virtual bool existSource(const am_sourceID_t sourceID) const = 0; - virtual bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const = 0; - virtual bool existSourceName(const std::string& name) const = 0; - virtual bool existSink(const am_sinkID_t sinkID) const = 0; - virtual bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const = 0; - virtual bool existSinkName(const std::string& name) const = 0; - virtual bool existDomain(const am_domainID_t domainID) const = 0; - virtual bool existGateway(const am_gatewayID_t gatewayID) const = 0; - virtual bool existSinkClass(const am_sinkClass_t sinkClassID) const = 0; - virtual bool existSourceClass(const am_sourceClass_t sourceClassID) const = 0; - virtual void registerObserver(CAmDatabaseObserver *iObserver) = 0; - virtual bool sourceVisible(const am_sourceID_t sourceID) const = 0; - virtual bool sinkVisible(const am_sinkID_t sinkID) const = 0; - virtual bool isComponentConnected(const am_Gateway_s & gateway) const = 0; - virtual bool isComponentConnected(const am_Converter_s & converter) const = 0; - virtual am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const = 0; //!< calculates a new main connection delay - virtual void dump( std::ostream & output) const = 0 ; - virtual am_Error_e enumerateSources(std::function cb) const = 0 ; - virtual am_Error_e enumerateSinks(std::function cb) const = 0 ; - virtual am_Error_e enumerateGateways(std::function cb) const = 0 ; - virtual am_Error_e enumerateConverters(std::function cb) const = 0 ; - -}; - - -} - -#endif /* DATABASEHANDLERINTERFACE_H_ */ diff --git a/AudioManagerDaemon/include/TAmPluginTemplate.h b/AudioManagerDaemon/include/TAmPluginTemplate.h deleted file mode 100644 index f000fbe..0000000 --- a/AudioManagerDaemon/include/TAmPluginTemplate.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file TAmPluginTemplate.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef PLUGINTEMPLATE_H_ -#define PLUGINTEMPLATE_H_ - -#include -#include -#include "CAmDltWrapper.h" - -namespace am -{ - -/** - * * This template tries to load a library and cast to a class - * @param libname the full path to the library to be loaded - * @param libraryHandle the handle to the library that gets returned - * @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/src/CAmCommandReceiver.cpp b/AudioManagerDaemon/src/CAmCommandReceiver.cpp deleted file mode 100644 index d903384..0000000 --- a/AudioManagerDaemon/src/CAmCommandReceiver.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmCommandReceiver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmCommandReceiver.h" -#include -#include -#include "IAmDatabaseHandler.h" -#include "CAmControlSender.h" -#include "CAmDltWrapper.h" -#include "CAmSocketHandler.h" - -namespace am -{ - -CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : - mDatabaseHandler(iDatabaseHandler), // - mControlSender(iControlSender), // - mDBusWrapper(NULL), // - mSocketHandler(iSocketHandler), // - handleCount(0),// - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false), - mLastErrorStartup(E_OK), // - mLastErrorRundown(E_OK) // - -{ - assert(mDatabaseHandler!=NULL); - assert(mSocketHandler!=NULL); - assert(mControlSender!=NULL); -} - -CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : - mDatabaseHandler(iDatabaseHandler), // - mControlSender(iControlSender), // - mDBusWrapper(iDBusWrapper), // - mSocketHandler(iSocketHandler), // - handleCount(0),// - mListStartupHandles(), // - mListRundownHandles(), // - mWaitStartup(false), // - mWaitRundown(false), // - mLastErrorStartup(E_UNKNOWN), // - mLastErrorRundown(E_UNKNOWN) -{ - 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::getVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const -{ - return (mDatabaseHandler->getSinkMainVolume(sinkID, mainVolume)); -} - -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 - dbusConnectionWrapper = NULL; - 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 = CommandVersion; -} - -void CAmCommandReceiver::confirmCommandReady(const uint16_t handle, const am_Error_e error) -{ - if (error !=E_OK) - mLastErrorStartup=error; - mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); - if (mWaitStartup && mListStartupHandles.empty()) - mControlSender->confirmCommandReady(mLastErrorStartup); -} - -void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle, const am_Error_e error) -{ - if (error !=E_OK) - mLastErrorRundown=error; - mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); - if (mWaitRundown && mListRundownHandles.empty()) - mControlSender->confirmCommandRundown(mLastErrorRundown); -} - -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; - mLastErrorStartup=E_OK; -} - -am_Error_e CAmCommandReceiver::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) const -{ - return (mDatabaseHandler->getListMainSinkNotificationConfigurations(sinkID,listMainNotificationConfigurations)); -} - -am_Error_e CAmCommandReceiver::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) const -{ - return (mDatabaseHandler->getListMainSourceNotificationConfigurations(sourceID,listMainNotificationConfigurations)); -} - -am_Error_e CAmCommandReceiver::setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - logInfo("CommandReceiver::setMainSinkNotificationConfiguration got called, sinkID=", sinkID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status); - return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration)); -} - -am_Error_e CAmCommandReceiver::setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - logInfo("CommandReceiver::setMainSourceNotificationConfiguration got called, sourceID=", sourceID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status); - return (mControlSender->hookUserSetMainSourceNotificationConfiguration(sourceID,mainNotificationConfiguration)); -} - -void CAmCommandReceiver::waitOnRundown(bool rundown) -{ - mWaitRundown = rundown; - mLastErrorStartup=E_OK; -} - -} diff --git a/AudioManagerDaemon/src/CAmCommandSender.cpp b/AudioManagerDaemon/src/CAmCommandSender.cpp deleted file mode 100644 index c41c01d..0000000 --- a/AudioManagerDaemon/src/CAmCommandSender.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmCommandSender.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmCommandSender.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "CAmCommandReceiver.h" -#include "TAmPluginTemplate.h" -#include "CAmDltWrapper.h" - -namespace am -{ - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 //!< major interface version. All versions smaller than this will be rejected -#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< minor interface version. All versions smaller than this will be rejected -/** - * 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() -{ - if (listOfPluginDirectories.empty()) - { - logError("CAmCommandSender::CAmCommandSender: List of commandplugins is empty"); - } - - 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; - std::string fullName = *dirIter + "/" + entryName; - - bool regularFile = (entryType == DT_REG || entryType == DT_LNK); - bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); - - // Handle cases where readdir() could not determine the file type - if (entryType == DT_UNKNOWN) { - struct stat buf; - - if (stat(fullName.c_str(), &buf)) { - logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); - continue; - } - - regularFile = S_ISREG(buf.st_mode); - } - - 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"); - dlclose(tempLibHandle); - 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"); - dlclose(tempLibHandle); - 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); - - //create a list of handles - std::vector listStartupHandles; - for (size_t i = 0; i < mListInterfaces.size(); i++) - { - listStartupHandles.push_back(mCommandReceiver->getStartupHandle()); - } - - //set the receiver ready to wait for replies - mCommandReceiver->waitOnStartup(true); - - //now do the calls - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - std::vector::const_iterator handleIter(listStartupHandles.begin()); - for (; iter < iterEnd; ++iter) - { - (*iter)->setCommandReady(*(handleIter++)); - } -} - -void CAmCommandSender::setCommandRundown() -{ - mCommandReceiver->waitOnRundown(false); - //create a list of handles - std::vector listStartupHandles; - for (size_t i = 0; i < mListInterfaces.size(); i++) - { - listStartupHandles.push_back(mCommandReceiver->getRundownHandle()); - } - - //set the receiver ready to wait for replies - mCommandReceiver->waitOnRundown(true); - - //now do the calls - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - std::vector::const_iterator handleIter(listStartupHandles.begin()); - for (; iter < iterEnd; ++iter) - { - (*iter)->setCommandRundown(*(handleIter++)); - } -} - -void CAmCommandSender::getInterfaceVersion(std::string & version) const -{ - version = CommandVersion; -} - -am_Error_e am::CAmCommandSender::getListPlugins(std::vector & interfaces) const -{ - interfaces = mListLibraryNames; - return (E_OK); -} - -void CAmCommandSender::cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties) -{ - CALL_ALL_INTERFACES(cbSinkUpdated(sinkID,sinkClassID,listMainSoundProperties)); -} - -void CAmCommandSender::cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties) -{ - CALL_ALL_INTERFACES(cbSourceUpdated(sourceID,sourceClassID,listMainSoundProperties)); -} - -void CAmCommandSender::cbSinkNotification(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification) -{ - CALL_ALL_INTERFACES(cbSinkNotification(sinkID,notification)); -} - -void CAmCommandSender::cbSourceNotification(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification) -{ - CALL_ALL_INTERFACES(cbSourceNotification(sourceID,notification)); -} - -void CAmCommandSender::cbSinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - CALL_ALL_INTERFACES(cbMainSinkNotificationConfigurationChanged(sinkID,mainNotificationConfiguration)); -} - -void CAmCommandSender::cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - CALL_ALL_INTERFACES(cbMainSourceNotificationConfigurationChanged(sourceID,mainNotificationConfiguration)); -} - -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 deleted file mode 100644 index c1c161e..0000000 --- a/AudioManagerDaemon/src/CAmControlReceiver.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmControlReceiver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmControlReceiver.h" -#include -#include -#include -#include "audiomanagerconfig.h" -#include "IAmDatabaseHandler.h" -#include "CAmRoutingSender.h" -#include "CAmCommandSender.h" -#include "CAmRouter.h" -#include "CAmDltWrapper.h" -#include "CAmSocketHandler.h" - -namespace am { - -CAmControlReceiver::CAmControlReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter) : - mDatabaseHandler(iDatabaseHandler), // - mRoutingSender(iRoutingSender), // - mCommandSender(iCommandSender), // - mSocketHandler(iSocketHandler), // - mRouter(iRouter), // - mNodeStateCommunicator(NULL) -{ - 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_CustomConnectionFormat_t 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; - tempConnection.delay=-1; - - mDatabaseHandler->enterConnectionDB(tempConnection, connectionID); - am_Error_e syncError(mRoutingSender->asyncConnect(handle, connectionID, sourceID, sinkID, format)); - if (syncError) - { - mDatabaseHandler->removeConnection(connectionID); - } - return(syncError); -} - -am_Error_e CAmControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID) -{ - logInfo("CAmControlReceiver::disconnect got called, connectionID=", connectionID); - 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_CustomRampType_t rampType, const am_time_t rampTime) -{ - logInfo("CAmControlReceiver::crossfade got called, hotSource=", hotSource, "crossfaderID=", crossfaderID, "rampType=", rampType, "rampTime=", rampTime); - 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); - 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_CustomRampType_t ramp, const am_time_t time) -{ - logInfo("CAmControlReceiver::setSinkVolume got called, sinkID=", sinkID, "volume=", volume, "ramp=", ramp, "time=", time); - 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_CustomRampType_t rampType, const am_time_t time) -{ - logInfo("CAmControlReceiver::setSourceVolume got called, sourceID=", sourceID, "volume=", volume, "ramp=", rampType, "time=", time); - 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); - 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); - 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); - 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); - 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); - 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::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID) -{ - return (mDatabaseHandler->enterConverterDB(converterData, converterID)); -} - -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->changeMainSourceSoundPropertyDB(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::removeConverterDB(const am_converterID_t converterID) -{ - return (mDatabaseHandler->removeConverterDB(converterID)); -} - -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::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s & converterData) const -{ - return (mDatabaseHandler->getConverterInfoDB(converterID, converterData)); -} - - -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::getListConvertersOfDomain(const am_domainID_t domainID,std::vector& listConverterID) const -{ - return (mDatabaseHandler->getListConvertersOfDomain(domainID,listConverterID)); -} - -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::getListConverters(std::vector& listConverters) const -{ - return (mDatabaseHandler->getListConverters(listConverters)); -} - -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(const am_Error_e error) -{ - if (error!=E_OK) - logError("CAmControlReceiver::confirmControllerReady controller reported error", error); -} - -void CAmControlReceiver::confirmControllerRundown(const am_Error_e error) -{ - if (error!=E_OK) - { - logError("CAmControlReceiver::confirmControllerRundown() exited with error ",error); - //we might be blocked here -> so lets better exit right away - throw std::runtime_error("controller Confirmed with error"); - } - - logInfo ("CAmControlReceiver::confirmControllerRundown(), will exit now"); - - //end the mainloop here... - mSocketHandler->exit_mainloop(); -} - -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 = ControlVersion; -} - -am_Error_e CAmControlReceiver::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - logInfo("CAmControlReceiver::changeSourceDB was called, sourceID", sourceID); - return (mDatabaseHandler->changeSourceDB(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -am_Error_e CAmControlReceiver::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - logInfo("CAmControlReceiver::changeSinkDB was called with sinkID", sinkID); - return (mDatabaseHandler->changeSinkDB(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -am_Error_e CAmControlReceiver::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - logInfo("CAmControlReceiver::changeGatewayDB was called with gatewayID", gatewayID); - return (mDatabaseHandler->changeGatewayDB(gatewayID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix)); -} - -am_Error_e CAmControlReceiver::changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - logInfo("CAmControlReceiver::changeConverterDB was called with converterID", converterID); - return (mDatabaseHandler->changeConverterDB(converterID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix)); -} - -am_Error_e CAmControlReceiver::setVolumes(am_Handle_s& handle, const std::vector& listVolumes) -{ - logInfo("CAmControlReceiver::setVolumes got called"); - return (mRoutingSender->asyncSetVolumes(handle,listVolumes)); -} - -am_Error_e CAmControlReceiver::setSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - logInfo("CAmControlReceiver::setSinkNotificationConfiguration called, sinkID=",sinkID,"notificationConfiguration.type=",notificationConfiguration.type,"notificationConfiguration.status",notificationConfiguration.status,"notificationConfiguration.parameter",notificationConfiguration.parameter); - return (mRoutingSender->asyncSetSinkNotificationConfiguration(handle,sinkID,notificationConfiguration)); -} - -am_Error_e CAmControlReceiver::setSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - logInfo("CAmControlReceiver::setSourceNotificationConfiguration called, sourceID=",sourceID,"notificationConfiguration.type=",notificationConfiguration.type,"notificationConfiguration.status",notificationConfiguration.status,"notificationConfiguration.parameter",notificationConfiguration.parameter); - return (mRoutingSender->asyncSetSourceNotificationConfiguration(handle,sourceID,notificationConfiguration)); -} - -void CAmControlReceiver::sendMainSinkNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s& notificationPayload) -{ - logInfo("CAmControlReceiver::sendSinkMainNotificationPayload called, sinkID=",sinkID,"type=",notificationPayload.type,"value=",notificationPayload.value); - mCommandSender->cbSinkNotification(sinkID,notificationPayload); -} - -void CAmControlReceiver::sendMainSourceNotificationPayload(const am_sourceID_t sourceID, const am_NotificationPayload_s& notificationPayload) -{ - logInfo("CAmControlReceiver::sendSourceMainNotificationPayload called, sourceID=",sourceID,"type=",notificationPayload.type,"value=",notificationPayload.value); - mCommandSender->cbSourceNotification(sourceID,notificationPayload); -} - -am_Error_e CAmControlReceiver::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - logInfo("CAmControlReceiver::changeMainSinkNotificationConfigurationDB was called with sinkID", sinkID); - return (mDatabaseHandler->changeMainSinkNotificationConfigurationDB(sinkID,mainNotificationConfiguration)); -} - -am_Error_e CAmControlReceiver::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration) -{ - logInfo("CAmControlReceiver::changeMainSourceNotificationConfigurationDB was called with sourceID", sourceID); - return (mDatabaseHandler->changeMainSourceNotificationConfigurationDB(sourceID,mainNotificationConfiguration)); -} - -am_Error_e CAmControlReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const -{ - logInfo("CAmControlReceiver::getListMainSinkSoundProperties was called, sinkID", sinkID); - return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID,listSoundproperties)); -} - -am_Error_e CAmControlReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const -{ - logInfo("CAmControlReceiver::getListMainSourceSoundProperties was called, sourceID", sourceID); - return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSoundproperties)); -} - -am_Error_e CAmControlReceiver::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const -{ - logInfo("CAmControlReceiver::getListSinkSoundProperties was called, sinkID", sinkID); - return (mDatabaseHandler->getListSinkSoundProperties(sinkID,listSoundproperties)); -} - -am_Error_e CAmControlReceiver::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const -{ - logInfo("CAmControlReceiver::getListSourceSoundProperties was called, sourceID", sourceID); - return (mDatabaseHandler->getListSourceSoundProperties(sourceID, listSoundproperties)); -} - -am_Error_e CAmControlReceiver::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const -{ - logInfo("CAmControlReceiver::getMainSinkSoundPropertyValue was called, sinkID", sinkID); - return (mDatabaseHandler->getMainSinkSoundPropertyValue(sinkID,propertyType,value)); -} - -am_Error_e CAmControlReceiver::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const -{ - logInfo("CAmControlReceiver::getSinkSoundPropertyValue was called, sinkID", sinkID); - return (mDatabaseHandler->getSinkSoundPropertyValue(sinkID,propertyType,value)); -} - -am_Error_e CAmControlReceiver::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const -{ - logInfo("CAmControlReceiver::getMainSourceSoundPropertyValue was called, sourceID", sourceID); - return (mDatabaseHandler->getMainSourceSoundPropertyValue(sourceID,propertyType,value)); -} - -am_Error_e CAmControlReceiver::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const -{ - logInfo("CAmControlReceiver::getSourceSoundPropertyValue was called, sourceID", sourceID); - return (mDatabaseHandler->getSourceSoundPropertyValue(sourceID,propertyType,value)); -} - -am_Error_e CAmControlReceiver::resyncConnectionState(const am_domainID_t domainID,std::vector& listOfExistingConnections) -{ - logInfo("CAmControlReceiver::resyncConnectionState was called, domainID", domainID); - return (mRoutingSender->resyncConnectionState(domainID,listOfExistingConnections)); -} - -} - diff --git a/AudioManagerDaemon/src/CAmControlSender.cpp b/AudioManagerDaemon/src/CAmControlSender.cpp deleted file mode 100644 index 672c2d5..0000000 --- a/AudioManagerDaemon/src/CAmControlSender.cpp +++ /dev/null @@ -1,513 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmControlSender.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmControlSender.h" -#include -#include -#include -#include -#include -#include "TAmPluginTemplate.h" -#include "CAmDltWrapper.h" - -namespace am -{ - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 //!< major interface version. All versions smaller than this will be rejected -#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< minor interface version. All versions smaller than this will be rejected - -CAmControlSender* CAmControlSender::mInstance=NULL; - -CAmControlSender::CAmControlSender(std::string controlPluginFile,CAmSocketHandler* sockethandler) : - receiverCallbackT(this, &CAmControlSender::receiverCallback),// - checkerCallbackT(this, &CAmControlSender::checkerCallback),// - dispatcherCallbackT(this, &CAmControlSender::dispatcherCallback), // - mPipe(), // - mlibHandle(NULL), // - mController(NULL), // - mSignal(0) -{ - assert(sockethandler); - std::ifstream isfile(controlPluginFile.c_str()); - if (!isfile) - { - logError("ControlSender::ControlSender: Controller plugin not found:", controlPluginFile); - throw std::runtime_error("Could not find controller plugin!"); - } - else if (!controlPluginFile.empty()) - { - mInstance=this; - 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 !"); - } - - //here we need a pipe to be able to call the rundown function out of the mainloop - if (pipe(mPipe) == -1) - { - logError("CAmControlSender could not create pipe!"); - } - - //add the pipe to the poll - nothing needs to be proccessed here we just need the pipe to trigger the ppoll - short event = 0; - sh_pollHandle_t handle; - event |= POLLIN; - sockethandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, handle); -} - -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) -{ - assert(mController); - return (mController->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID)); -} - -am_Error_e CAmControlSender::hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) -{ - assert(mController); - return (mController->hookUserDisconnectionRequest(connectionID)); -} - -am_Error_e CAmControlSender::hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s & soundProperty) -{ - assert(mController); - return (mController->hookUserSetMainSinkSoundProperty(sinkID, soundProperty)); -} - -am_Error_e CAmControlSender::hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s & soundProperty) -{ - assert(mController); - return (mController->hookUserSetMainSourceSoundProperty(sourceID, soundProperty)); -} - -am_Error_e CAmControlSender::hookUserSetSystemProperty(const am_SystemProperty_s & property) -{ - assert(mController); - return (mController->hookUserSetSystemProperty(property)); -} - -am_Error_e CAmControlSender::hookUserVolumeChange(const am_sinkID_t sinkID, const am_mainVolume_t newVolume) -{ - assert(mController); - return (mController->hookUserVolumeChange(sinkID, newVolume)); -} - -am_Error_e CAmControlSender::hookUserVolumeStep(const am_sinkID_t sinkID, const int16_t increment) -{ - assert(mController); - return (mController->hookUserVolumeStep(sinkID, increment)); -} - -am_Error_e CAmControlSender::hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - assert(mController); - return (mController->hookUserSetSinkMuteState(sinkID, muteState)); -} - -am_Error_e CAmControlSender::hookSystemRegisterDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - assert(mController); - return (mController->hookSystemRegisterDomain(domainData, domainID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterDomain(const am_domainID_t domainID) -{ - assert(mController); - return (mController->hookSystemDeregisterDomain(domainID)); -} - -void CAmControlSender::hookSystemDomainRegistrationComplete(const am_domainID_t domainID) -{ - assert(mController); - return (mController->hookSystemDomainRegistrationComplete(domainID)); -} - -am_Error_e CAmControlSender::hookSystemRegisterSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - assert(mController); - return (mController->hookSystemRegisterSink(sinkData, sinkID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterSink(const am_sinkID_t sinkID) -{ - assert(mController); - return (mController->hookSystemDeregisterSink(sinkID)); -} - -am_Error_e CAmControlSender::hookSystemRegisterSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - assert(mController); - return (mController->hookSystemRegisterSource(sourceData, sourceID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterSource(const am_sourceID_t sourceID) -{ - assert(mController); - return (mController->hookSystemDeregisterSource(sourceID)); -} - -am_Error_e CAmControlSender::hookSystemRegisterGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - assert(mController); - return (mController->hookSystemRegisterGateway(gatewayData, gatewayID)); -} - -am_Error_e CAmControlSender::hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID) -{ - assert(mController); - return (mController->hookSystemRegisterConverter(converterData, converterID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) -{ - assert(mController); - return (mController->hookSystemDeregisterGateway(gatewayID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterConverter(const am_converterID_t converterID) -{ - assert(mController); - return (mController->hookSystemDeregisterConverter(converterID)); -} - -am_Error_e CAmControlSender::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - assert(mController); - return (mController->hookSystemRegisterCrossfader(crossfaderData, crossfaderID)); -} - -am_Error_e CAmControlSender::hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) -{ - assert(mController); - return (mController->hookSystemDeregisterCrossfader(crossfaderID)); -} - -void CAmControlSender::hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - assert(mController); - mController->hookSystemSinkVolumeTick(handle, sinkID, volume); -} - -void CAmControlSender::hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - assert(mController); - mController->hookSystemSourceVolumeTick(handle, sourceID, volume); -} - -void CAmControlSender::hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - assert(mController); - mController->hookSystemInterruptStateChange(sourceID, interruptState); -} - -void CAmControlSender::hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - assert(mController); - mController->hookSystemSinkAvailablityStateChange(sinkID, availability); -} - -void CAmControlSender::hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - assert(mController); - mController->hookSystemSourceAvailablityStateChange(sourceID, availability); -} - -void CAmControlSender::hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) -{ - assert(mController); - mController->hookSystemDomainStateChange(domainID, state); -} - -void CAmControlSender::hookSystemReceiveEarlyData(const std::vector & data) -{ - assert(mController); - mController->hookSystemReceiveEarlyData(data); -} - -void CAmControlSender::hookSystemSpeedChange(const am_speed_t speed) -{ - assert(mController); - mController->hookSystemSpeedChange(speed); -} - -void CAmControlSender::hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) -{ - assert(mController); - mController->hookSystemTimingInformationChanged(mainConnectionID, time); -} - -void CAmControlSender::cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) -{ - assert(mController); - mController->cbAckConnect(handle, errorID); -} - -void CAmControlSender::cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) -{ - assert(mController); - mController->cbAckDisconnect(handle, errorID); -} - -void CAmControlSender::cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) -{ - assert(mController); - mController->cbAckCrossFade(handle, hostsink, error); -} - -void CAmControlSender::cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSinkVolumeChange(handle, volume, error); -} - -void CAmControlSender::cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSourceVolumeChange(handle, volume, error); -} - -void CAmControlSender::cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSourceState(handle, error); -} - -void CAmControlSender::cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSourceSoundProperty(handle, error); -} - -am_Error_e CAmControlSender::startupController(IAmControlReceive *controlreceiveinterface) -{ - if (!mController) - { - logError("ControlSender::startupController: no Controller to startup!"); - throw std::runtime_error("ControlSender::startupController: no Controller to startup! Exiting now ..."); - return (E_NON_EXISTENT); - } - return (mController->startupController(controlreceiveinterface)); -} - -void CAmControlSender::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSinkSoundProperty(handle, error); -} - -void CAmControlSender::cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSinkSoundProperties(handle, error); -} - -void CAmControlSender::cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSourceSoundProperties(handle, error); -} - -void CAmControlSender::setControllerReady() -{ - assert(mController); - mController->setControllerReady(); -} - -void CAmControlSender::setControllerRundown(const int16_t signal) -{ - assert(mController); - logInfo("CAmControlSender::setControllerRundown received, signal=",signal); - mController->setControllerRundown(signal); -} - -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) -{ - assert(mController); - return (mController->getConnectionFormatChoice(sourceID, sinkID, listRoute, listPossibleConnectionFormats, listPrioConnectionFormats)); -} - -void CAmControlSender::getInterfaceVersion(std::string & version) const -{ - version = ControlVersion; -} - -void CAmControlSender::confirmCommandReady(const am_Error_e error) -{ - assert(mController); - mController->confirmCommandReady(error); -} - -void CAmControlSender::confirmRoutingReady(const am_Error_e error) -{ - assert(mController); - mController->confirmRoutingReady(error); -} - -void CAmControlSender::confirmCommandRundown(const am_Error_e error) -{ - assert(mController); - mController->confirmCommandRundown(error); -} - -void CAmControlSender::confirmRoutingRundown(const am_Error_e error) -{ - assert(mController); - mController->confirmRoutingRundown(error); -} - -am_Error_e CAmControlSender::hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(mController); - return (mController->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -am_Error_e CAmControlSender::hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(mController); - return (mController->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -am_Error_e CAmControlSender::hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) -{ - assert(mController); - return (mController->hookSystemUpdateGateway(gatewayID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix)); -} - -am_Error_e CAmControlSender::hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFromats, const std::vector& convertionMatrix) -{ - assert(mController); - return (mController->hookSystemUpdateConverter(converterID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix)); -} - -void CAmControlSender::cbAckSetVolume(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetVolumes(handle,listVolumes,error); -} - -void CAmControlSender::cbAckSetSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSinkNotificationConfiguration(handle,error); -} - -void CAmControlSender::cbAckSetSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) -{ - assert(mController); - mController->cbAckSetSourceNotificationConfiguration(handle,error); -} - -void CAmControlSender::hookSinkNotificationDataChanged(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) -{ - assert(mController); - mController->hookSinkNotificationDataChanged(sinkID,payload); -} - -void CAmControlSender::hookSourceNotificationDataChanged(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) -{ - assert(mController); - mController->hookSourceNotificationDataChanged(sourceID,payload); -} - -am_Error_e CAmControlSender::hookUserSetMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - assert(mController); - return (mController->hookUserSetMainSinkNotificationConfiguration(sinkID,notificationConfiguration)); -} - -am_Error_e CAmControlSender::hookUserSetMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - assert(mController); - return (mController->hookUserSetMainSourceNotificationConfiguration(sourceID,notificationConfiguration)); -} - -void CAmControlSender::receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) -{ - (void) handle; - (void) userData; - //get the signal number from the socket - ssize_t result = read(pollfd.fd, &mSignal, sizeof(mSignal)); -} - -bool CAmControlSender::checkerCallback(const sh_pollHandle_t handle, void* userData) -{ - (void) handle; - (void) userData; - return (true); -} - -void CAmControlSender::hookSystemSingleTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t time) -{ - assert(mController); - mController->hookSystemSingleTimingInformationChanged(connectionID,time); -} - -/**for testing only contructor - do not use ! - * - */ -CAmControlSender::CAmControlSender() : - receiverCallbackT(this, &CAmControlSender::receiverCallback),// - checkerCallbackT(this, &CAmControlSender::checkerCallback),// - dispatcherCallbackT(this, &CAmControlSender::dispatcherCallback), // - mPipe(), // - mlibHandle(NULL), // - mController(NULL), // - mSignal(0) -{ - logInfo("CAmControlSender was loaded in test mode!"); -} - -bool CAmControlSender::dispatcherCallback(const sh_pollHandle_t handle, void* userData) -{ - (void)handle; - (void)userData; - setControllerRundown(mSignal); - return (false); -} - -} - - diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp deleted file mode 100644 index 929c8d5..0000000 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp +++ /dev/null @@ -1,3079 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file CAmDatabaseHandlerMap.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "CAmDatabaseHandlerMap.h" -#include "CAmDatabaseObserver.h" -#include "CAmRouter.h" -#include "CAmDltWrapper.h" - - -#ifdef WITH_DATABASE_CHANGE_CHECK -# define DB_COND_UPDATE_RIE(x,y) \ - if (isDataEqual(x,y)) return (E_NO_CHANGE); else x = y -# define DB_COND_UPDATE_INIT \ - bool modified = false -# define DB_COND_UPDATE(x,y) \ - if (!isDataEqual(x,y)) { x = y; modified = true; } -# define DB_COND_ISMODIFIED \ - (modified == true) -#else -# define DB_COND_UPDATE_RIE(x,y) \ - x = y -# define DB_COND_UPDATE_INIT -# define DB_COND_UPDATE(x,y) \ - x = y -# define DB_COND_ISMODIFIED \ - (true) -#endif - - -namespace am -{ - -/* - * Checks if content of data is equal - */ -template bool isDataEqual(const T & left, const T & right) -{ - return static_cast(!std::memcmp(&left, &right, sizeof(T))); -} - -template > bool isDataEqual(const L & left, const L & right) -{ - return std::equal(left.begin(), left.end(), right.begin(), isDataEqual); -} - - -/* - * Returns an object for given key - */ -template TMapObjectType const * objectForKeyIfExistsInMap(const TMapKeyType & key, const std::unordered_map & map) -{ - typename std::unordered_map::const_iterator iter = map.find(key); - if( iter!=map.end() ) - return &iter->second; - return NULL; -} - -/* - * Checks whether any object with key exists in a given map - */ -template bool existsObjectWithKeyInMap(const TMapKeyType & key, const std::unordered_map & map) -{ - return objectForKeyIfExistsInMap(key, map)!=NULL; -} - -/** - * \brief Returns an object matching predicate. - * - * Convenient method for searching in a given map. - * - * @param map Map reference. - * @param comparator Search predicate. - * @return NULL or pointer to the found object. - */ -template const TReturn * objectMatchingPredicate(const std::unordered_map & map, - std::function comparator) -{ - typename std::unordered_map::const_iterator elementIterator = map.begin(); - for (;elementIterator != map.end(); ++elementIterator) - { - if( comparator(elementIterator->second) ) - return &elementIterator->second; - } - return NULL; -} - - -/* Domain */ - -void CAmDatabaseHandlerMap::CAmDomain::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Domain(" << name.c_str() << ") id(" << domainID << ")" << std::endl << - "bus name(" << busname.c_str() << - ") node name(" << nodename.c_str() << - ") early(" << early << - ") domainID(" << domainID << - ") complete(" << complete << - ") state(" << state << - ") reserved(" << reserved << ")" << std::endl; - outString = fmt.str(); -} - -/* Source */ - -void CAmDatabaseHandlerMap::CAmSource::getSourceType(am_SourceType_s & sourceType) const -{ - sourceType.name = name; - sourceType.sourceClassID = sourceClassID; - sourceType.availability = available; - sourceType.sourceID = sourceID; -} - -void CAmDatabaseHandlerMap::CAmSource::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Source(" << name.c_str() << ") id(" << sourceID << ")" << std::endl << - "sourceClassID(" << sourceClassID << - ") domainID(" << domainID << - ") visible(" << visible << - ") volume(" << volume << - ") interruptState(" << interruptState << - ") sourceState(" << sourceState << - ") reserved(" << reserved << ")" << - ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]" - ") listSoundProperties ("; - std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) { - fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; - }); - fmt << ") listConnectionFormats ("; - std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { - fmt << "[" << ref << "]"; - }); - fmt << ") listMainSoundProperties ("; - std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) { - fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; - }); - fmt << ") listMainNotificationConfigurations ("; - std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { - fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; - }); - fmt << ") listNotificationConfigurations ("; - std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { - fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - -/* Sink */ - -void CAmDatabaseHandlerMap::CAmSink::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Sink(" << name.c_str() << ") id(" << sinkID << ")" << std::endl << - "sinkClassID(" << sinkClassID << - ") domainID(" << domainID << - ") visible(" << visible << - ") volume(" << volume << - ") muteState(" << muteState << - ") mainVolume(" << mainVolume << - ") reserved(" << reserved << ")" << - ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]" - ") listSoundProperties ("; - std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) { - fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; - }); - fmt << ") listConnectionFormats ("; - std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { - fmt << "[" << ref << "]"; - }); - fmt << ") listMainSoundProperties ("; - std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) { - fmt << "[type:" << ref.type << " value:" << ref.value <<"]"; - }); - fmt << ") listMainNotificationConfigurations ("; - std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { - fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; - }); - fmt << ") listNotificationConfigurations ("; - std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) { - fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - -void CAmDatabaseHandlerMap::CAmSink::getSinkType(am_SinkType_s & sinkType) const -{ - sinkType.name = name; - sinkType.sinkID = sinkID; - sinkType.availability = available; - sinkType.muteState = muteState; - sinkType.volume = mainVolume; - sinkType.sinkClassID = sinkClassID; -} - -/* Connection */ - -void CAmDatabaseHandlerMap::CAmConnection::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Connection id(" << connectionID << ") " << std::endl << - "sourceID(" << sourceID << - ") sinkID(" << sinkID << - ") delay(" << delay << - ") connectionFormat(" << connectionFormat << - ") reserved(" << reserved << ")" << std::endl; - outString = fmt.str(); -} - -/* Main Connection */ - -void CAmDatabaseHandlerMap::CAmMainConnection::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "MainConnection id(" << mainConnectionID << ") " << std::endl << - "connectionState(" << connectionState << - ") sinkID(" << sinkID << - ") sourceID(" << sourceID << - ") delay(" << delay << - ") listConnectionID ("; - std::for_each(listConnectionID.begin(), listConnectionID.end(), [&](const am_connectionID_t & connID) { - fmt << "["<< connID << "]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - -void CAmDatabaseHandlerMap::am_MainConnection_Database_s::getMainConnectionType(am_MainConnectionType_s & connectionType) const -{ - connectionType.mainConnectionID = mainConnectionID; - connectionType.sourceID = sourceID; - connectionType.sinkID = sinkID; - connectionType.connectionState = connectionState; - connectionType.delay = delay; -} - -/* Source Class */ - -void CAmDatabaseHandlerMap::CAmSourceClass::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Source class(" << name.c_str() << ") id(" << sourceClassID << ")\n" << - ") listClassProperties ("; - std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) { - fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - -/* Sink Class */ - -void CAmDatabaseHandlerMap::CAmSinkClass::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Sink class(" << name.c_str() << ") id(" << sinkClassID << ")\n" << - ") listClassProperties ("; - std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) { - fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - - -/* Gateway */ - -void CAmDatabaseHandlerMap::CAmGateway::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Gateway(" << name.c_str() << ") id(" << gatewayID << ")\n" << - "sinkID(" << sinkID << - ") sourceID(" << sourceID << - ") domainSinkID(" << domainSinkID << - ") domainSourceID(" << domainSourceID << - ") controlDomainID(" << controlDomainID << - ") listSourceFormats ("; - std::for_each(listSourceFormats.begin(), listSourceFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { - fmt << "[" << ref << "]"; - }); - fmt << ") listSinkFormats ("; - std::for_each(listSinkFormats.begin(), listSinkFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { - fmt << "[" << ref << "]"; - }); - fmt << ") convertionMatrix ("; - std::for_each(convertionMatrix.begin(), convertionMatrix.end(), [&](const bool & ref) { - fmt << "[" << ref << "]"; - }); - fmt << ")" << std::endl; - outString = fmt.str(); -} - -/* Crossfader */ - -void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outString) const -{ - std::ostringstream fmt; - fmt << "Crossfader(" << name.c_str() << ") id(" << crossfaderID << ")\n" << - "sinkID_A(" << sinkID_A << - ") sinkID_B(" << sinkID_B << - ") sourceID(" << sourceID << - ") hotSink(" << hotSink << - ")" << std::endl; - outString = fmt.str(); -} - -bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t & resultID, am_Identifier_s & sourceID, - int16_t const desiredStaticID = 0) -{ - if( desiredStaticID > 0 && desiredStaticID < sourceID.mMin ) - { - resultID = desiredStaticID; - return true; - } - else if( sourceID.mCurrentValue < sourceID.mMax ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved. - { - resultID = sourceID.mCurrentValue++; - return true; - } - else - { - resultID = -1; - return false; - } - } - -template bool CAmDatabaseHandlerMap::CAmMappedData::getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, - const std::unordered_map & map) -{ - TMapKey nextID; - int16_t const lastID = sourceID.mCurrentValue; - if( sourceID.mCurrentValue < sourceID.mMax ) - nextID = sourceID.mCurrentValue++; - else - nextID = sourceID.mCurrentValue = sourceID.mMin; - - bool notFreeIDs = false; - while( existsObjectWithKeyInMap(nextID, map) ) - { - - if( sourceID.mCurrentValue < sourceID.mMax ) - nextID = sourceID.mCurrentValue++; - else - { - sourceID.mCurrentValue = sourceID.mMin; - nextID = sourceID.mCurrentValue++; - } - - if( sourceID.mCurrentValue == lastID ) - { - notFreeIDs = true; - break; - } - } - if(notFreeIDs) - { - resultID = -1; - return false; - } - resultID = nextID; - return true; -} - -bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t & resultID) -{ - return getNextConnectionID(resultID, mCurrentMainConnectionID, mMainConnectionMap); -} - -bool CAmDatabaseHandlerMap::CAmMappedData::increaseConnectionID(int16_t & resultID) -{ - return getNextConnectionID(resultID, mCurrentConnectionID, mConnectionMap); -} - - -CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), // - mFirstStaticSource(true), // - mFirstStaticGateway(true), // - mFirstStaticConverter(true), // - mFirstStaticSinkClass(true), // - mFirstStaticSourceClass(true), // - mFirstStaticCrossfader(true), // - mpDatabaseObserver(NULL), // - mListConnectionFormat(), // - mMappedData() -{ - logInfo(__PRETTY_FUNCTION__,"Init "); -} - -CAmDatabaseHandlerMap::~CAmDatabaseHandlerMap() -{ - logInfo(__PRETTY_FUNCTION__,"Destroy"); - mpDatabaseObserver = NULL; -} - -am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - assert(!domainData.name.empty()); - assert(!domainData.busname.empty()); - assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX); - //first check for a reserved domain - am_Domain_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const CAmDomain & obj){ - return domainData.name.compare(obj.name)==0; - }); - - int16_t nextID = 0; - - if( NULL != reservedDomain ) - { - nextID = reservedDomain->domainID; - domainID = nextID; - mMappedData.mDomainMap[nextID] = domainData; - mMappedData.mDomainMap[nextID].domainID = nextID; - mMappedData.mDomainMap[nextID].reserved = 0; - logInfo("DatabaseHandler::enterDomainDB entered reserved domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "reserved ID:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); - return (E_OK); - } - else - { - if(mMappedData.increaseID(nextID, mMappedData.mCurrentDomainID, domainData.domainID)) - { - domainID = nextID; - mMappedData.mDomainMap[nextID] = domainData; - mMappedData.mDomainMap[nextID].domainID = nextID; - logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); - return (E_OK); - } - else - { - domainID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (E_UNKNOWN); - } - } -} - -int16_t CAmDatabaseHandlerMap::calculateDelayForRoute(const std::vector& listConnectionID) -{ - int16_t delay = 0; - std::vector::const_iterator elementIterator = listConnectionID.begin(); - for (; elementIterator < listConnectionID.end(); ++elementIterator) - { - am_connectionID_t key = *elementIterator; - std::unordered_map::const_iterator it = mMappedData.mConnectionMap.find(key); - if (it!=mMappedData.mConnectionMap.end()) - { - int16_t temp_delay = it->second.delay; - if (temp_delay != -1 && delay != -1) - delay += temp_delay; - else - delay = -1; - } - } - return delay; -} - -am_Error_e CAmDatabaseHandlerMap::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); - - int16_t delay = 0; - int16_t nextID = 0; - if(mMappedData.increaseMainConnectionID(nextID)) - { - connectionID = nextID; - mMappedData.mMainConnectionMap[nextID] = mainConnectionData; - mMappedData.mMainConnectionMap[nextID].mainConnectionID = nextID; - } - else - { - connectionID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (E_UNKNOWN); - } - - //now check the connectionTable for all connections in the route. IF connectionID exist - delay = calculateDelayForRoute(mainConnectionData.listConnectionID); - logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); - - if (mpDatabaseObserver) - { - am_MainConnectionType_s mainConnection; - mMappedData.mMainConnectionMap[nextID].getMainConnectionType(mainConnection); - mpDatabaseObserver->newMainConnection(mainConnection); - mpDatabaseObserver->mainConnectionStateChanged(connectionID, mMappedData.mMainConnectionMap[nextID].connectionState); - } - - //finally, we update the delay value for the maintable - if (delay == 0) - delay = -1; - (void)changeDelayMainConnection(delay, connectionID); - - return (E_OK); -} - -/** - * Helper method, that inserts a new struct in the map and copies the given into it. - * This method uses the increaseID function to secure the global id is properly increased. - **/ -bool CAmDatabaseHandlerMap::insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - int16_t nextID = 0; - if( mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID, sinkData.sinkID) ) - { - sinkID = nextID; - mMappedData.mSinkMap[nextID] = sinkData; - mMappedData.mSinkMap[nextID].sinkID = nextID; - filterDuplicateNotificationConfigurationTypes(mMappedData.mSinkMap[nextID].listNotificationConfigurations); - filterDuplicateNotificationConfigurationTypes(mMappedData.mSinkMap[nextID].listMainNotificationConfigurations); - return (true); - } - else - { - sinkID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached!"); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - assert(sinkData.sinkID=MS_UNKNOWN && sinkData.muteState<=MS_MAX); - - am_sinkID_t temp_SinkID = 0; - am_sinkID_t temp_SinkIndex = 0; - //if sinkID is zero and the first Static Sink was already entered, the ID is created - am_Sink_s const *reservedDomain = objectMatchingPredicate(mMappedData.mSinkMap, [&](const CAmSink & obj){ - return true==obj.reserved && obj.name.compare(sinkData.name)==0; - }); - if( NULL!=reservedDomain ) - { - am_sinkID_t oldSinkID = reservedDomain->sinkID; - mMappedData.mSinkMap[oldSinkID] = sinkData; - mMappedData.mSinkMap[oldSinkID].reserved = 0; - temp_SinkID = oldSinkID; - temp_SinkIndex = oldSinkID; - } - else - { - bool result; - if ( sinkData.sinkID != 0 || mFirstStaticSink ) - { - //check if the ID already exists - if (existSinkNameOrID(sinkData.sinkID, sinkData.name)) - { - sinkID = sinkData.sinkID; - return (E_ALREADY_EXISTS); - } - } - result = insertSinkDB(sinkData, temp_SinkID); - if( false == result ) - return (E_UNKNOWN); - temp_SinkIndex = temp_SinkID; - } - //if the first static sink is entered, we need to set it onto the boundary - if (sinkData.sinkID == 0 && mFirstStaticSink) - { - mFirstStaticSink = false; - } - mMappedData.mSinkMap[temp_SinkIndex].sinkID = temp_SinkID; - sinkID = temp_SinkID; - - am_Sink_s & sink = mMappedData.mSinkMap[temp_SinkID]; - logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sink.name, "domainID:", sink.domainID, "classID:", sink.sinkClassID, "volume:", sink.volume, "assigned ID:", sink.sinkID); - - if (mpDatabaseObserver != NULL) - { - sink.sinkID=sinkID; - mpDatabaseObserver->newSink(sink); - } - return (E_OK); -} - -bool CAmDatabaseHandlerMap::insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentCrossfaderID, crossfaderData.crossfaderID)) - { - crossfaderID = nextID; - mMappedData.mCrossfaderMap[nextID] = crossfaderData; - mMappedData.mCrossfaderMap[nextID].crossfaderID = nextID; - return (true); - } - else - { - crossfaderID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::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)); - - am_crossfaderID_t temp_CrossfaderID = 0; - am_crossfaderID_t temp_CrossfaderIndex = 0; - - bool result; - //if gatewayData is zero and the first Static Sink was already entered, the ID is created - if (crossfaderData.crossfaderID != 0 || mFirstStaticCrossfader) - { - //check if the ID already exists - if (existCrossFader(crossfaderData.crossfaderID)) - { - crossfaderID = crossfaderData.crossfaderID; - return (E_ALREADY_EXISTS); - } - } - result = insertCrossfaderDB(crossfaderData, temp_CrossfaderID); - if( false == result ) - return (E_UNKNOWN); - temp_CrossfaderIndex = temp_CrossfaderID; - - //if the first static sink is entered, we need to set it onto the boundary - if ( 0==crossfaderData.crossfaderID && mFirstStaticCrossfader) - { - mFirstStaticCrossfader = false; - } - - mMappedData.mCrossfaderMap[temp_CrossfaderIndex].crossfaderID = temp_CrossfaderID; - crossfaderID = temp_CrossfaderID; - logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID); - - if (mpDatabaseObserver) - mpDatabaseObserver->newCrossfader(mMappedData.mCrossfaderMap[temp_CrossfaderIndex]); - return (E_OK); -} - -bool CAmDatabaseHandlerMap::insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentGatewayID, gatewayData.gatewayID)) - { - gatewayID = nextID; - mMappedData.mGatewayMap[nextID] = gatewayData; - mMappedData.mGatewayMap[nextID].gatewayID = nextID; - return (true); - } - else - { - gatewayID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - assert(gatewayData.gatewayIDnewGateway(mMappedData.mGatewayMap[temp_GatewayIndex]); - return (E_OK); -} - -bool CAmDatabaseHandlerMap::insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentConverterID, converteData.converterID)) - { - converterID = nextID; - mMappedData.mConverterMap[nextID] = converteData; - mMappedData.mConverterMap[nextID].converterID = nextID; - return (true); - } - else - { - converterID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID) -{ - assert(converterData.converterIDnewConverter(mMappedData.mConverterMap[tempIndex]); - return (E_OK); -} - -void CAmDatabaseHandlerMap::dump( std::ostream & output ) const -{ - output << std::endl << "****************** DUMP START ******************" << std::endl; - CAmMappedData::printMap(mMappedData.mDomainMap, output); - CAmMappedData::printMap(mMappedData.mSourceMap, output); - CAmMappedData::printMap(mMappedData.mSinkMap, output); - CAmMappedData::printMap(mMappedData.mSourceClassesMap, output); - CAmMappedData::printMap(mMappedData.mSinkClassesMap, output); - CAmMappedData::printMap(mMappedData.mConnectionMap, output); - CAmMappedData::printMap(mMappedData.mMainConnectionMap, output); - CAmMappedData::printMap(mMappedData.mCrossfaderMap, output); - CAmMappedData::printMap(mMappedData.mGatewayMap, output); - CAmVectorSystemProperties::const_iterator iter = mMappedData.mSystemProperties.begin(); - output << "System properties" << "\n"; - for(; iter!=mMappedData.mSystemProperties.end(); iter++) - output << "[type:" << iter->type << " value:" << iter->value << "]"; - output << std::endl << "****************** DUMP END ******************" << std::endl; -} - -bool CAmDatabaseHandlerMap::insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID, sourceData.sourceID)) - { - sourceID = nextID; - mMappedData.mSourceMap[nextID] = sourceData; - mMappedData.mSourceMap[nextID].sourceID = nextID; - filterDuplicateNotificationConfigurationTypes(mMappedData.mSourceMap[nextID].listNotificationConfigurations); - filterDuplicateNotificationConfigurationTypes(mMappedData.mSourceMap[nextID].listMainNotificationConfigurations); - return (true); - } - else - { - sourceID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - assert(sourceData.sourceID=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX); - - bool isFirstStatic = sourceData.sourceID == 0 && mFirstStaticSource; - am_sourceID_t temp_SourceID = 0; - am_sourceID_t temp_SourceIndex = 0; - CAmSource const *reservedSource = objectMatchingPredicate(mMappedData.mSourceMap, [&](const CAmSource & obj){ - return true==obj.reserved && obj.name.compare(sourceData.name)==0; - }); - if( NULL != reservedSource ) - { - am_sourceID_t oldSourceID = reservedSource->sourceID; - mMappedData.mSourceMap[oldSourceID] = sourceData; - mMappedData.mSourceMap[oldSourceID].reserved = 0; - temp_SourceID = oldSourceID; - temp_SourceIndex = oldSourceID; - } - else - { - bool result; - if ( !isFirstStatic ) - { - //check if the ID already exists - if (existSourceNameOrID(sourceData.sourceID, sourceData.name)) - { - sourceID = sourceData.sourceID; - return (E_ALREADY_EXISTS); - } - } - result = insertSourceDB(sourceData, temp_SourceID); - if( false == result ) - return (E_UNKNOWN); - temp_SourceIndex = temp_SourceID; - } - - if ( isFirstStatic ) - { - //if the first static sink is entered, we need to set it onto the boundary if needed - mFirstStaticSource = false; - } - mMappedData.mSourceMap[temp_SourceIndex].sourceID = temp_SourceID; - sourceID = temp_SourceID; - - logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); - - if (mpDatabaseObserver) - mpDatabaseObserver->newSource(mMappedData.mSourceMap[temp_SourceIndex]); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::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 - int16_t nextID = 0; - if(mMappedData.increaseConnectionID(nextID)) - { - connectionID = nextID; - mMappedData.mConnectionMap[nextID] = connection; - mMappedData.mConnectionMap[nextID].connectionID = nextID; - mMappedData.mConnectionMap[nextID].reserved = true; - } - else - { - connectionID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (E_UNKNOWN); - } - - logInfo("DatabaseHandler::enterConnectionDB entered new connection sourceID=", connection.sourceID, "sinkID=", connection.sinkID, "sourceID=", connection.sourceID, "connectionFormat=", connection.connectionFormat, "assigned ID=", connectionID); - return (E_OK); -} - -bool CAmDatabaseHandlerMap::insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkClassesID, sinkClass.sinkClassID)) - { - sinkClassID = nextID; - mMappedData.mSinkClassesMap[nextID] = sinkClass; - mMappedData.mSinkClassesMap[nextID].sinkClassID = nextID; - return (true); - } - else - { - sinkClassID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) -{ - assert(sinkClass.sinkClassIDnumberOfSinkClassesChanged(); - return (E_OK); -} - -bool CAmDatabaseHandlerMap::insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) -{ - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceClassesID, sourceClass.sourceClassID)) - { - sourceClassID = nextID; - mMappedData.mSourceClassesMap[nextID] = sourceClass; - mMappedData.mSourceClassesMap[nextID].sourceClassID = nextID; - return (true); - } - else - { - sourceClassID = 0; - logInfo(__PRETTY_FUNCTION__,"Max limit reached."); - return (false); - } -} - -am_Error_e CAmDatabaseHandlerMap::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) -{ - assert(sourceClass.sourceClassIDnumberOfSourceClassesChanged(); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::enterSystemProperties(const std::vector & listSystemProperties) -{ - assert(!listSystemProperties.empty()); - - mMappedData.mSystemProperties = listSystemProperties; - - logInfo("DatabaseHandler::enterSystemProperties entered system properties"); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector& listConnectionID) -{ - assert(mainconnectionID!=0); - if (!existMainConnection(mainconnectionID)) - { - return (E_NON_EXISTENT); - } - - int16_t delay = calculateDelayForRoute(listConnectionID); - - //now we replace the data in the main connection object with the new one - mMappedData.mMainConnectionMap[mainconnectionID].listConnectionID = listConnectionID; - - if (changeDelayMainConnection(delay,mainconnectionID) == E_NO_CHANGE) - logError("DatabaseHandler::changeMainConnectionRouteDB error while changing mainConnectionDelay to ", delay); - - logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) -{ - assert(mainconnectionID!=0); - assert(connectionState>=CS_UNKNOWN && connectionState<=CS_MAX); - - if (!existMainConnection(mainconnectionID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[mainconnectionID].connectionState, connectionState); - - logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); - if (mpDatabaseObserver) - mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].mainVolume, mainVolume); - - logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); - - if (mpDatabaseObserver) - mpDatabaseObserver->volumeChanged(sinkID, mainVolume); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].available, availability); - - logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mpDatabaseObserver && sinkVisible(sinkID)) - mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) -{ - assert(domainID!=0); - assert(domainState>=DS_UNKNOWN && domainState<=DS_MAX); - - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mDomainMap[domainID].state, domainState); - - logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - assert(muteState>=MS_UNKNOWN && muteState<=MS_MAX); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mSinkMap[sinkID].muteState, muteState); - - logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); - - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; - std::vector::iterator elementIterator = sink.listMainSoundProperties.begin(); - for (;elementIterator != sink.listMainSoundProperties.end(); ++elementIterator) - { - if (elementIterator->type == soundProperty.type) - { - DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); - if(sink.cacheMainSoundProperties.size()) - sink.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; - break; - } - } - - logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - if (mpDatabaseObserver) - mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - am_Source_Database_s & source = mMappedData.mSourceMap.at(sourceID); - std::vector::iterator elementIterator = source.listMainSoundProperties.begin(); - for (;elementIterator != source.listMainSoundProperties.end(); ++elementIterator) - { - if (elementIterator->type == soundProperty.type) - { - DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); - if(source.cacheMainSoundProperties.size()) - source.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; - break; - } - } - - logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - - if (mpDatabaseObserver) - mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_MAX); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_RIE(mMappedData.mSourceMap[sourceID].available, availability); - - logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mpDatabaseObserver && sourceVisible(sourceID)) - mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSystemPropertyDB(const am_SystemProperty_s & property) -{ - std::vector::iterator elementIterator = mMappedData.mSystemProperties.begin(); - for (;elementIterator != mMappedData.mSystemProperties.end(); ++elementIterator) - { - if (elementIterator->type == property.type) - DB_COND_UPDATE_RIE(elementIterator->value, property.value); - } - - logInfo("DatabaseHandler::changeSystemPropertyDB changed system property"); - - if (mpDatabaseObserver) - mpDatabaseObserver->systemPropertyChanged(property); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) -{ - assert(mainConnectionID!=0); - - if (!existMainConnection(mainConnectionID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mMainConnectionMap.erase(mainConnectionID); - - logInfo("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID); - if (mpDatabaseObserver) - { - mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); - mpDatabaseObserver->removedMainConnection(mainConnectionID); - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeSinkDB(const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - bool visible = sinkVisible(sinkID); - - mMappedData.mSinkMap.erase(sinkID); - // todo: Check the tables SinkMainSoundProperty and SinkMainNotificationConfiguration with 'visible' set to true - //if visible is true then delete SinkMainSoundProperty and SinkMainNotificationConfiguration ???? - logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); - - if (mpDatabaseObserver != NULL) - mpDatabaseObserver->removedSink(sinkID, visible); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeSourceDB(const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - bool visible = sourceVisible(sourceID); - - mMappedData.mSourceMap.erase(sourceID); - - // todo: Check the tables SourceMainSoundProperty and SourceMainNotificationConfiguration with 'visible' set to true - //if visible is true then delete SourceMainSoundProperty and SourceMainNotificationConfiguration ???? - - logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); - if (mpDatabaseObserver) - mpDatabaseObserver->removedSource(sourceID, visible); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeGatewayDB(const am_gatewayID_t gatewayID) -{ - assert(gatewayID!=0); - - if (!existGateway(gatewayID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mGatewayMap.erase(gatewayID); - - logInfo("DatabaseHandler::removeGatewayDB removed:", gatewayID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeGateway(gatewayID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeConverterDB(const am_converterID_t converterID) -{ - assert(converterID!=0); - - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mConverterMap.erase(converterID); - - logInfo("DatabaseHandler::removeConverterDB removed:", converterID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeConverter(converterID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeCrossfaderDB(const am_crossfaderID_t crossfaderID) -{ - assert(crossfaderID!=0); - - if (!existCrossFader(crossfaderID)) - { - return (E_NON_EXISTENT); - } - mMappedData.mCrossfaderMap.erase(crossfaderID); - - logInfo("DatabaseHandler::removeCrossfaderDB removed:", crossfaderID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeCrossfader(crossfaderID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeDomainDB(const am_domainID_t domainID) -{ - assert(domainID!=0); - - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - mMappedData.mDomainMap.erase(domainID); - - logInfo("DatabaseHandler::removeDomainDB removed:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeDomain(domainID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeSinkClassDB(const am_sinkClass_t sinkClassID) -{ - assert(sinkClassID!=0); - - if (!existSinkClass(sinkClassID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mSinkClassesMap.erase(sinkClassID); - - logInfo("DatabaseHandler::removeSinkClassDB removed:", sinkClassID); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSinkClassesChanged(); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeSourceClassDB(const am_sourceClass_t sourceClassID) -{ - assert(sourceClassID!=0); - - if (!existSourceClass(sourceClassID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mSourceClassesMap.erase(sourceClassID); - logInfo("DatabaseHandler::removeSourceClassDB removed:", sourceClassID); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSourceClassesChanged(); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::removeConnection(const am_connectionID_t connectionID) -{ - assert(connectionID!=0); - - mMappedData.mConnectionMap.erase(connectionID); - - logInfo("DatabaseHandler::removeConnection removed:", connectionID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - am_Source_Database_s source = mMappedData.mSourceMap.at(sourceID); - classInfo.sourceClassID = source.sourceClassID; - - if (!existSourceClass(classInfo.sourceClassID)) - { - return (E_NON_EXISTENT); - } - am_SourceClass_s tmpClass = mMappedData.mSourceClassesMap.at(classInfo.sourceClassID); - classInfo = tmpClass; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s & sinkData) const -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - return (E_NON_EXISTENT); - - am_Sink_Database_s mappedSink = mMappedData.mSinkMap.at(sinkID); - if( true == mappedSink.reserved ) - return (E_NON_EXISTENT); - sinkData = mappedSink; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s & sourceData) const -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - return (E_NON_EXISTENT); - - am_Source_Database_s mappedSource = mMappedData.mSourceMap.at(sourceID); - if( true == mappedSource.reserved ) - return (E_NON_EXISTENT); - - sourceData = mappedSource; - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerMap::getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s & mainConnectionData) const -{ - assert(mainConnectionID!=0); - if (!existMainConnection(mainConnectionID)) - { - return (E_NON_EXISTENT); - } - am_MainConnection_s temp = mMappedData.mMainConnectionMap.at(mainConnectionID); - mainConnectionData = temp; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkClassInfoDB(const am_SinkClass_s& sinkClass) -{ - assert(sinkClass.sinkClassID!=0); - assert(!sinkClass.listClassProperties.empty()); - - //check if the ID already exists - if (!existSinkClass(sinkClass.sinkClassID)) - return (E_NON_EXISTENT); - - DB_COND_UPDATE_RIE(mMappedData.mSinkClassesMap[sinkClass.sinkClassID].listClassProperties, sinkClass.listClassProperties); - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceClassInfoDB(const am_SourceClass_s& sourceClass) -{ - assert(sourceClass.sourceClassID!=0); - assert(!sourceClass.listClassProperties.empty()); - - //check if the ID already exists - if (!existSourceClass(sourceClass.sourceClassID)) - return (E_NON_EXISTENT); - - DB_COND_UPDATE_RIE(mMappedData.mSourceClassesMap[sourceClass.sourceClassID].listClassProperties, sourceClass.listClassProperties); - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - am_Sink_Database_s sink = mMappedData.mSinkMap.at(sinkID); - sinkClass.sinkClassID = sink.sinkClassID; - - if (!existSinkClass(sinkClass.sinkClassID)) - { - return (E_NON_EXISTENT); - } - am_SinkClass_s tmpSinkClass = mMappedData.mSinkClassesMap.at(sinkClass.sinkClassID); - sinkClass = tmpSinkClass; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const -{ - assert(gatewayID!=0); - if (!existGateway(gatewayID)) - { - return (E_NON_EXISTENT); - } - - gatewayData = mMappedData.mGatewayMap.at(gatewayID); - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerMap::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const -{ - assert(converterID!=0); - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - - converterData = mMappedData.mConverterMap.at(converterID); - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerMap::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const -{ - assert(crossfaderID!=0); - if (!existCrossFader(crossfaderID)) - { - return (E_NON_EXISTENT); - } - - crossfaderData = mMappedData.mCrossfaderMap.at(crossfaderID); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSinksOfDomain(const am_domainID_t domainID, std::vector & listSinkID) const -{ - assert(domainID!=0); - listSinkID.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - - std::unordered_map::const_iterator elementIterator = mMappedData.mSinkMap.begin(); - for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator) - { - if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID) - listSinkID.push_back(elementIterator->second.sinkID); - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSourcesOfDomain(const am_domainID_t domainID, std::vector & listSourceID) const -{ - assert(domainID!=0); - listSourceID.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - CAmMapSource::const_iterator elementIterator = mMappedData.mSourceMap.begin(); - for (;elementIterator != mMappedData.mSourceMap.end(); ++elementIterator) - { - if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID) - listSourceID.push_back(elementIterator->second.sourceID); - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector & listCrossfader) const -{ - assert(domainID!=0); - listCrossfader.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - - CAmMapSource::const_iterator sourceIterator = mMappedData.mSourceMap.begin(); - for (;sourceIterator != mMappedData.mSourceMap.end(); ++sourceIterator) - { - if (domainID==sourceIterator->second.domainID) - { - CAmMapCrossfader::const_iterator elementIterator = mMappedData.mCrossfaderMap.begin(); - for (;elementIterator != mMappedData.mCrossfaderMap.end(); ++elementIterator) - { - if ( sourceIterator->second.sourceID==elementIterator->second.sourceID ) - listCrossfader.push_back(elementIterator->second.crossfaderID); - } - } - } - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerMap::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector & listGatewaysID) const -{ - assert(domainID!=0); - listGatewaysID.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - - CAmMapGateway::const_iterator elementIterator = mMappedData.mGatewayMap.begin(); - for (;elementIterator != mMappedData.mGatewayMap.end(); ++elementIterator) - { - if (domainID==elementIterator->second.controlDomainID) - listGatewaysID.push_back(elementIterator->second.gatewayID); - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) const -{ - assert(domainID!=0); - listConvertersID.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - - CAmMapConverter::const_iterator elementIterator = mMappedData.mConverterMap.begin(); - for (;elementIterator != mMappedData.mConverterMap.end(); ++elementIterator) - { - if (domainID==elementIterator->second.domainID) - listConvertersID.push_back(elementIterator->second.converterID); - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainConnections(std::vector & listMainConnections) const -{ - listMainConnections.clear(); - - CAmMapMainConnection::const_iterator elementIterator = mMappedData.mMainConnectionMap.begin(); - for (;elementIterator != mMappedData.mMainConnectionMap.end(); ++elementIterator) - { - listMainConnections.push_back(elementIterator->second); - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListDomains(std::vector & listDomains) const -{ - listDomains.clear(); - - CAmMapDomain::const_iterator elementIterator = mMappedData.mDomainMap.begin(); - for (;elementIterator != mMappedData.mDomainMap.end(); ++elementIterator) - { - if( 0==elementIterator->second.reserved ) - listDomains.push_back(elementIterator->second); - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListConnections(std::vector & listConnections) const -{ - listConnections.clear(); - - CAmMapConnection::const_iterator elementIterator = mMappedData.mConnectionMap.begin(); - for (;elementIterator != mMappedData.mConnectionMap.end(); ++elementIterator) - { - if( 0==elementIterator->second.reserved ) - listConnections.push_back(elementIterator->second); - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSinks(std::vector & listSinks) const -{ - listSinks.clear(); - - std::for_each(mMappedData.mSinkMap.begin(), mMappedData.mSinkMap.end(), [&](const std::pair& ref) { - if( 0==ref.second.reserved ) - listSinks.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSources(std::vector & listSources) const -{ - listSources.clear(); - - std::for_each(mMappedData.mSourceMap.begin(), mMappedData.mSourceMap.end(), [&](const std::pair& ref) { - if( 0==ref.second.reserved ) - { - listSources.push_back(ref.second); - } - }); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSourceClasses(std::vector & listSourceClasses) const -{ - listSourceClasses.clear(); - - std::for_each(mMappedData.mSourceClassesMap.begin(), mMappedData.mSourceClassesMap.end(), [&](const std::pair& ref) { - listSourceClasses.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListCrossfaders(std::vector & listCrossfaders) const -{ - listCrossfaders.clear(); - - std::for_each(mMappedData.mCrossfaderMap.begin(), mMappedData.mCrossfaderMap.end(), [&](const std::pair& ref) { - listCrossfaders.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListGateways(std::vector & listGateways) const -{ - listGateways.clear(); - - std::for_each(mMappedData.mGatewayMap.begin(), mMappedData.mGatewayMap.end(), [&](const std::pair& ref) { - listGateways.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListConverters(std::vector & listConverters) const -{ - listConverters.clear(); - - std::for_each(mMappedData.mConverterMap.begin(), mMappedData.mConverterMap.end(), [&](const std::pair& ref) { - listConverters.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSinkClasses(std::vector & listSinkClasses) const -{ - listSinkClasses.clear(); - - std::for_each(mMappedData.mSinkClassesMap.begin(), mMappedData.mSinkClassesMap.end(), [&](const std::pair& ref) { - listSinkClasses.push_back(ref.second); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListVisibleMainConnections(std::vector & listConnections) const -{ - listConnections.clear(); - std::for_each(mMappedData.mMainConnectionMap.begin(), mMappedData.mMainConnectionMap.end(), [&](const std::pair& ref) { - listConnections.emplace_back(); - ref.second.getMainConnectionType(listConnections.back()); - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSinks(std::vector & listMainSinks) const -{ - listMainSinks.clear(); - std::for_each(mMappedData.mSinkMap.begin(), mMappedData.mSinkMap.end(), [&](const std::pair& ref) { - if( 0==ref.second.reserved && 1==ref.second.visible ) - { - listMainSinks.emplace_back(); - ref.second.getSinkType(listMainSinks.back()); - } - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSources(std::vector & listMainSources) const -{ - listMainSources.clear(); - std::for_each(mMappedData.mSourceMap.begin(), mMappedData.mSourceMap.end(), [&](const std::pair& ref) { - if( 0==ref.second.reserved && 1==ref.second.visible ) - { - listMainSources.emplace_back(); - ref.second.getSourceType(listMainSources.back()); - } - }); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector & listSoundProperties) const -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return E_NON_EXISTENT; - - const am_Sink_s & sink = mMappedData.mSinkMap.at(sinkID); - listSoundProperties = sink.listMainSoundProperties; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector & listSourceProperties) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return E_NON_EXISTENT; - - const am_Source_s & source = mMappedData.mSourceMap.at(sourceID); - listSourceProperties = source.listMainSoundProperties; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return E_NON_EXISTENT; - - const am_Sink_Database_s & sink = mMappedData.mSinkMap.at(sinkID); - listSoundproperties = sink.listSoundProperties; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return E_NON_EXISTENT; - - const am_Source_Database_s & source = mMappedData.mSourceMap.at(sourceID); - listSoundproperties = source.listSoundProperties; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListSystemProperties(std::vector & listSystemProperties) const -{ - listSystemProperties = mMappedData.mSystemProperties; - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerMap::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const -{ - if (!existSink(sinkID)) - return E_NON_EXISTENT; - const am_Sink_s & sink = mMappedData.mSinkMap.at(sinkID); - listConnectionFormats = sink.listConnectionFormats; - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerMap::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const -{ - if (!existSource(sourceID)) - return E_NON_EXISTENT; - const am_Source_s & source = mMappedData.mSourceMap.at(sourceID); - listConnectionFormats = source.listConnectionFormats; - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerMap::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_NON_EXISTENT; - } - listConnectionFormat = iter->second; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const -{ - assert(mainConnectionID!=0); - if (!existMainConnection(mainConnectionID)) - return E_NON_EXISTENT; - delay = -1; - - const am_MainConnection_s & mainConnection = mMappedData.mMainConnectionMap.at(mainConnectionID); - delay = mainConnection.delay; - - if (delay == -1) - return (E_NOT_POSSIBLE); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID) -{ - assert(connectionID!=0); - if (!existMainConnection(connectionID)) - return (E_NON_EXISTENT); - DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[connectionID].delay, delay); - if (mpDatabaseObserver) - mpDatabaseObserver->timingInformationChanged(connectionID, delay); - return (E_OK); -} - -/** - * checks for a certain mainConnection - * @param mainConnectionID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existMainConnection(const am_mainConnectionID_t mainConnectionID) const -{ - return existsObjectWithKeyInMap(mainConnectionID, mMappedData.mMainConnectionMap); -} - -/** - * checks for a certain Source - * @param sourceID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existSource(const am_sourceID_t sourceID) const -{ - am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=source ) - return (0==source->reserved); - - return false; -} - -/** - * checks if a source name or ID exists - * @param sourceID the sourceID - * @param name the name - * @return true if it exits - */ -bool CAmDatabaseHandlerMap::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const -{ - return sourceWithNameOrID(sourceID, name); -} - -/** - * checks if a name exits - * @param name the name - * @return true if it exits - */ -bool CAmDatabaseHandlerMap::existSourceName(const std::string & name) const -{ - return existSourceNameOrID(mMappedData.mCurrentSourceID.mMax, name); -} - -/** - * checks for a certain Sink - * @param sinkID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existSink(const am_sinkID_t sinkID) const -{ - bool returnVal = false; - CAmMapSink::const_iterator elementIterator = mMappedData.mSinkMap.begin(); - for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator) - { - if( 0==elementIterator->second.reserved && - sinkID==elementIterator->second.sinkID) - { - returnVal = true; - break; - } - } - return (returnVal); -} - -/** - * returns source with given ID or the name if exists - * @param sourceID the ID - * @param name the name - * @return source structure if exists. - */ -const CAmDatabaseHandlerMap::am_Source_Database_s * CAmDatabaseHandlerMap::sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const -{ - std::function comparator = [&](const CAmDatabaseHandlerMap::am_Source_Database_s & source)->bool{ - return ( 0==source.reserved && - (sourceID==source.sourceID || name.compare(source.name)==0)); - }; - return objectMatchingPredicate(mMappedData.mSourceMap, comparator); -} - -/** - * returns sink with given ID or the name if exists - * @param sinkID the ID - * @param name the name - * @return sink structure if exists. - */ -const CAmDatabaseHandlerMap::am_Sink_Database_s * CAmDatabaseHandlerMap::sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const -{ - std::function comparator = [&](const CAmDatabaseHandlerMap::am_Sink_Database_s & sink)->bool{ - return ( 0==sink.reserved && - (sinkID==sink.sinkID || name.compare(sink.name)==0)); - }; - return objectMatchingPredicate(mMappedData.mSinkMap, comparator); -} - -/** - * 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 CAmDatabaseHandlerMap::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const -{ - return sinkWithNameOrID( sinkID, name)!=NULL; -} - -/** - * checks if a sink with the name exists - * @param name the name - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existSinkName(const std::string & name) const -{ - return existSinkNameOrID(mMappedData.mCurrentSinkID.mMax, name); -} - -/** - * checks for a certain domain - * @param domainID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existDomain(const am_domainID_t domainID) const -{ - am_Domain_Database_s const * source = objectForKeyIfExistsInMap(domainID, mMappedData.mDomainMap); - if( NULL!=source ) - return (0==source->reserved); - - return false; -} - -/** - * checks for certain gateway - * @param gatewayID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existGateway(const am_gatewayID_t gatewayID) const -{ - return existsObjectWithKeyInMap(gatewayID, mMappedData.mGatewayMap); -} - -bool CAmDatabaseHandlerMap::existConverter(const am_converterID_t converterID) const -{ - return existsObjectWithKeyInMap(converterID, mMappedData.mConverterMap); -} - -am_Error_e CAmDatabaseHandlerMap::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const -{ - assert(sourceID!=0); - domainID=0; - - am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=source ) - { - domainID = source->domainID; - return E_OK; - } - return E_NON_EXISTENT; -} - -am_Error_e am::CAmDatabaseHandlerMap::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t & domainID) const -{ - assert(sinkID!=0); - domainID=0; - - am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=source ) - { - domainID = source->domainID; - return E_OK; - } - return E_NON_EXISTENT; -} - -am_Error_e am::CAmDatabaseHandlerMap::getDomainOfCrossfader(const am_converterID_t crossfader, am_domainID_t & domainID) const -{ - assert(crossfader!=0); - domainID=0; - - am_Crossfader_Database_s const * cross = objectForKeyIfExistsInMap(crossfader, mMappedData.mCrossfaderMap); - if( NULL!=cross ) - { - getDomainOfSource(cross->sinkID_A,domainID); - return E_OK; - } - return E_NON_EXISTENT; -} - -/** - * checks for certain SinkClass - * @param sinkClassID - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existSinkClass(const am_sinkClass_t sinkClassID) const -{ - return existsObjectWithKeyInMap(sinkClassID, mMappedData.mSinkClassesMap); -} - -/** - * checks for certain sourceClass - * @param sourceClassID - * @return true if it exists - */ -bool CAmDatabaseHandlerMap::existSourceClass(const am_sourceClass_t sourceClassID) const -{ - return existsObjectWithKeyInMap(sourceClassID, mMappedData.mSourceClassesMap); -} - -am_Error_e CAmDatabaseHandlerMap::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - assert(connectionID!=0); - if(!existConnectionID(connectionID)) - return E_NON_EXISTENT; - - mMappedData.mConnectionMap[connectionID].delay = delay; - - //now we need to find all mainConnections that use the changed connection and update their timing - - //first get all route tables for all mainconnections - am_Error_e error = E_OK; - CAmMapMainConnection::const_iterator iter = mMappedData.mMainConnectionMap.begin(); - for(; iter != mMappedData.mMainConnectionMap.end(); ++iter) - { - const am_MainConnection_s & mainConnection = iter->second; - if (std::find(mainConnection.listConnectionID.begin(), mainConnection.listConnectionID.end(), connectionID) != mainConnection.listConnectionID.end()) - { - // Got it. - error = changeDelayMainConnection(calculateMainConnectionDelay(mainConnection.mainConnectionID), mainConnection.mainConnectionID); - } - } - - return error; -} - -am_Error_e CAmDatabaseHandlerMap::changeConnectionFinal(const am_connectionID_t connectionID) -{ - assert(connectionID!=0); - am_Connection_Database_s const * connection = objectForKeyIfExistsInMap(connectionID, mMappedData.mConnectionMap); - if( NULL!=connection ) - { - mMappedData.mConnectionMap.at(connectionID).reserved = false; - return E_OK; - } - return (E_NON_EXISTENT); -} - -am_timeSync_t CAmDatabaseHandlerMap::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const -{ - assert(mainConnectionID!=0); - if (!existMainConnection(mainConnectionID)) - return -1; - const am_MainConnection_s & mainConnection = mMappedData.mMainConnectionMap.at(mainConnectionID); - am_timeSync_t delay = 0; - std::vector::const_iterator iter = mainConnection.listConnectionID.begin(); - for(;iterdelay, static_cast(0)); - } - } - return (delay == 0 ? -1 : std::min(delay, static_cast(SHRT_MAX))); -} - -/** - * registers the Observer at the Database - * @param iObserver pointer to the observer - */ -void CAmDatabaseHandlerMap::registerObserver(CAmDatabaseObserver *iObserver) -{ - assert(iObserver!=NULL); - mpDatabaseObserver = iObserver; -} - -/** - * gives information about the visibility of a source - * @param sourceID the sourceID - * @return true if source is visible - */ -bool CAmDatabaseHandlerMap::sourceVisible(const am_sourceID_t sourceID) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return false; - am_Source_Database_s source = mMappedData.mSourceMap.at(sourceID); - return source.visible; -} - -/** - * gives information about the visibility of a sink - * @param sinkID the sinkID - * @return true if source is visible - */ -bool CAmDatabaseHandlerMap::sinkVisible(const am_sinkID_t sinkID) const -{ - am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=source ) - { - if(0==source->reserved) - return source->visible; - } - return false; -} - -/** - * 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 CAmDatabaseHandlerMap::existConnection(const am_Connection_s & connection) const -{ - am_Connection_Database_s const * connectionObject = objectMatchingPredicate(mMappedData.mConnectionMap, [&](const am_Connection_Database_s & obj){ - return false==obj.reserved && - connection.sinkID == obj.sinkID && - connection.sourceID == obj.sourceID && - connection.connectionFormat == obj.connectionFormat; - }); - return ( NULL!=connectionObject ); -} - -/** - * checks if a connection with the given ID exists - * @param connectionID - * @return true if connection exits - */ -bool CAmDatabaseHandlerMap::existConnectionID(const am_connectionID_t connectionID) const -{ - am_Connection_Database_s const * connection = objectForKeyIfExistsInMap(connectionID, mMappedData.mConnectionMap); - if( NULL!=connection ) - { - return (0==connection->reserved); - } - return false; -} - -/** - * checks if a CrossFader exists - * @param crossfaderID the ID of the crossfader to be checked - * @return true if exists - */ -bool CAmDatabaseHandlerMap::existCrossFader(const am_crossfaderID_t crossfaderID) const -{ - return existsObjectWithKeyInMap(crossfaderID, mMappedData.mCrossfaderMap); -} - -am_Error_e CAmDatabaseHandlerMap::getSoureState(const am_sourceID_t sourceID, am_SourceState_e & sourceState) const -{ - am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=source ) - { - sourceState = source->sourceState; - return (E_OK); - } - else - { - sourceState = SS_UNKNNOWN; - return (E_NON_EXISTENT); - } -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) -{ - assert(sourceID!=0); - assert(sourceState>=SS_UNKNNOWN && sourceState<=SS_MAX); - if(existSource(sourceID)) - { - mMappedData.mSourceMap.at(sourceID).sourceState = sourceState; - return (E_OK); - } - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const { - assert(sinkID!=0); - - am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=source ) - { - mainVolume = source->mainVolume; - return (E_OK); - } - mainVolume = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getSinkVolume(const am_sinkID_t sinkID, am_volume_t & volume) const -{ - assert(sinkID!=0); - - am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=source ) - { - volume = source->volume; - return (E_OK); - } - volume = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getSourceVolume(const am_sourceID_t sourceID, am_volume_t & volume) const -{ - assert(sourceID!=0); - am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=source ) - { - volume = source->volume; - return (E_OK); - } - volume = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t & value) const -{ - assert(sinkID!=0); - - am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=pObject ) - { - if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) - { - std::vector::const_iterator iter = pObject->listSoundProperties.begin(); - for(; iterlistSoundProperties.end(); ++iter) - pObject->cacheSoundProperties[iter->type] = iter->value; - } - auto it = pObject->cacheSoundProperties.find(propertyType); - if(it!=pObject->cacheSoundProperties.end()) - { - value = it->second; - return (E_OK); - } - } - value = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t & value) const -{ - assert(sourceID!=0); - - am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=pObject ) - { - if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) - { - std::vector::const_iterator iter = pObject->listSoundProperties.begin(); - for(; iterlistSoundProperties.end(); ++iter) - pObject->cacheSoundProperties[iter->type] = iter->value; - } - auto it = pObject->cacheSoundProperties.find(propertyType); - if(it!=pObject->cacheSoundProperties.end()) - { - value = it->second; - return (E_OK); - } - } - value = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const -{ - assert(sinkID!=0); - - am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=pObject ) - { - if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) - { - std::vector::const_iterator iter = pObject->listMainSoundProperties.begin(); - for(; iterlistMainSoundProperties.end(); ++iter) - pObject->cacheMainSoundProperties[iter->type] = iter->value; - } - auto it = pObject->cacheMainSoundProperties.find(propertyType); - if(it!=pObject->cacheMainSoundProperties.end()) - { - value = it->second; - return (E_OK); - } - } - value = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const -{ - assert(sourceID!=0); - - am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=pObject ) - { - if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) - { - std::vector::const_iterator iter = pObject->listMainSoundProperties.begin(); - for(; iterlistMainSoundProperties.end(); ++iter) - pObject->cacheMainSoundProperties[iter->type] = iter->value; - } - auto it = pObject->cacheMainSoundProperties.find(propertyType); - if(it!=pObject->cacheMainSoundProperties.end()) - { - value = it->second; - return (E_OK); - } - } - - value = -1; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const -{ - assert(domainID!=0); - - am_Domain_Database_s const * source = objectForKeyIfExistsInMap(domainID, mMappedData.mDomainMap); - if( NULL!=source ) - { - state = source->state; - return (E_OK); - } - state = DS_UNKNOWN; - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::peekDomain(const std::string & name, am_domainID_t & domainID) -{ - domainID=0; - - am_Domain_Database_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const am_Domain_Database_s & obj){ - return name.compare(obj.name)==0; - }); - - if( NULL != reservedDomain ) - { - domainID = reservedDomain->domainID; - return E_OK; - } - else - { - int16_t nextID = 0; - if( mMappedData.increaseID( nextID, mMappedData.mCurrentDomainID) ) - { - domainID = nextID; - am_Domain_Database_s domain; - domain.domainID = nextID; - domain.name = name; - domain.reserved = 1; - mMappedData.mDomainMap[nextID] = domain; - return E_OK; - } - return E_UNKNOWN; - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::peekSink(const std::string & name, am_sinkID_t & sinkID) -{ - am_Sink_Database_s const *reservedSink = objectMatchingPredicate(mMappedData.mSinkMap, [&](const am_Sink_Database_s & obj){ - return name.compare(obj.name)==0; - }); - if( NULL!=reservedSink ) - { - sinkID = reservedSink->sinkID; - return E_OK; - } - else - { - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID)) - { - if(mFirstStaticSink) - { - nextID = DYNAMIC_ID_BOUNDARY; - mFirstStaticSink = false; - } - sinkID = nextID; - am_Sink_Database_s object; - object.sinkID = nextID; - object.name = name; - object.reserved = 1; - mMappedData.mSinkMap[nextID] = object; - return E_OK; - } - return E_UNKNOWN; - } -} - -am_Error_e CAmDatabaseHandlerMap::peekSource(const std::string & name, am_sourceID_t & sourceID) -{ - am_Source_Database_s const *reservedSrc = objectMatchingPredicate(mMappedData.mSourceMap, [&](const am_Source_Database_s & obj){ - return name.compare(obj.name)==0; - }); - if( NULL!=reservedSrc ) - { - sourceID = reservedSrc->sourceID; - return E_OK; - } - else - { - int16_t nextID = 0; - if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID)) - { - if(mFirstStaticSource) - { -// nextID = DYNAMIC_ID_BOUNDARY; - mFirstStaticSource = false; - } - sourceID = nextID; - am_Source_Database_s object; - object.sourceID = nextID; - object.name = name; - object.reserved = 1; - mMappedData.mSourceMap[nextID] = object; - return E_OK; - } - else - return E_UNKNOWN; - } -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mSinkMap[sinkID].volume = volume; - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume) -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - mMappedData.mSourceMap[sourceID].volume = volume; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - am_Source_Database_s & source = mMappedData.mSourceMap[sourceID]; - std::vector::iterator iter = source.listSoundProperties.begin(); - for(; itertype ) - { - iter->value = soundProperty.value; - if(source.cacheSoundProperties.size()) - source.cacheSoundProperties[soundProperty.type] = soundProperty.value; - return (E_OK); - } - } - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; - std::vector::iterator iter = sink.listSoundProperties.begin(); - for(; itertype ) - { - iter->value = soundProperty.value; - if(sink.cacheSoundProperties.size()) - sink.cacheSoundProperties[soundProperty.type] = soundProperty.value; - return (E_OK); - } - } - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) -{ - assert(crossfaderID!=0); - assert(hotsink!=HS_UNKNOWN); - - if (!existCrossFader(crossfaderID)) - { - return (E_NON_EXISTENT); - } - - mMappedData.mCrossfaderMap[crossfaderID].hotSink = hotsink; - return (E_OK); -} - -bool CAmDatabaseHandlerMap::isComponentConnected(const am_Gateway_s & gateway) const -{ - bool ret = isConnected(gateway); - return ret; -} - -bool CAmDatabaseHandlerMap::isComponentConnected(const am_Converter_s & converter) const -{ - bool ret = isConnected(converter); - return ret; -} - -am_Error_e am::CAmDatabaseHandlerMap::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID) -{ - if (name.empty()) - return (E_NON_EXISTENT); - am_SinkClass_Database_s const *reserved = objectMatchingPredicate(mMappedData.mSinkClassesMap, [&](const am_SinkClass_Database_s & obj){ - return name.compare(obj.name)==0; - }); - if( NULL!=reserved ) - { - sinkClassID = reserved->sinkClassID; - return E_OK; - } - return (E_NON_EXISTENT); -} - -am_Error_e am::CAmDatabaseHandlerMap::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID) -{ - if (name.empty()) - return (E_NON_EXISTENT); - am_SourceClass_Database_s const *ptrSource = objectMatchingPredicate(mMappedData.mSourceClassesMap, [&](const am_SourceClass_Database_s & obj){ - return name.compare(obj.name)==0; - }); - if( NULL!=ptrSource ) - { - sourceClassID = ptrSource->sourceClassID; - return E_OK; - } - return (E_NON_EXISTENT); -} - - -am_Error_e CAmDatabaseHandlerMap::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - DB_COND_UPDATE_INIT; - am_sourceClass_t sourceClassOut(sourceClassID); - std::vector listMainSoundPropertiesOut(listMainSoundProperties); - //check if sinkClass needs to be changed - - std::unordered_map::iterator iter = mMappedData.mSourceMap.begin(); - for(; iter!=mMappedData.mSourceMap.end(); ++iter) - { - if( iter->second.sourceID == sourceID ) - { - if (sourceClassID != 0) - { - DB_COND_UPDATE(iter->second.sourceClassID, sourceClassID); - } - else if (0 == iter->second.reserved) - { - sourceClassOut = iter->second.sourceClassID; - } - break; - } - } - - //check if soundProperties need to be updated - if (!listSoundProperties.empty()) - { - mMappedData.mSourceMap.at(sourceID).listSoundProperties = listSoundProperties; - mMappedData.mSourceMap.at(sourceID).cacheSoundProperties.clear(); - } - - //check if we have to update the list of connectionformats - if (!listConnectionFormats.empty()) - { - mMappedData.mSourceMap.at(sourceID).listConnectionFormats = listConnectionFormats; - } - - //then we need to check if we need to update the listMainSoundProperties - if (sourceVisible(sourceID)) - { - if (!listMainSoundProperties.empty()) - { - DB_COND_UPDATE(mMappedData.mSourceMap.at(sourceID).listMainSoundProperties, listMainSoundProperties); - mMappedData.mSourceMap.at(sourceID).cacheMainSoundProperties.clear(); - } - else - { - getListMainSourceSoundProperties(sourceID,listMainSoundPropertiesOut); - } - } - - if (DB_COND_ISMODIFIED) - { - logInfo("DatabaseHandler::changeSource changed changeSource of source:", sourceID); - - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sourceUpdated(sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID)); - } - } - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(sinkID!=0); - - DB_COND_UPDATE_INIT; - am_sinkClass_t sinkClassOut(sinkClassID); - std::vector listMainSoundPropertiesOut(listMainSoundProperties); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - std::unordered_map::iterator iter = mMappedData.mSinkMap.begin(); - for(; iter!=mMappedData.mSinkMap.end(); ++iter) - { - if (iter->second.sinkID == sinkID) - { - if (sinkClassID != 0) - { - DB_COND_UPDATE(iter->second.sinkClassID, sinkClassID); - } - else if (0 == iter->second.reserved) - { - sinkClassOut = iter->second.sinkClassID; - } - break; - } - } - - //check if soundProperties need to be updated - if (!listSoundProperties.empty()) - { - mMappedData.mSinkMap.at(sinkID).listSoundProperties = listSoundProperties; - mMappedData.mSinkMap.at(sinkID).cacheSoundProperties.clear(); - } - - //check if we have to update the list of connectionformats - if (!listConnectionFormats.empty()) - { - mMappedData.mSinkMap.at(sinkID).listConnectionFormats = listConnectionFormats; - } - - //then we need to check if we need to update the listMainSoundProperties - if (sinkVisible(sinkID)) - { - if (!listMainSoundProperties.empty()) - { - DB_COND_UPDATE(mMappedData.mSinkMap.at(sinkID).listMainSoundProperties, listMainSoundProperties); - mMappedData.mSinkMap.at(sinkID).cacheMainSoundProperties.clear(); - } - else //read out the properties - { - getListMainSinkSoundProperties(sinkID,listMainSoundPropertiesOut); - } - } - - if (DB_COND_ISMODIFIED) - { - logInfo("DatabaseHandler::changeSink changed changeSink of sink:", sinkID); - - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sinkUpdated(sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID)); - } - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences - listMainNotificationConfigurations.clear(); - - listMainNotificationConfigurations = mMappedData.mSinkMap.at(sinkID).listMainNotificationConfigurations; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences - - listMainNotificationConfigurations = mMappedData.mSourceMap.at(sourceID).listMainNotificationConfigurations; - - return (E_OK); -} - -bool changeMainNotificationConfiguration(std::vector & listMainNotificationConfigurations, - const am_NotificationConfiguration_s & mainNotificationConfiguration) -{ - std::vector::iterator iter = listMainNotificationConfigurations.begin(); - for(; itertype ) - { -#ifdef WITH_DATABASE_CHANGE_CHECK - if( iter->status == mainNotificationConfiguration.status && iter->parameter == mainNotificationConfiguration.parameter ) - return false; -#endif - *iter = mainNotificationConfiguration; - return true; - } - } - return false; -} - -am_Error_e CAmDatabaseHandlerMap::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - if(!changeMainNotificationConfiguration(mMappedData.mSinkMap.at(sinkID).listMainNotificationConfigurations, mainNotificationConfiguration)) - return (E_NO_CHANGE); - - logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - if(!changeMainNotificationConfiguration(mMappedData.mSourceMap.at(sourceID).listMainNotificationConfigurations, mainNotificationConfiguration)) - return (E_NO_CHANGE); - - logInfo("DatabaseHandler::changeMainSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - - if (mpDatabaseObserver) - mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - assert(gatewayID!=0); - - if (!existGateway(gatewayID)) - { - return (E_NON_EXISTENT); - } - - if (!listSourceConnectionFormats.empty()) - { - mMappedData.mGatewayMap.at(gatewayID).listSourceFormats = listSourceConnectionFormats; - } - - if (!listSinkConnectionFormats.empty()) - { - mMappedData.mGatewayMap.at(gatewayID).listSinkFormats = listSinkConnectionFormats; - } - - if (!convertionMatrix.empty()) - { - mListConnectionFormat.clear(); - mListConnectionFormat.insert(std::make_pair(gatewayID, convertionMatrix)); - } - - logInfo("DatabaseHandler::changeGatewayDB changed Gateway with ID", gatewayID); - - //todo: check if observer needs to be adopted. - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerMap::changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - assert(converterID!=0); - - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - - if (!listSourceConnectionFormats.empty()) - { - mMappedData.mConverterMap.at(converterID).listSourceFormats = listSourceConnectionFormats; - } - - if (!listSinkConnectionFormats.empty()) - { - mMappedData.mConverterMap.at(converterID).listSinkFormats = listSinkConnectionFormats; - } - - if (!convertionMatrix.empty()) - { - mListConnectionFormat.clear(); - mListConnectionFormat.insert(std::make_pair(converterID, convertionMatrix)); - } - - logInfo("DatabaseHandler::changeConverterDB changed Gateway with ID", converterID); - - //todo: check if observer needs to be adopted. - return (E_OK); -} - -bool changeNotificationConfiguration(std::vector & listNotificationConfigurations, const am_NotificationConfiguration_s & notificationConfiguration) -{ - bool changed = false; - std::vector::iterator iter = listNotificationConfigurations.begin(); - for(; itertype ) - { - iter->status = notificationConfiguration.status; - iter->parameter = notificationConfiguration.parameter; - changed |= true; - } - } - return changed; -} - -am_Error_e CAmDatabaseHandlerMap::changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s notificationConfiguration) -{ - assert(sinkID!=0); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - if(!changeNotificationConfiguration(mMappedData.mSinkMap.at(sinkID).listNotificationConfigurations, notificationConfiguration)) - return (E_NO_CHANGE); - - logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); - - //todo:: inform obsever here... - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s notificationConfiguration) -{ - assert(sourceID!=0); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - if(!changeNotificationConfiguration(mMappedData.mSourceMap.at(sourceID).listNotificationConfigurations, notificationConfiguration)) - return (E_NO_CHANGE); - - logInfo("DatabaseHandler::changeSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); - - //todo:: implement observer function - return (E_NON_EXISTENT); -} - -am_Error_e CAmDatabaseHandlerMap::enumerateSources(std::function cb) const -{ - for(auto it = mMappedData.mSourceMap.begin(); it!=mMappedData.mSourceMap.end(); it++) - { - const am_Source_Database_s *pObject = &it->second; - if( 0==pObject->reserved ) - cb(*pObject); - } - return E_OK; -} - -am_Error_e CAmDatabaseHandlerMap::enumerateSinks(std::function cb) const -{ - for(auto it = mMappedData.mSinkMap.begin(); it!=mMappedData.mSinkMap.end(); it++) - { - const am_Sink_Database_s *pObject = &it->second; - if( 0==pObject->reserved ) - cb(*pObject); - } - return E_OK; -} - -am_Error_e CAmDatabaseHandlerMap::enumerateGateways(std::function cb) const -{ - for(auto it = mMappedData.mGatewayMap.begin(); it!=mMappedData.mGatewayMap.end(); it++) - { - const am_Gateway_s *pObject = &it->second; - cb(*pObject); - } - return E_OK; -} - -am_Error_e CAmDatabaseHandlerMap::enumerateConverters(std::function cb) const -{ - for(auto it = mMappedData.mConverterMap.begin(); it!=mMappedData.mConverterMap.end(); it++) - { - const am_Converter_s *pObject = &it->second; - cb(*pObject); - } - return E_OK; -} - -} diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp deleted file mode 100644 index 5e95c6c..0000000 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp +++ /dev/null @@ -1,5651 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseHandlerSQLite.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmDatabaseHandlerSQLite.h" -#include -#include -#include -#include -#include -#include -#include "CAmDatabaseObserver.h" -#include "CAmRouter.h" -#include "CAmDltWrapper.h" -#include - -namespace am -{ - -/** - * Macro to handle SQLITE errors on prepare - */ -#define MY_SQLITE_PREPARE_V2(db,zSql,nByte,ppStmt,pzTail) \ - if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \ - { \ - logError("CAmDatabaseHandler::my_sqlite_prepare_v2 on Command",zSql,"failed with errorCode:", eCode); \ - return (E_DATABASE_ERROR); \ - } - -#define MY_SQLITE_PREPARE_V2_BOOL(db,zSql,nByte,ppStmt,pzTail) \ - if ((eCode = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail))) \ - { \ - logError("CAmDatabaseHandler::my_sqlite_prepare_v2_bool on Command",zSql,"failed with errorCode:", eCode); \ - return (false); \ - } - -/** - * Macro to handle SQLITE errors bind text - */ -#define MY_SQLITE_BIND_TEXT(query,index,text,size,static_) \ - if ((eCode = sqlite3_bind_text(query, index, text, size, static_))) \ - { \ - logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); \ - return (E_DATABASE_ERROR); \ - } - -/** - * Macro to handle SQLITE errors on bind int - */ -#define MY_SQLITE_BIND_INT(query, index, data) \ - if((eCode = sqlite3_bind_int(query, index, data))) \ - { \ - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); \ - return (E_DATABASE_ERROR); \ - } - -/** - * Macro to handle SQLITE errors on reset - */ -#define MY_SQLITE_RESET(query) \ - if((eCode = sqlite3_reset(query))) \ - { \ - logError("CAmDatabaseHandler::sqlite3_reset failed with errorCode:", eCode); \ - return (E_DATABASE_ERROR); \ - } - -/** - * Macro to handle SQLITE finalize - */ -#define MY_SQLITE_FINALIZE(query) \ - if((eCode = sqlite3_finalize(query))) \ - { \ - logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \ - return (E_DATABASE_ERROR); \ - } - -#define MY_SQLITE_FINALIZE_BOOL(query) \ - if((eCode = sqlite3_finalize(query))) \ - { \ - logError("CAmDatabaseHandler::sqlite3_finalize failed with errorCode:", eCode); \ - return (true); \ - } - -#define DOMAIN_TABLE "Domains" //!< domain table -#define SOURCE_CLASS_TABLE "SourceClasses" //!< source class table -#define SINK_CLASS_TABLE "SinkClasses" //!< sink class table -#define SOURCE_TABLE "Sources" //!< source table -#define SINK_TABLE "Sinks" //!< sink table -#define GATEWAY_TABLE "Gateways" //!< gateway table -#define CONVERTER_TABLE "Converters" //!< converter table -#define CROSSFADER_TABLE "Crossfaders" //!< crossfader table -#define CONNECTION_TABLE "Connections" //!< connection table -#define MAINCONNECTION_TABLE "MainConnections" //!< main connection table -#define SYSTEM_TABLE "SystemProperties" //!< system properties table -/** - * table that holds table informations - */ -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);", // - " Converters (converterID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainID 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 x T - * @return string - */ -template -inline std::string i2s(T const& x) -{ - std::ostringstream o; - o << x; - return (o.str()); -} - -CAmDatabaseHandlerSQLite::CAmDatabaseHandlerSQLite():mpDatabaseObserver(NULL), // - mFirstStaticSink(true), // - mFirstStaticSource(true), // - mFirstStaticGateway(true), // - mFirstStaticConverter(true), - mFirstStaticSinkClass(true), // - mFirstStaticSourceClass(true), // - mFirstStaticCrossfader(true), // - mListConnectionFormat(), - mpDatabase(NULL), // - mPath(std::string("")) -{ - -} - -CAmDatabaseHandlerSQLite::CAmDatabaseHandlerSQLite(std::string databasePath):mpDatabaseObserver(NULL), // - mFirstStaticSink(true), // - mFirstStaticSource(true), // - mFirstStaticGateway(true), // - mFirstStaticConverter(true), - mFirstStaticSinkClass(true), // - mFirstStaticSourceClass(true), // - mFirstStaticCrossfader(true), // - mListConnectionFormat(), - mpDatabase(NULL), // - mPath(databasePath) -{ - std::ifstream infile(mPath.c_str()); - - if (infile) - { - if(remove(mPath.c_str())==0) - { - logError("DatabaseHandler::DatabaseHandler Knocked down database failed !"); - } - logInfo("DatabaseHandler::DatabaseHandler Knocked down database"); - } - - bool dbOpen = openDatabase(); - if (!dbOpen) - { - logInfo("DatabaseHandler::DatabaseHandler problems opening the database!"); - } - - createTables(); -} - -CAmDatabaseHandlerSQLite::~CAmDatabaseHandlerSQLite() -{ - logInfo("Closed Database"); - mpDatabaseObserver = NULL; - if(mpDatabase) - sqlite3_close(mpDatabase); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - int eCode = 0; - domainID=0; - std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC) - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - domainID = sqlite3_column_int(query, 0); - 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); - } - - MY_SQLITE_FINALIZE(query) - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_TEXT(query, 1, domainData.name.c_str(), domainData.name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_TEXT(query, 2, domainData.busname.c_str(), domainData.busname.size(), SQLITE_STATIC) - MY_SQLITE_BIND_TEXT(query, 3, domainData.nodename.c_str(), domainData.nodename.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(query, 4, domainData.early) - MY_SQLITE_BIND_INT(query, 5, domainData.complete) - MY_SQLITE_BIND_INT(query, 6, domainData.state) - MY_SQLITE_BIND_INT(query, 7, 0) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterDomainDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - if (domainID==0) - domainID = sqlite3_last_insert_rowid(mpDatabase); - 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 (mpDatabaseObserver) - mpDatabaseObserver->newDomain(domain); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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)"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, mainConnectionData.sourceID) - MY_SQLITE_BIND_INT(query, 2, mainConnectionData.sinkID) - MY_SQLITE_BIND_INT(query, 3, mainConnectionData.connectionState) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - connectionID = sqlite3_last_insert_rowid(mpDatabase); - - //now check the connectionTable for all connections in the route. IF connectionID exist - command = "SELECT delay FROM " + std::string(CONNECTION_TABLE) + (" WHERE connectionID=?"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator elementIterator = mainConnectionData.listConnectionID.begin(); - for (; elementIterator < mainConnectionData.listConnectionID.end(); ++elementIterator) - { - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - //now we create a table with references to the connections; - command = "CREATE TABLE MainConnectionRoute" + i2s(connectionID) + std::string("(connectionID INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO MainConnectionRoute" + i2s(connectionID) + "(connectionID) VALUES (?)"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator listConnectionIterator(mainConnectionData.listConnectionID.begin()); - for (; listConnectionIterator < mainConnectionData.listConnectionID.end(); ++listConnectionIterator) - { - MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterMainConnectionDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); - - if (mpDatabaseObserver) - { - am_MainConnectionType_s mainConnection; - mainConnection.mainConnectionID = connectionID; - mainConnection.connectionState = mainConnectionData.connectionState; - mainConnection.delay = delay; - mainConnection.sinkID = mainConnectionData.sinkID; - mainConnection.sourceID = mainConnectionData.sourceID; - mpDatabaseObserver->newMainConnection(mainConnection); - mpDatabaseObserver->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 CAmDatabaseHandlerSQLite::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - assert(sinkData.sinkID=MS_UNKNOWN && sinkData.muteState<=MS_MAX); - - sqlite3_stmt *query = NULL; - int eCode = 0; - std::string command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=? AND reserved=1"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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)) - { - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_TEXT(query, 1, sinkData.name.c_str(), sinkData.name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(query, 2, sinkData.domainID) - MY_SQLITE_BIND_INT(query, 3, sinkData.sinkClassID) - MY_SQLITE_BIND_INT(query, 4, sinkData.volume) - MY_SQLITE_BIND_INT(query, 5, sinkData.visible) - MY_SQLITE_BIND_INT(query, 6, sinkData.available.availability) - MY_SQLITE_BIND_INT(query, 7, sinkData.available.availabilityReason) - MY_SQLITE_BIND_INT(query, 8, sinkData.muteState) - MY_SQLITE_BIND_INT(query, 9, sinkData.mainVolume) - MY_SQLITE_BIND_INT(query, 10, 0) - - //if the ID is not created, we add it to the query - if (sinkData.sinkID != 0) - { - MY_SQLITE_BIND_INT(query, 11, sinkData.sinkID) - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticSink) - { - MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY) - mFirstStaticSink = false; - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //now read back the sinkID - command = "SELECT sinkID FROM " + std::string(SINK_TABLE) + " WHERE name=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - //now we need to create the additional tables: - command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE SinkNotificationConfiguration" + i2s(sinkID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = sinkData.listConnectionFormats.begin(); - for (; connectionFormatIterator < sinkData.listConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - //Fill SinkSoundProperties - command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator SoundPropertyIterator = sinkData.listSoundProperties.begin(); - for (; SoundPropertyIterator < sinkData.listSoundProperties.end(); ++SoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - //Fill NotificationConfigurations - command = "INSERT INTO SinkNotificationConfiguration" + i2s(sinkID) + std::string("(type,status,parameter) VALUES (?,?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator NotificationConfigurationIterator(sinkData.listNotificationConfigurations.begin()); - for (; NotificationConfigurationIterator < sinkData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator) - { - MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->type) - MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->status) - MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - if (sinkData.visible == true) - { - command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - //now we got MainNotificationConfigurations as well - command = "CREATE TABLE SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(type,status,parameter) VALUES (?,?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainNotificationConfigurationIterator(sinkData.listMainNotificationConfigurations.begin()); - for (; mainNotificationConfigurationIterator < sinkData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->status) - MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(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 (mpDatabaseObserver != NULL) - mpDatabaseObserver->newSink(sink); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (?,?,?,?,?,?)"; - } - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - MY_SQLITE_BIND_TEXT(query, 1, crossfaderData.name.c_str(), crossfaderData.name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(query, 2, crossfaderData.sinkID_A) - MY_SQLITE_BIND_INT(query, 3, crossfaderData.sinkID_B) - MY_SQLITE_BIND_INT(query, 4, crossfaderData.sourceID) - MY_SQLITE_BIND_INT(query, 5, crossfaderData.hotSink) - - //if the ID is not created, we add it to the query - if (crossfaderData.crossfaderID != 0) - { - MY_SQLITE_BIND_INT(query, 6, crossfaderData.crossfaderID) - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticCrossfader) - { - MY_SQLITE_BIND_INT(query, 6, DYNAMIC_ID_BOUNDARY) - mFirstStaticCrossfader = false; - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterCrossfaderDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //now read back the crossfaderID - command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE name=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_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 (mpDatabaseObserver) - mpDatabaseObserver->newCrossfader(crossfader); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - assert(gatewayData.gatewayIDsqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = gatewayData.listSourceFormats.begin(); - for (; connectionFormatIterator < gatewayData.listSourceFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - connectionFormatIterator = gatewayData.listSinkFormats.begin(); - for (; connectionFormatIterator < gatewayData.listSinkFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(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 (mpDatabaseObserver) - mpDatabaseObserver->newGateway(gateway); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID) -{ - assert(converterData.converterIDsqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO ConverterSourceFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = converterData.listSourceFormats.begin(); - for (; connectionFormatIterator < converterData.listSourceFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - command = "INSERT INTO ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - connectionFormatIterator = converterData.listSinkFormats.begin(); - for (; connectionFormatIterator < converterData.listSinkFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::enterConverterDB entered new gateway with name", converterData.name, "sourceID:", converterData.sourceID, "sinkID:", converterData.sinkID, "assigned ID:", converterID); - am_Converter_s converter = converterData; - converter.converterID = converterID; - if (mpDatabaseObserver) - mpDatabaseObserver->newConverter(converter); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - assert(sourceData.sourceID=SS_UNKNNOWN && sourceData.sourceState<=SS_MAX); - - sqlite3_stmt* query = NULL; - ; - int eCode = 0; - std::string command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=? AND reserved=1"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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)) - { - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_TEXT(query, 1, sourceData.name.c_str(), sourceData.name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(query, 2, sourceData.domainID) - MY_SQLITE_BIND_INT(query, 3, sourceData.sourceClassID) - MY_SQLITE_BIND_INT(query, 4, sourceData.sourceState) - MY_SQLITE_BIND_INT(query, 5, sourceData.volume) - MY_SQLITE_BIND_INT(query, 6, sourceData.visible) - MY_SQLITE_BIND_INT(query, 7, sourceData.available.availability) - MY_SQLITE_BIND_INT(query, 8, sourceData.available.availabilityReason) - MY_SQLITE_BIND_INT(query, 9, sourceData.interruptState) - MY_SQLITE_BIND_INT(query, 10, 0) - - //if the ID is not created, we add it to the query - if (sourceData.sourceID != 0) - { - MY_SQLITE_BIND_INT(query, 11, sourceData.sourceID) - } - - //if the first static sink is entered, we need to set it onto the boundary - else if (mFirstStaticSource) - { - MY_SQLITE_BIND_INT(query, 11, DYNAMIC_ID_BOUNDARY) - mFirstStaticSource = false; - } - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //now read back the sinkID - command = "SELECT sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE name=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - //now we need to create the additional tables: - command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - command = "CREATE TABLE SourceNotificationConfiguration" + i2s(sourceID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = sourceData.listConnectionFormats.begin(); - for (; connectionFormatIterator != sourceData.listConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - //Fill SinkSoundProperties - command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator SoundPropertyIterator = sourceData.listSoundProperties.begin(); - for (; SoundPropertyIterator != sourceData.listSoundProperties.end(); ++SoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - //Fill NotificationConfigurations - command = "INSERT INTO SourceNotificationConfiguration" + i2s(sourceID) + std::string("(type,status,parameter) VALUES (?,?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator NotificationConfigurationIterator(sourceData.listNotificationConfigurations.begin()); - for (; NotificationConfigurationIterator < sourceData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator) - { - MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->type) - MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->status) - MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - if (sourceData.visible == true) - { - command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator != sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - - //now we got MainNotificationConfigurations as well - command = "CREATE TABLE SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(type INTEGER, status INTEGER, parameter INTEGER)"); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(type,status,parameter) VALUES (?,?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainNotificationConfigurationIterator(sourceData.listMainNotificationConfigurations.begin()); - for (; mainNotificationConfigurationIterator != sourceData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->status) - MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(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 (mpDatabaseObserver) - mpDatabaseObserver->newSource(source); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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=?"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator elementIterator = listConnectionID.begin(); - for (; elementIterator < listConnectionID.end(); ++elementIterator) - { - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - //now we delete the data in the table - command = "DELETE from MainConnectionRoute" + i2s(mainconnectionID); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO MainConnectionRoute" + i2s(mainconnectionID) + "(connectionID) VALUES (?)"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator listConnectionIterator(listConnectionID.begin()); - for (; listConnectionIterator != listConnectionID.end(); ++listConnectionIterator) - { - MY_SQLITE_BIND_INT(query, 1, *listConnectionIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainConnectionRouteDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - if (changeDelayMainConnection(delay,mainconnectionID)!=E_OK) - logError("DatabaseHandler::changeMainConnectionRouteDB error while changing mainConnectionDelay to ", delay); - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeMainConnectionRouteDB entered new route:", mainconnectionID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, connectionState) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainConnectionStateDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); - - if (mpDatabaseObserver) - mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, mainVolume) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkMainVolumeDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); - - if (mpDatabaseObserver) - mpDatabaseObserver->volumeChanged(sinkID, mainVolume); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) -{ - assert(sinkID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, availability.availability) - MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkAvailabilityDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - assert(sinkID!=0); - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mpDatabaseObserver && sourceVisible(sinkID)) - mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, domainState) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changDomainStateDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changDomainStateDB changed domainState of domain:", domainID, "to:", domainState); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, muteState) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkMuteStateDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - assert(sinkID!=0); - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); - - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, 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 SinkMainSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, soundProperty.value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSinkSoundPropertyDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - assert(sinkID!=0); - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - if (mpDatabaseObserver) - mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - 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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, soundProperty.value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSourceSoundPropertyDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - - if (mpDatabaseObserver) - mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) -{ - assert(sourceID!=0); - assert(availability.availability>=A_UNKNOWN && availability.availability<=A_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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, availability.availability) - MY_SQLITE_BIND_INT(query, 2, availability.availabilityReason) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceAvailabilityDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); - - if (mpDatabaseObserver && sourceVisible(sourceID)) - mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSystemPropertyDB(const am_SystemProperty_s & property) -{ - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, property.value) - MY_SQLITE_BIND_INT(query, 2, property.type) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSystemPropertyDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeSystemPropertyDB changed system property"); - - if (mpDatabaseObserver) - mpDatabaseObserver->systemPropertyChanged(property); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (mpDatabaseObserver) - { - mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); - mpDatabaseObserver->removedMainConnection(mainConnectionID); - } - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 SinkSoundProperty" + i2s(sinkID); - std::string command3 = "DROP table SinkMainSoundProperty" + i2s(sinkID); - std::string command4 = "DROP table SinkNotificationConfiguration" + i2s(sinkID); - std::string command5 = "DROP table SinkMainNotificationConfiguration" + 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(command4)) - return (E_DATABASE_ERROR); - if (visible) //only drop table if it ever existed - { - if (!sqQuery(command3)) - return (E_DATABASE_ERROR); - if (!sqQuery(command5)) - return (E_DATABASE_ERROR); - } - logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); - - if (mpDatabaseObserver != NULL) - mpDatabaseObserver->removedSink(sinkID, visible); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - std::string command4 = "DROP table SourceNotificationConfiguration" + i2s(sourceID); - std::string command5 = "DROP table SourceMainNotificationConfiguration" + i2s(sourceID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - if (!sqQuery(command1)) - return (E_DATABASE_ERROR); - if (!sqQuery(command3)) - return (E_DATABASE_ERROR); - if (!sqQuery(command4)) - return (E_DATABASE_ERROR); - - if(visible) - { - if (!sqQuery(command2)) - return (E_DATABASE_ERROR); - if (!sqQuery(command5)) - return (E_DATABASE_ERROR); - } - logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); - if (mpDatabaseObserver) - mpDatabaseObserver->removedSource(sourceID, visible); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (mpDatabaseObserver) - mpDatabaseObserver->removeGateway(gatewayID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::removeConverterDB(const am_converterID_t converterID) -{ - assert(converterID!=0); - - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - std::string command = "DELETE from " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - logInfo("DatabaseHandler::removeConverterDB removed:", converterID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeConverter(converterID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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::removeCrossfaderDB removed:", crossfaderID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeCrossfader(crossfaderID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (mpDatabaseObserver) - mpDatabaseObserver->removeDomain(domainID); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (mpDatabaseObserver) - mpDatabaseObserver->numberOfSinkClassesChanged(); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (mpDatabaseObserver) - mpDatabaseObserver->numberOfSourceClassesChanged(); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 CAmDatabaseHandlerSQLite::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)); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - command = "SELECT name FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE sourceClassID=" + (i2s(classInfo.sourceClassID)); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //read out Properties - command = "SELECT classProperty, value FROM SourceClassProperties" + i2s(classInfo.sourceClassID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_CustomClassProperty_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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, *qMainNotification = NULL, *qNotification = NULL; - int eCode = 0; - am_CustomConnectionFormat_t tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - am_NotificationConfiguration_s tempNotificationConfiguration,tempMainNotification; - 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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 5); - sinkData.available.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - sinkData.listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL) - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - sinkData.listSoundProperties.push_back(tempSoundProperty); - } - - MY_SQLITE_FINALIZE(qSoundProperty) - - std::string notificationCommand = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL) - - while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW) - { - tempNotificationConfiguration.type = static_cast(sqlite3_column_int(qNotification, 0)); - tempNotificationConfiguration.status = static_cast(sqlite3_column_int(qNotification, 1)); - tempNotificationConfiguration.parameter= static_cast(sqlite3_column_int(qNotification, 2)); - sinkData.listNotificationConfigurations.push_back(tempNotificationConfiguration); - } - MY_SQLITE_FINALIZE(qNotification) - - if (sinkData.visible) - { - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL) - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - sinkData.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - MY_SQLITE_FINALIZE(qMAinSoundProperty) - - std::string mainNotificationCommand = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL) - - while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW) - { - tempMainNotification.type = static_cast(sqlite3_column_int(qMainNotification, 0)); - tempMainNotification.status = static_cast(sqlite3_column_int(qMainNotification, 1)); - tempMainNotification.parameter= static_cast(sqlite3_column_int(qMainNotification, 2)); - sinkData.listMainNotificationConfigurations.push_back(tempMainNotification); - } - MY_SQLITE_FINALIZE(qMainNotification) - } - } - - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSinkInfoDB SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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, *qMainNotification = NULL, *qNotification = NULL; - int eCode = 0; - am_CustomConnectionFormat_t tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - am_NotificationConfiguration_s tempNotificationConfiguration,tempMainNotification; - 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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 6); - sourceData.available.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - sourceData.listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL); - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - sourceData.listSoundProperties.push_back(tempSoundProperty); - } - - MY_SQLITE_FINALIZE(qSoundProperty) - - std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL) - - while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW) - { - tempNotificationConfiguration.type = static_cast(sqlite3_column_int(qNotification, 0)); - tempNotificationConfiguration.status = static_cast(sqlite3_column_int(qNotification, 1)); - tempNotificationConfiguration.parameter= static_cast(sqlite3_column_int(qNotification, 2)); - sourceData.listNotificationConfigurations.push_back(tempNotificationConfiguration); - } - MY_SQLITE_FINALIZE(qNotification) - - if (sourceData.visible) - { - - //read out MainSoundProperties - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL) - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - sourceData.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - MY_SQLITE_FINALIZE(qMAinSoundProperty) - - std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL) - - while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW) - { - tempMainNotification.type = static_cast(sqlite3_column_int(qMainNotification, 0)); - tempMainNotification.status = static_cast(sqlite3_column_int(qMainNotification, 1)); - tempMainNotification.parameter= static_cast(sqlite3_column_int(qMainNotification, 2)); - sourceData.listMainNotificationConfigurations.push_back(tempMainNotification); - } - MY_SQLITE_FINALIZE(qMainNotification) - - } - } - else if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getSourceInfoDB SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::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"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_PREPARE_V2(mpDatabase, statement.c_str(), -1, &query1, NULL) - while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) - { - mainConnectionData.listConnectionID.push_back(sqlite3_column_int(query1, 0)); - } - MY_SQLITE_FINALIZE(query1) - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getMainConnectionInfoDB SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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=?;"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); - for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) - { - MY_SQLITE_BIND_INT(query, 1, Iterator->value) - MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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=?;"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator Iterator = sourceClass.listClassProperties.begin(); - for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) - { - MY_SQLITE_BIND_INT(query, 1, Iterator->value) - MY_SQLITE_BIND_INT(query, 2, Iterator->classProperty) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::setSinkClassInfoDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::setSinkClassInfoDB set setSinkClassInfo"); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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)); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - command = "SELECT name FROM " + std::string(SINK_CLASS_TABLE) + " WHERE sinkClassID=" + (i2s(sinkClass.sinkClassID)); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //read out Properties - command = "SELECT classProperty, value FROM SinkClassProperties" + i2s(sinkClass.sinkClassID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_CustomClassProperty_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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_CustomConnectionFormat_t tempConnectionFormat; - std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE gatewayID=" + i2s(gatewayID); - MY_SQLITE_PREPARE_V2(mpDatabase, 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"); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - gatewayData.convertionMatrix = iter->second; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(gatewayData.gatewayID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0); - gatewayData.listSourceFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSourceConnectionFormat) - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(gatewayData.gatewayID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0); - gatewayData.listSinkFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSinkConnectionFormat) - - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getGatewayInfoDB SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const -{ - assert(converterID!=0); - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; - int eCode = 0; - am_CustomConnectionFormat_t tempConnectionFormat; - std::string command = "SELECT name, sinkID, sourceID, domainID, converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - converterData.name = std::string((const char*) sqlite3_column_text(query, 0)); - converterData.sinkID = sqlite3_column_int(query, 1); - converterData.sourceID = sqlite3_column_int(query, 2); - converterData.domainID = sqlite3_column_int(query, 3); - converterData.converterID = sqlite3_column_int(query, 4); - - //convertionMatrix: - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(converterData.converterID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getConverterInfoDB database error with convertionFormat"); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - converterData.convertionMatrix = iter->second; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM ConverterSourceFormat" + i2s(converterData.converterID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0); - converterData.listSourceFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSourceConnectionFormat) - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM ConverterSinkFormat" + i2s(converterData.converterID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0); - converterData.listSinkFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSinkConnectionFormat) - - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getConverterInfoDB SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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)); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListConvertersOfDomain(const am_domainID_t domainID, std::vector& listConvertersID) const -{ - assert(domainID!=0); - listConvertersID.clear(); - if (!existDomain(domainID)) - { - return (E_NON_EXISTENT); - } - sqlite3_stmt* query = NULL; - int eCode = 0; - am_gatewayID_t temp; - - std::string command = "SELECT converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE domainID=" + i2s(domainID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp = sqlite3_column_int(query, 0); - listConvertersID.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListConvertersOfDomain SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query1) - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListMainConnections SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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_CustomConnectionFormat_t) sqlite3_column_int(query, 4); - listConnections.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListConnections SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListSinks(std::vector & listSinks) const -{ - listSinks.clear(); - return enumerateSinks([&](const am_Sink_s & sink){ listSinks.push_back(sink);}); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListSources(std::vector & listSources) const -{ - listSources.clear(); - return enumerateSources([&](const am_Source_s & source){ listSources.push_back(source);}); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL) - - while ((eCode1 = sqlite3_step(subQuery)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_CustomClassProperty_t) 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); - MY_SQLITE_FINALIZE(query) - MY_SQLITE_FINALIZE(subQuery) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(subQuery) - - listSourceClasses.push_back(classTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(subQuery) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListGateways(std::vector & listGateways) const -{ - listGateways.clear(); - return enumerateGateways([&](const am_Gateway_s & gateway){ listGateways.push_back(gateway);}); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListConverters(std::vector & listConverters) const -{ - listConverters.clear(); - return enumerateConverters([&](const am_Converter_s & converter){ listConverters.push_back(converter);}); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_PREPARE_V2(mpDatabase, command2.c_str(), -1, &subQuery, NULL) - - while ((eCode = sqlite3_step(subQuery)) == SQLITE_ROW) - { - propertyTemp.classProperty = (am_CustomClassProperty_t) 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); - } - - MY_SQLITE_FINALIZE(subQuery) - - listSinkClasses.push_back(classTemp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceClasses SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 2); - temp.availability.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 AND reserved=0"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 2); - temp.availability.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_CustomMainSoundPropertyType_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSourceProperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListMainSourceSoundProperties SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListSinkSoundProperties(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_SoundProperty_s temp; - std::string command = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSoundproperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinkSoundProperties SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - 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_SoundProperty_s temp; - std::string command = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(query, 0); - temp.value = sqlite3_column_int(query, 1); - listSoundproperties.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceSoundProperties SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = (am_CustomSystemPropertyType_t) 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector & listConnectionFormats) const -{ - listConnectionFormats.clear(); - sqlite3_stmt *qConnectionFormat = NULL; - int eCode = 0; - am_CustomConnectionFormat_t tempConnectionFormat; - std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector & listConnectionFormats) const -{ - listConnectionFormats.clear(); - sqlite3_stmt* qConnectionFormat = NULL; - int eCode = 0; - am_CustomConnectionFormat_t tempConnectionFormat; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - return (E_OK); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::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 am::CAmDatabaseHandlerSQLite::getListConverterConnectionFormats(const am_converterID_t converterID, std::vector & listConnectionFormat) const -{ - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(converterID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getListConverterConnectionFormats database error with convertionFormat"); - - return (E_DATABASE_ERROR); - } - listConnectionFormat = iter->second; - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - if (delay == -1) - return (E_NOT_POSSIBLE); - - return (E_OK); -} - -bool CAmDatabaseHandlerSQLite::sqQuery(const std::string& query) -{ - sqlite3_stmt* statement; - int eCode = 0; - if ((eCode = sqlite3_exec(mpDatabase, 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 CAmDatabaseHandlerSQLite::openDatabase() -{ - if (sqlite3_open_v2(mPath.c_str(), &mpDatabase, 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 CAmDatabaseHandlerSQLite::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=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, delay) - MY_SQLITE_BIND_INT(query, 2, connectionID) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - MY_SQLITE_FINALIZE(query) - return (E_OK); - } - command = "UPDATE " + std::string(MAINCONNECTION_TABLE) + " SET delay=? WHERE mainConnectionID=?;"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, delay) - MY_SQLITE_BIND_INT(query, 2, connectionID) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeDelayMainConnection SQLITE Step error code:", eCode); - - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - if (mpDatabaseObserver) - mpDatabaseObserver->timingInformationChanged(connectionID, delay); - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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 (?,?,?,?,?)"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, connection.sinkID) - MY_SQLITE_BIND_INT(query, 2, connection.sourceID) - MY_SQLITE_BIND_INT(query, 3, connection.delay) - MY_SQLITE_BIND_INT(query, 4, connection.connectionFormat) - MY_SQLITE_BIND_INT(query, 5, true) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConnectionDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - connectionID = sqlite3_last_insert_rowid(mpDatabase); - - 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 CAmDatabaseHandlerSQLite::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID) -{ - assert(sinkClass.sinkClassIDsqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SinkClassProperties" + i2s(sinkClassID) + std::string("(classProperty,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator Iterator = sinkClass.listClassProperties.begin(); - for (; Iterator < sinkClass.listClassProperties.end(); ++Iterator) - { - MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty) - MY_SQLITE_BIND_INT(query, 2, Iterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkClassDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::enterSinkClassDB entered new sinkClass"); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSinkClassesChanged(); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass) -{ - assert(sourceClass.sourceClassIDsqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SourceClassProperties" + i2s(sourceClassID) + std::string("(classProperty,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator Iterator = sourceClass.listClassProperties.begin(); - for (; Iterator < sourceClass.listClassProperties.end(); ++Iterator) - { - MY_SQLITE_BIND_INT(query, 1, Iterator->classProperty) - MY_SQLITE_BIND_INT(query, 2, Iterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceClassDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::enterSourceClassDB entered new sourceClass"); - - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSourceClassesChanged(); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - if (!this->sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO " + std::string(SYSTEM_TABLE) + " (type, value) VALUES (?,?)"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - for (; listIterator < listSystemProperties.end(); ++listIterator) - { - MY_SQLITE_BIND_INT(query, 1, listIterator->type) - MY_SQLITE_BIND_INT(query, 2, listIterator->value) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSystemProperties SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_RESET(query) - } - - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::enterSystemProperties entered system properties"); - return (E_OK); -} - -/** - * checks for a certain mainConnection - * @param mainConnectionID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks for a certain Source - * @param sourceID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks if a source name or ID exists - * @param sourceID the sourceID - * @param name the name - * @return true if it exits - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC))) - { - logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_bind_int(query, 2, sourceID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSource database error!:", eCode); - } - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks if a name exits - * @param name the name - * @return true if it exits - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC))) - { - logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSource database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks for a certain Sink - * @param sinkID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * 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 CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC))) - { - logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_bind_int(query, 2, sinkID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSink database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks if a sink with the name exists - * @param name the name - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC))) - { - logError("CAmDatabaseHandler::sqlite3_bind_text failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existSink database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks for a certain domain - * @param domainID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks for certain gateway - * @param gatewayID to be checked for - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -bool CAmDatabaseHandlerSQLite::existConverter(const am_converterID_t converterID) const -{ - sqlite3_stmt* query = NULL; - std::string command = "SELECT converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID); - int eCode = 0; - bool returnVal = true; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existConverter database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE(query) - return (returnVal); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE(query) - return (returnVal); -} - -am_Error_e CAmDatabaseHandlerSQLite::getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const -{ - assert(crossfader!=0); - - am_sourceID_t sourceID = 0; - sqlite3_stmt* query = NULL; - std::string command = "SELECT sourceID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=" + i2s(crossfader); - int eCode = 0; - am_Error_e returnVal = E_DATABASE_ERROR; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceID = sqlite3_column_int(query, 0); - MY_SQLITE_FINALIZE(query); - - sqlite3_stmt* querySrc = NULL; - command = "SELECT domainID FROM " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &querySrc, NULL) - if ((eCode = sqlite3_step(querySrc)) == SQLITE_ROW) - { - domainID = sqlite3_column_int(query, 0); - returnVal = E_OK; - } - else - { - logError("DatabaseHandler::getDomainOfCrossfader database error!:", eCode); - } - MY_SQLITE_FINALIZE(querySrc) - } - else - { - logError("DatabaseHandler::getDomainOfCrossfader database error!:", eCode); - } - MY_SQLITE_FINALIZE(query) - return (returnVal); -} - -/** - * checks for certain SinkClass - * @param sinkClassID - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks for certain sourceClass - * @param sourceClassID - * @return true if it exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, 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); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - assert(connectionID!=0); - - sqlite3_stmt *query = NULL, *queryMainConnectionSubIDs = NULL; - int eCode = 0, eCode1 = 0; - std::string command = "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, delay) - MY_SQLITE_BIND_INT(query, 2, connectionID) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - //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%'"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - //now check if the connection ID is in this table - std::string tablename = std::string((const char*) sqlite3_column_text(query, 0)); - std::string command2 = "SELECT connectionID FROM " + tablename + " WHERE connectionID=" + i2s(connectionID); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - MY_SQLITE_FINALIZE(queryMainConnectionSubIDs) - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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=?"; - - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, connectionID) - - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeConnectionFinal SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_timeSync_t CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - 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); - -} - -/** - * registers the Observer at the Database - * @param iObserver pointer to the observer - */ -void CAmDatabaseHandlerSQLite::registerObserver(CAmDatabaseObserver *iObserver) -{ - assert(iObserver!=NULL); - mpDatabaseObserver = iObserver; -} - -/** - * gives information about the visibility of a source - * @param sourceID the sourceID - * @return true if source is visible - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - returnVal = (bool) sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_DONE) - { - returnVal = false; - logError("DatabaseHandler::sourceVisible database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * gives information about the visibility of a sink - * @param sinkID the sinkID - * @return true if source is visible - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - returnVal = sqlite3_column_int(query, 0); - } - else if (eCode != SQLITE_DONE) - { - returnVal = false; - logError("DatabaseHandler::sinkVisible database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * 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 CAmDatabaseHandlerSQLite::existConnection(const am_Connection_s & connection) const -{ - 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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_int(query, 1, connection.sinkID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_bind_int(query, 2, connection.sourceID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_bind_int(query, 3, connection.connectionFormat))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks if a connection with the given ID exists - * @param connectionID - * @return true if connection exits - */ -bool CAmDatabaseHandlerSQLite::existConnectionID(const am_connectionID_t connectionID) const -{ - 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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_int(query, 1, connectionID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -/** - * checks if a CrossFader exists - * @param crossfaderID the ID of the crossfader to be checked - * @return true if exists - */ -bool CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_bind_int(query, 1, crossfaderID))) - { - logError("CAmDatabaseHandler::sqlite3_bind_int failed with errorCode:", eCode); - return (false); - } - - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - returnVal = false; - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::existMainConnection database error!:", eCode); - } - - MY_SQLITE_FINALIZE_BOOL(query) - return (returnVal); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, sourceState) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceState SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t& mainVolume) const { - assert(sinkID!=0); - sqlite3_stmt* query = NULL; - mainVolume = -1; - std::string command = "SELECT mainVolume FROM " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); - int eCode = 0; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - mainVolume = sqlite3_column_int(query, 0); - } - else if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - logError("DatabaseHandler::getSinkVolume database error!:", eCode); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_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 SinkMainSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - value = sqlite3_column_int(query, 0); - } - else - { - logError("DatabaseHandler::getDomainState database error!:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_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 SourceMainSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - if ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - value = sqlite3_column_int(query, 0); - } - else - { - logError("DatabaseHandler::getDomainState database error!:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_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); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::peekDomain(const std::string & name, am_domainID_t & domainID) -{ - domainID=0; - sqlite3_stmt* query = NULL, *queryInsert = NULL; - std::string command = "SELECT domainID FROM " + std::string(DOMAIN_TABLE) + " WHERE name=?"; - int eCode = 0, eCode1 = 0; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - else - { - command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (name,reserved) VALUES (?,?)"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL) - MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(queryInsert, 2, 1) - //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekDomain SQLITE Step error code:", eCode1); - MY_SQLITE_FINALIZE(queryInsert) - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(queryInsert) - - domainID = sqlite3_last_insert_rowid(mpDatabase); - } - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - 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 (?,?)"; - } - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL) - MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(queryInsert, 2, 1) - //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); - MY_SQLITE_FINALIZE(queryInsert) - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(queryInsert) - - sinkID = sqlite3_last_insert_rowid(mpDatabase); - } - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - 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 (?,?)"; - } - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &queryInsert, NULL) - MY_SQLITE_BIND_TEXT(queryInsert, 1, name.c_str(), name.size(), SQLITE_STATIC) - MY_SQLITE_BIND_INT(queryInsert, 2, 1) - //reservation flag - if ((eCode1 = sqlite3_step(queryInsert)) != SQLITE_DONE) - { - logError("DatabaseHandler::peekSink SQLITE Step error code:", eCode1); - MY_SQLITE_FINALIZE(queryInsert) - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(queryInsert) - sourceID = sqlite3_last_insert_rowid(mpDatabase); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, volume) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkVolume SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSinkVolume changed volume of sink:", sinkID, "to:", volume); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, volume) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceVolume SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSourceVolume changed volume of source=:", sourceID, "to:", volume); - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) -{ - 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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, soundProperty.value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSourceSoundPropertyDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSourceSoundPropertyDB changed SourceSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, 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 SinkSoundProperty" + i2s(sinkID) + " SET value=? WHERE soundPropertyType=" + i2s(soundProperty.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, soundProperty.value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSinkSoundPropertyDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - assert(sinkID!=0); - - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeSinkSoundPropertyDB changed SinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::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); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, hotsink) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeCrossFaderHotSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - logInfo("DatabaseHandler::changeCrossFaderHotSink changed hotsink of crossfader=", crossfaderID, "to:", hotsink); - return (E_OK); -} - -bool CAmDatabaseHandlerSQLite::isComponentConnected(const am_Gateway_s & gateway) const -{ - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - bool returnVal = true; - command = "SELECT 1 FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = ? OR c.sourceID = ?"; - - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, gateway.sinkID) - MY_SQLITE_BIND_INT(query, 2, gateway.sourceID) - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - returnVal = false; - } - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::isComponentConnected database error!:", eCode); - } - MY_SQLITE_FINALIZE(query) - return returnVal; -} - -bool CAmDatabaseHandlerSQLite::isComponentConnected(const am_Converter_s & converter) const -{ - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - bool returnVal = true; - command = "SELECT 1 FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = ? OR c.sourceID = ?"; - - MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, converter.sinkID) - MY_SQLITE_BIND_INT(query, 2, converter.sourceID) - if ((eCode = sqlite3_step(query)) == SQLITE_DONE) - { - returnVal = false; - } - else if (eCode != SQLITE_ROW) - { - returnVal = false; - logError("DatabaseHandler::isComponentConnected database error!:", eCode); - } - MY_SQLITE_FINALIZE(query) - - return returnVal; -} - -am_Error_e am::CAmDatabaseHandlerSQLite::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=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - returnVal = E_DATABASE_ERROR; - } - - MY_SQLITE_FINALIZE(query) - return (returnVal); -} - -am_Error_e am::CAmDatabaseHandlerSQLite::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=?"; - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_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); - MY_SQLITE_FINALIZE(query) - returnVal = E_DATABASE_ERROR; - } - - MY_SQLITE_FINALIZE(query) - return (returnVal); -} - - -am_Error_e CAmDatabaseHandlerSQLite::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - am_sourceClass_t sourceClassOut(sourceClassID); - std::vector listMainSoundPropertiesOut(listMainSoundProperties); - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - - //check if sinkClass needs to be changed - if (sourceClassID!=0) - { - command = "UPDATE"+ std::string(SOURCE_TABLE)+ " SET sourceClassID=? WHERE sourceID=" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, sourceClassID) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSource SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query); - } - - else //we need to read out the active one - { - command = "SELECT sourceClassID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0 and sourceID=" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sourceClassOut = sqlite3_column_int(query, 0); - } - MY_SQLITE_FINALIZE(query) - } - - //check if soundProperties need to be updated - if (!listSoundProperties.empty()) - { - //first we drop the table - command = "DELETE from SourceSoundProperty" + i2s(sourceID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //then we'll have a new one - //Fill SinkSoundProperties - command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator SoundPropertyIterator = listSoundProperties.begin(); - for (; SoundPropertyIterator < listSoundProperties.end(); ++SoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSource SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - //check if we have to update the list of connectionformats - if (!listConnectionFormats.empty()) - { - //first clear the table - command = "DELETE from SourceConnectionFormat" + i2s(sourceID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listConnectionFormats.begin(); - for (; connectionFormatIterator < listConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - //then we need to check if we need to update the listMainSoundProperties - if (!listMainSoundProperties.empty() && sourceVisible(sourceID)) - { - command = "DELETE from SourceMainSoundProperty" + i2s(sourceID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainSoundPropertyIterator = listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - else //read out the properties - { - getListMainSourceSoundProperties(sourceID,listMainSoundPropertiesOut); - } - - logInfo("DatabaseHandler::changeSource changed changeSink of source:", sourceID); - - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sourceUpdated(sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID)); - } - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - am_sinkClass_t sinkClassOut(sinkClassID); - std::vector listMainSoundPropertiesOut(listMainSoundProperties); - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - - //check if sinkClass needs to be changed - if (sinkClassID!=0) - { - command = "UPDATE"+ std::string(SINK_TABLE)+ " SET sinkClassID=? WHERE sinkID=" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, sinkClassID) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query); - } - - else //we need to read out the active one - { - command = "SELECT sinkClassID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0 and sinkID=" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - sinkClassOut = sqlite3_column_int(query, 0); - } - MY_SQLITE_FINALIZE(query) - } - - //check if soundProperties need to be updated - if (!listSoundProperties.empty()) - { - //first we drop the table - command = "DELETE from SinkSoundProperty" + i2s(sinkID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //then we'll have a new one - //Fill SinkSoundProperties - command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator SoundPropertyIterator = listSoundProperties.begin(); - for (; SoundPropertyIterator < listSoundProperties.end(); ++SoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, SoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, SoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - //check if we have to update the list of connectionformats - if (!listConnectionFormats.empty()) - { - //first clear the table - command = "DELETE from SinkConnectionFormat" + i2s(sinkID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listConnectionFormats.begin(); - for (; connectionFormatIterator < listConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - //then we need to check if we need to update the listMainSoundProperties - if (!listMainSoundProperties.empty() && sinkVisible(sinkID)) - { - command = "DELETE from SinkMainSoundProperty" + i2s(sinkID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //Fill MainSinkSoundProperties - command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator mainSoundPropertyIterator = listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - MY_SQLITE_BIND_INT(query, 1, mainSoundPropertyIterator->type) - MY_SQLITE_BIND_INT(query, 2, mainSoundPropertyIterator->value) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeSink SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - else //read out the properties - { - getListMainSinkSoundProperties(sinkID,listMainSoundPropertiesOut); - } - - logInfo("DatabaseHandler::changeSink changed changeSink of sink:", sinkID); - - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sinkUpdated(sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID)); - } - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector& listMainNotificationConfigurations) -{ - assert(sinkID!=0); - if (!existSink(sinkID)) - return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences - listMainNotificationConfigurations.clear(); - - sqlite3_stmt* query = NULL; - int eCode = 0; - am_NotificationConfiguration_s temp; - std::string command = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = static_cast(sqlite3_column_int(query, 0)); - temp.status = static_cast(sqlite3_column_int(query, 1)); - temp.parameter= static_cast(sqlite3_column_int(query, 2)); - listMainNotificationConfigurations.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinkMainNotificationConfigurations SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); - -} - -am_Error_e CAmDatabaseHandlerSQLite::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector& listMainNotificationConfigurations) -{ - assert(sourceID!=0); - if (!existSource(sourceID)) - return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences - listMainNotificationConfigurations.clear(); - - sqlite3_stmt* query = NULL; - int eCode = 0; - am_NotificationConfiguration_s temp; - std::string command = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - - while ((eCode = sqlite3_step(query)) == SQLITE_ROW) - { - temp.type = static_cast(sqlite3_column_int(query, 0)); - temp.status = static_cast(sqlite3_column_int(query, 1)); - temp.parameter= static_cast(sqlite3_column_int(query, 2)); - listMainNotificationConfigurations.push_back(temp); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSourceMainNotificationConfigurations SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - command = "UPDATE SinkMainNotificationConfiguration" + i2s(sinkID) + " SET status=?, parameter=? WHERE type=" + i2s(mainNotificationConfiguration.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.status) - MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSinkNotificationConfigurationDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - command = "UPDATE SourceMainNotificationConfiguration" + i2s(sourceID) + " SET status=?, parameter=? WHERE type=" + i2s(mainNotificationConfiguration.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.status) - MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeMainSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - - if (mpDatabaseObserver) - mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration); - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - assert(gatewayID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existGateway(gatewayID)) - { - return (E_NON_EXISTENT); - } - - if (!listSourceConnectionFormats.empty()) - { - //clear Database - command = "DELETE from GatewaySourceFormat" + i2s(gatewayID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO GatewaySourceFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listSourceConnectionFormats.begin(); - for (; connectionFormatIterator < listSourceConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - if (!listSinkConnectionFormats.empty()) - { - //clear Database - command = "DELETE from GatewaySinkFormat" + i2s(gatewayID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO GatewaySinkFormat" + i2s(gatewayID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listSinkConnectionFormats.begin(); - for (; connectionFormatIterator < listSinkConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterGatewayDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - if (!convertionMatrix.empty()) - { - mListConnectionFormat.clear(); - mListConnectionFormat.insert(std::make_pair(gatewayID, convertionMatrix)); - } - - logInfo("DatabaseHandler::changeGatewayDB changed Gateway with ID", gatewayID); - - //todo: check if observer needs to be adopted. - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) -{ - assert(converterID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existConverter(converterID)) - { - return (E_NON_EXISTENT); - } - - if (!listSourceConnectionFormats.empty()) - { - //clear Database - command = "DELETE from ConverterSourceFormat" + i2s(converterID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - //fill ConnectionFormats - command = "INSERT INTO ConverterSourceFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listSourceConnectionFormats.begin(); - for (; connectionFormatIterator < listSourceConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - if (!listSinkConnectionFormats.empty()) - { - //clear Database - command = "DELETE from ConverterSinkFormat" + i2s(converterID); - if (!sqQuery(command)) - return (E_DATABASE_ERROR); - - command = "INSERT INTO ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)"); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - std::vector::const_iterator connectionFormatIterator = listSinkConnectionFormats.begin(); - for (; connectionFormatIterator < listSinkConnectionFormats.end(); ++connectionFormatIterator) - { - MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_RESET(query) - } - MY_SQLITE_FINALIZE(query) - } - - if (!convertionMatrix.empty()) - { - mListConnectionFormat.clear(); - mListConnectionFormat.insert(std::make_pair(converterID, convertionMatrix)); - } - - logInfo("DatabaseHandler::changeConverterDB changed Gateway with ID", converterID); - - //todo: check if observer needs to be adopted. - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s notificationConfiguration) -{ - assert(sinkID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSink(sinkID)) - { - return (E_NON_EXISTENT); - } - command = "UPDATE SinkNotificationConfiguration" + i2s(sinkID) + " SET status=?, parameter=? WHERE type=" + i2s(notificationConfiguration.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.status) - MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSinkNotificationConfigurationDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); - - //todo:: inform obsever here... - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s notificationConfiguration) -{ - assert(sourceID!=0); - - sqlite3_stmt* query = NULL; - int eCode = 0; - std::string command; - - if (!existSource(sourceID)) - { - return (E_NON_EXISTENT); - } - command = "UPDATE SourceNotificationConfiguration" + i2s(sourceID) + " SET status=?, parameter=? WHERE type=" + i2s(notificationConfiguration.type); - MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) - MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.status) - MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.parameter) - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::changeMainSourceNotificationConfigurationDB SQLITE Step error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - MY_SQLITE_FINALIZE(query) - - logInfo("DatabaseHandler::changeSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", notificationConfiguration.type, "to status=", notificationConfiguration.status, "and parameter=",notificationConfiguration.parameter); - - //todo:: implement observer function - return (E_OK); -} - -void CAmDatabaseHandlerSQLite::createTables() -{ - for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++) - { - if (!sqQuery("CREATE TABLE " + databaseTables[i])) - throw std::runtime_error("CAmDatabaseHandler Could not create tables!"); - } -} - -am_Error_e CAmDatabaseHandlerSQLite::enumerateSources(std::function cb) const -{ - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qNotification(NULL), *qMainNotification(NULL); - int eCode = 0; - am_Source_s temp; - am_CustomConnectionFormat_t tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - am_NotificationConfiguration_s tempNotificationConfiguration; - std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 6); - temp.available.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - temp.listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL) - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - temp.listSoundProperties.push_back(tempSoundProperty); - } - - MY_SQLITE_FINALIZE(qSoundProperty) - - std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(temp.sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL) - - while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW) - { - tempNotificationConfiguration.type = static_cast(sqlite3_column_int(qNotification, 0)); - tempNotificationConfiguration.status = static_cast(sqlite3_column_int(qNotification, 1)); - tempNotificationConfiguration.parameter= static_cast(sqlite3_column_int(qNotification, 2)); - temp.listNotificationConfigurations.push_back(tempNotificationConfiguration); - } - MY_SQLITE_FINALIZE(qNotification) - - //read out MainSoundProperties if source is visible - if(temp.visible) - { - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL) - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - temp.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - MY_SQLITE_FINALIZE(qMAinSoundProperty) - - std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(temp.sourceID); - MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL) - - while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW) - { - tempNotificationConfiguration.type = static_cast(sqlite3_column_int(qMainNotification, 0)); - tempNotificationConfiguration.status = static_cast(sqlite3_column_int(qMainNotification, 1)); - tempNotificationConfiguration.parameter= static_cast(sqlite3_column_int(qMainNotification, 2)); - temp.listMainNotificationConfigurations.push_back(tempNotificationConfiguration); - } - MY_SQLITE_FINALIZE(qMainNotification) - } - - - cb(temp); - temp.listConnectionFormats.clear(); - temp.listMainSoundProperties.clear(); - temp.listSoundProperties.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSources SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enumerateSinks(std::function cb) const -{ - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qNotificationConfiguration= NULL, *qMAinSoundProperty = NULL, *qMainNotificationConfiguration= NULL; - int eCode = 0; - am_Sink_s temp; - am_CustomConnectionFormat_t tempConnectionFormat; - am_SoundProperty_s tempSoundProperty; - am_MainSoundProperty_s tempMainSoundProperty; - am_NotificationConfiguration_s tempNotificationConfiguration; - am_NotificationConfiguration_s tempMainNotificationConfiguration; - std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0"; - MY_SQLITE_PREPARE_V2(mpDatabase, 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_Availability_e) sqlite3_column_int(query, 5); - temp.available.availabilityReason = (am_CustomAvailabilityReason_t) 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); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL) - while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0); - temp.listConnectionFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qConnectionFormat) - - //read out sound properties - std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL) - while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW) - { - tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0); - tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1); - temp.listSoundProperties.push_back(tempSoundProperty); - } - - MY_SQLITE_FINALIZE(qSoundProperty) - - //read out notifications - std::string commandNotificationConfiguration = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(temp.sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandNotificationConfiguration.c_str(), -1, &qNotificationConfiguration, NULL) - while ((eCode = sqlite3_step(qNotificationConfiguration)) == SQLITE_ROW) - { - tempNotificationConfiguration.type = static_cast (sqlite3_column_int(qNotificationConfiguration, 0)); - tempNotificationConfiguration.status = static_cast (sqlite3_column_int(qNotificationConfiguration, 1)); - tempNotificationConfiguration.parameter = static_cast (sqlite3_column_int(qNotificationConfiguration, 2)); - temp.listNotificationConfigurations.push_back(tempNotificationConfiguration); - } - - MY_SQLITE_FINALIZE(qNotificationConfiguration) - - //read out MainSoundProperties if sink is visible - if(temp.visible) - { - std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL) - while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW) - { - tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0); - tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1); - temp.listMainSoundProperties.push_back(tempMainSoundProperty); - } - - MY_SQLITE_FINALIZE(qMAinSoundProperty) - - //and mainNotificationConfigurations - std::string commandMainNotificationConfiguration = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(temp.sinkID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandMainNotificationConfiguration.c_str(), -1, &qMainNotificationConfiguration, NULL) - while ((eCode = sqlite3_step(qMainNotificationConfiguration)) == SQLITE_ROW) - { - tempMainNotificationConfiguration.type = static_cast (sqlite3_column_int(qMainNotificationConfiguration, 0)); - tempMainNotificationConfiguration.status = static_cast (sqlite3_column_int(qMainNotificationConfiguration, 1)); - tempMainNotificationConfiguration.parameter = static_cast (sqlite3_column_int(qMainNotificationConfiguration, 2)); - temp.listMainNotificationConfigurations.push_back(tempMainNotificationConfiguration); - } - - MY_SQLITE_FINALIZE(qMainNotificationConfiguration) - } - - cb(temp); - temp.listConnectionFormats.clear(); - temp.listMainSoundProperties.clear(); - temp.listSoundProperties.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListSinks SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enumerateGateways(std::function cb) const -{ - sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; - int eCode = 0; - am_Gateway_s temp; - am_CustomConnectionFormat_t tempConnectionFormat; - - std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE); - MY_SQLITE_PREPARE_V2(mpDatabase, 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); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0); - temp.listSourceFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSourceConnectionFormat) - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0); - temp.listSinkFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSinkConnectionFormat) - - cb(temp); - temp.listSinkFormats.clear(); - temp.listSourceFormats.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListGateways SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -am_Error_e CAmDatabaseHandlerSQLite::enumerateConverters(std::function cb) const -{ - sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL; - int eCode = 0; - am_Converter_s temp; - am_CustomConnectionFormat_t tempConnectionFormat; - - std::string command = "SELECT name, sinkID, sourceID, domainID, converterID FROM " + std::string(CONVERTER_TABLE); - MY_SQLITE_PREPARE_V2(mpDatabase, 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.domainID = sqlite3_column_int(query, 3); - temp.converterID = sqlite3_column_int(query, 4); - - //convertionMatrix: - ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin(); - iter = mListConnectionFormat.find(temp.converterID); - if (iter == mListConnectionFormat.end()) - { - logError("DatabaseHandler::getListConverters database error with convertionFormat"); - - return (E_DATABASE_ERROR); - } - temp.convertionMatrix = iter->second; - - //read out the connectionFormats - std::string commandConnectionFormat = "SELECT soundFormat FROM ConverterSourceFormat" + i2s(temp.converterID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0); - temp.listSourceFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSourceConnectionFormat) - - //read out sound properties - commandConnectionFormat = "SELECT soundFormat FROM ConverterSinkFormat" + i2s(temp.converterID); - MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL) - while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW) - { - tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0); - temp.listSinkFormats.push_back(tempConnectionFormat); - } - - MY_SQLITE_FINALIZE(qSinkConnectionFormat) - - cb(temp); - temp.listSinkFormats.clear(); - temp.listSourceFormats.clear(); - } - - if (eCode != SQLITE_DONE) - { - logError("DatabaseHandler::getListConverters SQLITE error code:", eCode); - MY_SQLITE_FINALIZE(query) - return (E_DATABASE_ERROR); - } - - MY_SQLITE_FINALIZE(query) - - return (E_OK); -} - -} diff --git a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp deleted file mode 100644 index acac639..0000000 --- a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseObserver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmDatabaseObserver.h" -#include -#include -#include -#include -#include -#include "CAmCommandSender.h" -#include "CAmRoutingSender.h" -#include "CAmTelnetServer.h" -#include "CAmDltWrapper.h" -#include "CAmSerializer.h" - -namespace am { - -CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : - mCommandSender(iCommandSender), // - mRoutingSender(iRoutingSender), // - mTelnetServer(NULL), // - 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::newConverter(const am_Converter_s& coverter) -{ - (void) coverter; - //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::removeConverter(const am_converterID_t converterID) -{ - (void) converterID; - //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); -} - -void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) -{ - if (visible) - mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sinkID, sinkClassID, listMainSoundProperties); -} - -void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) -{ - if (visible) - mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sourceID, sourceClassID, listMainSoundProperties); -} - -void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - mSerializer.asyncCall (mCommandSender, &CAmCommandSender::cbSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration); -} - -void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration); -} - -} diff --git a/AudioManagerDaemon/src/CAmLog.cpp b/AudioManagerDaemon/src/CAmLog.cpp deleted file mode 100644 index f68f660..0000000 --- a/AudioManagerDaemon/src/CAmLog.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file CAmLog.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmLog.h" - - -void CAmLog::CAmFileLogger::generateLogFilename(std::string &result) -{ - static uint32_t logFileID = 1; - time_t rawtime; - time (&rawtime); - - std::ostringstream stream; - stream << DEFAULT_LOG_FOLDER << DEFAULT_LOGFILE_PREFIX << logFileID << "_" << rawtime << DEFAULT_LOGFILE_EXT; - logFileID++; - result = stream.str(); -} - -CAmLog::CAmFileLogger::~CAmFileLogger() -{ - if (mOutputStream) - { - std::ofstream* of = static_cast(mOutputStream); - of->close(); - DEL(mOutputStream) - } -} - -CAmLog::CAmLog(const eCAmLogType type ):mLogType(type) -{ - instantiateLogger(type); -} - -CAmLog::CAmLog():mLogType(eCAmLogStdout) -{ - instantiateLogger((const eCAmLogType)eCAmLogStdout); -} - -CAmLog::~CAmLog() -{ - releaseLogger(); -} - -void CAmLog::releaseLogger() -{ - if(mLogger) - DEL(mLogger) -} - -void CAmLog::instantiateLogger( const eCAmLogType type) -{ - if( eCAmLogStdout == type ) - mLogger = new CAmStdOutLogger(); - else if( eCAmLogFile == type ) - { - std::string filename(""); - CAmLog::CAmFileLogger::generateLogFilename(filename); - mLogger = new CAmFileLogger(filename); - } -} - -CAmLog *CAmLog::getDefaultLog() -{ - static CAmLog theInstance; - return &theInstance; -} - -void CAmLog::setLogType( const eCAmLogType type) -{ - if(mLogType!=type) - { - mLogType = type; - releaseLogger(); - instantiateLogger(type); - } -} - -eCAmLogType CAmLog::getLogType() const -{ - return mLogType; -} diff --git a/AudioManagerDaemon/src/CAmRouter.cpp b/AudioManagerDaemon/src/CAmRouter.cpp deleted file mode 100644 index f98bf11..0000000 --- a/AudioManagerDaemon/src/CAmRouter.cpp +++ /dev/null @@ -1,884 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014 - * - * \file CAmRouter.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include -#include -#include -#include -#include "CAmRouter.h" -#include "IAmDatabaseHandler.h" -#include "CAmControlSender.h" -#include "CAmDltWrapper.h" - - - -namespace am { - - -template void getMergeConnectionFormats(const X * element, - const am_CustomConnectionFormat_t connectionFormat, - const std::vector & listConnectionFormats, - std::vector & outListMergeConnectionFormats) -{ - std::vector listRestrictedConnectionFormats; - CAmRouter::getRestrictedOutputFormats(element->convertionMatrix, - element->listSourceFormats, - element->listSinkFormats, - connectionFormat, - listRestrictedConnectionFormats); - std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input - std::insert_iterator > inserter(outListMergeConnectionFormats, outListMergeConnectionFormats.begin()); - set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter); -} - - -CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : - mpDatabaseHandler(iDatabaseHandler), // - mpControlSender(iSender), - mOnlyFreeConversionNodes(false), - mRoutingGraph(), - mNodeListSources(), - mNodeListSinks(), - mNodeListGateways(), - mNodeListConverters() -{ - assert(mpDatabaseHandler); - assert(mpControlSender); -} - -CAmRouter::~CAmRouter() -{ -} - -/** - * returns the best route between a source and a sink - * @param onlyfree if true only free gateways are used - * @param sourceID - * @param sinkID - * @param returnList this list contains a set of routes - * @return E_OK in case of success - */ -am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) -{ - returnList.clear(); - am_Source_s source; - am_Sink_s sink; - am_Error_e error = mpDatabaseHandler->getSourceInfoDB(sourceID, source); - if(error!=E_OK) - return error; - error = mpDatabaseHandler->getSinkInfoDB(sinkID, sink); - if(error!=E_OK) - return error; - error = getRoute(onlyfree, source, sink, returnList); - return error; -} - - -am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) -{ - am_Error_e error; - load(onlyfree); - - CAmRoutingNode* pRootSource = sourceNodeWithID(aSource.sourceID); - CAmRoutingNode* pRootSink = sinkNodeWithID(aSink.sinkID); - - assert(pRootSource); - assert(pRootSink); - -#ifdef TRACE_GRAPH - mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { - std::cout << "Node " << node.getIndex() << " :"; - ((CAmRoutingNode &)node).getData().trace(); - std::cout << "-->"; - std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ - am::CAmNode* data = refVertex->getNode(); - std::cout << "Node " << data->getIndex() << " :"; - data->getData().trace(); - }); - std::cout << std::endl; - }); -#endif - - std::vector> pathNodes; - error = getAllPaths(*pRootSource, *pRootSink, listRoutes, pathNodes); - return error; -} - -void CAmRouter::load(const bool onlyFree) -{ - clear(); - mOnlyFreeConversionNodes = onlyFree; - -#if defined (WITH_DATABASE_STORAGE) - std::deque listSources; - std::deque listSinks; - std::deque listGateways; - std::deque listConverters; -#endif - am_RoutingNodeData_s nodeDataSrc; - nodeDataSrc.type = CAmNodeDataType::SOURCE; - mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listSources.push_back(obj); - nodeDataSrc.data.source = &listSources.back(); -#else - nodeDataSrc.data.source = (am_Source_s*)&obj; -#endif - mNodeListSources[nodeDataSrc.data.source->domainID].push_back(&mRoutingGraph.addNode(nodeDataSrc)); - }); - am_RoutingNodeData_s nodeDataSink; - nodeDataSink.type = CAmNodeDataType::SINK; - mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listSinks.push_back(obj); - nodeDataSrc.data.sink = &listSinks.back(); -#else - nodeDataSink.data.sink = (am_Sink_s*)&obj; -#endif - mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(&mRoutingGraph.addNode(nodeDataSink)); - }); - am_RoutingNodeData_s nodeDataGateway; - nodeDataGateway.type = CAmNodeDataType::GATEWAY; - mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listGateways.push_back(obj); - nodeDataSrc.data.gateway = &listGateways.back(); -#else - nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; -#endif - mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(&mRoutingGraph.addNode(nodeDataGateway)); - }); - am_RoutingNodeData_s nodeDataConverter; - nodeDataConverter.type = CAmNodeDataType::CONVERTER; - mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listConverters.push_back(obj); - nodeDataSrc.data.converter = &listConverters.back(); -#else - nodeDataConverter.data.converter = (am_Converter_s*)&obj; -#endif - mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(&mRoutingGraph.addNode(nodeDataConverter)); - }); - -#ifdef ROUTING_BUILD_CONNECTIONS - constructConverterConnections(); - constructGatewayConnections(); - constructSourceSinkConnections(); -#endif -} - -void CAmRouter::clear() -{ - mRoutingGraph.clear(); - mNodeListSources.clear(); - mNodeListSinks.clear(); - mNodeListGateways.clear(); - mNodeListConverters.clear(); -} - -CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID) -{ - CAmRoutingNode* result = NULL; - for(auto it = mNodeListSinks.begin(); it!=mNodeListSinks.end(); it++) - { - result = sinkNodeWithID(sinkID, it->first); - if(result) - return result; - } - return result; -} - -CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListSinks[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.sink->sinkID==sinkID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} - -CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID) -{ - CAmRoutingNode* result = NULL; - for(auto it = mNodeListSources.begin(); it!=mNodeListSources.end(); it++) - { - result = sourceNodeWithID(sourceID, it->first); - if(result) - return result; - } - return result; -} - -CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListSources[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sourceID](CAmRoutingNode* node){ - return node->getData().data.source->sourceID==sourceID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} - -CAmRoutingNode* CAmRouter::converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListConverters[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.converter->sinkID==sinkID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} - -CAmRoutingNode* CAmRouter::gatewayNodeWithSinkID(const am_sinkID_t sinkID) -{ - for(auto it = mNodeListGateways.begin(); it!=mNodeListGateways.end(); it++) - { - std::vector & value = it->second; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.gateway->sinkID==sinkID; - }); - if(iter!=value.end()) - return *iter; - } - return NULL; -} - -#ifdef ROUTING_BUILD_CONNECTIONS - -void CAmRouter::constructSourceSinkConnections() -{ - std::vector intersection; - for(auto itSrc = mNodeListSources.begin(); itSrc!=mNodeListSources.end(); itSrc++) - { - for(auto it = itSrc->second.begin(); it!=itSrc->second.end(); it++) - { - CAmRoutingNode* srcNode = *it; - am_RoutingNodeData_s & srcNodeData = srcNode->getData(); - am_Source_s * source = srcNodeData.data.source; - for(auto itSink = mNodeListSinks[itSrc->first].begin(); itSink!=mNodeListSinks[itSrc->first].end(); itSink++) - { - CAmRoutingNode* sinkNode = *itSink; - am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); - am_Sink_s * sink = sinkNodeData.data.sink; - - intersection.clear(); - //Check whether the hidden sink formats match the source formats... - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); - if(intersection.size()>0)//OK match source -> sink - { - mRoutingGraph.connectNodes(*srcNode, *sinkNode, CF_UNKNOWN, 1); - } - } - } - } -} - -void CAmRouter::constructGatewayConnections() -{ - std::vector sourceFormats, sinkFormats; - for(auto iter = mNodeListGateways.begin(); iter!=mNodeListGateways.end(); iter++) - { - for(auto it = iter->second.begin(); it!=iter->second.end(); it++) - { - CAmRoutingNode* gatewayNode = *it; - am_RoutingNodeData_s & gatewayNodeData = gatewayNode->getData(); - am_Gateway_s * gateway = gatewayNodeData.data.gateway; - //Get only gateways with end point in current source domain - if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) - { - //Get the sink connected to the gateway... - CAmRoutingNode *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID, gateway->domainSinkID); - if(gatewaySinkNode) - { - am_RoutingNodeData_s & gatewaySinkData = gatewaySinkNode->getData(); - //Check whether the hidden sink formats match the source formats... - sourceFormats.clear(); - sinkFormats.clear(); - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); - if(gatewaySourceNode) - { - //Connections hidden_sink->gateway->hidden_source - mRoutingGraph.connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1); - mRoutingGraph.connectNodes(*gatewayNode, *gatewaySourceNode, CF_UNKNOWN, 1); - } - } - } - } - } - } -} - -void CAmRouter::constructConverterConnections() -{ - std::vector sourceFormats, sinkFormats; - - for(auto iter = mNodeListConverters.begin(); iter!=mNodeListConverters.end(); iter++) - { - for(auto it = iter->second.begin(); it!=iter->second.end(); it++) - { - CAmRoutingNode* converterNode = *it; - am_RoutingNodeData_s & converterNodeData = converterNode->getData(); - am_Converter_s * converter = converterNodeData.data.converter; - //Get only converters with end point in current source domain - if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) - { - //Get the sink connected to the converter... - CAmRoutingNode *converterSinkNode = this->sinkNodeWithID(converter->sinkID, converter->domainID); - if(converterSinkNode) - { - am_RoutingNodeData_s & converterSinkData = converterSinkNode->getData(); - //Check whether the hidden sink formats match the source formats... - sourceFormats.clear(); - sinkFormats.clear(); - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); - if(converterSourceNode) - { - //Connections hidden_sink->converter->hidden_source - mRoutingGraph.connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1); - mRoutingGraph.connectNodes(*converterNode, *converterSourceNode, CF_UNKNOWN, 1); - } - } - } - } - } - } -} -#else - -void CAmRouter::getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & srcNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector intersection; - am_Source_s * source = srcNodeData.data.source; - std::vector & sinks = mNodeListSinks[source->domainID]; - for(auto itSink = sinks.begin(); itSink!=sinks.end(); itSink++) - { - CAmRoutingNode* sinkNode = *itSink; - am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); - am_Sink_s * sink = sinkNodeData.data.sink; - - intersection.clear(); - //Check whether the hidden sink formats match the source formats... - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); - if(intersection.size()>0)//OK match source -> sink - { - list.emplace_back(sinkNode, CF_UNKNOWN, 1); - } - } -} - -void CAmRouter::getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & sinkNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector intersection; - am_Sink_s * sink = sinkNodeData.data.sink; - - CAmRoutingNode *converterNode = converterNodeWithSinkID(sink->sinkID, sink->domainID); - if(converterNode) - { - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & converterData = converterNode->getData(); - am_Converter_s * converter = converterData.data.converter; - if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) - { - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - list.emplace_back(converterNode, CF_UNKNOWN, 1); - } - } - else - { - std::vector sourceFormats, sinkFormats; - CAmRoutingNode *gatewayNode = gatewayNodeWithSinkID(sink->sinkID); - if(gatewayNode) - { - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & gatewayData = gatewayNode->getData(); - am_Gateway_s * gateway = gatewayData.data.gateway; - if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) - { - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - list.emplace_back(gatewayNode, CF_UNKNOWN, 1); - } - } - } - -} - -void CAmRouter::getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & converterNodeData = ((CAmRoutingNode*)&node)->getData(); - am_Converter_s * converter = converterNodeData.data.converter; - //Get only converters with end point in current source domain - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); - if(converterSourceNode) - { - list.emplace_back(converterSourceNode, CF_UNKNOWN, 1); - } - } -} - -void CAmRouter::getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & gatewayNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector sourceFormats, sinkFormats; - am_Gateway_s * gateway = gatewayNodeData.data.gateway; - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); - if(gatewaySourceNode) - { - //Connections hidden_sink->gateway->hidden_source - list.emplace_back(gatewaySourceNode, CF_UNKNOWN, 1); - } - } -} - -void CAmRouter::getVerticesForNode( - const CAmRoutingNode & node, - CAmRoutingListVertices & list - ) -{ - am_RoutingNodeData_s & nodeData = ((CAmRoutingNode*)&node)->getData(); - if(nodeData.type==CAmNodeDataType::SOURCE) - { - getVerticesForSource(node, list); - } - else if(nodeData.type==CAmNodeDataType::SINK) - { - getVerticesForSink(node, list); - } - else if(nodeData.type==CAmNodeDataType::CONVERTER) - { - getVerticesForConverter(node, list); - } - else if(nodeData.type==CAmNodeDataType::GATEWAY) - { - getVerticesForGateway(node, list); - } -} - -#endif - -am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes) -{ - std::vector::iterator routingElementIterator = routeObjects.route.begin(); - std::vector::iterator nodeIterator = nodes.begin(); - if( routingElementIterator!= routeObjects.route.end() && nodeIterator!=nodes.end() ) - return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator); - return E_OK; -} - -am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & nodes, - std::vector::iterator routingElementIterator, - std::vector::iterator nodeIterator) -{ - am_Error_e returnError = E_NOT_POSSIBLE; - std::vector listConnectionFormats; - std::vector listMergeConnectionFormats; - - std::vector::iterator currentNodeIterator = nodeIterator; - std::vector::iterator currentRoutingElementIterator = routingElementIterator; - - if (currentRoutingElementIterator!=routeObjects.route.begin()) - { - std::vector listConnectionFormats; - std::vector::iterator tempIterator = (currentRoutingElementIterator-1); - CAmRoutingNode * currentNode = *currentNodeIterator; - getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats); - - if(currentNode->getData().type==CAmNodeDataType::GATEWAY) - { - am_Gateway_s *gateway = currentNode->getData().data.gateway; - getMergeConnectionFormats(gateway, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); - } - else if(currentNode->getData().type==CAmNodeDataType::CONVERTER) - { - am_Converter_s *converter = currentNode->getData().data.converter; - getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); - } - currentNodeIterator+=3; - } - else - { - CAmRoutingNode * currentNode = *currentNodeIterator; - assert(currentNode->getData().type==CAmNodeDataType::SOURCE); - - currentNodeIterator++; - assert(currentNodeIterator!=nodes.end()); - - CAmRoutingNode * nodeSink = *currentNodeIterator; - assert(nodeSink->getData().type==CAmNodeDataType::SINK); - - am_Source_s *source = currentNode->getData().data.source; - am_Sink_s *sink = nodeSink->getData().data.sink; - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats); - currentNodeIterator+=1; //now we are on the next converter/gateway - } - - //let the controller decide: - std::vector listPriorityConnectionFormats; - mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects, - listMergeConnectionFormats, listPriorityConnectionFormats); - - //we have the list sorted after priors - 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 - std::vector::iterator nextIterator = currentRoutingElementIterator + 1;//next pair source and sink - if (nextIterator == routeObjects.route.end()) - { - if (!listPriorityConnectionFormats.empty()) - { - currentRoutingElementIterator->connectionFormat = listPriorityConnectionFormats.front(); - return (E_OK); - } - else - return (E_NOT_POSSIBLE); - } - - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) - { - currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; - if ((returnError = doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator)) == E_OK) - { - break; - } - } - return (returnError); -} - -#ifdef ROUTING_BUILD_CONNECTIONS - -void CAmRouter::getShortestPath(const CAmRoutingNode & source, - const CAmRoutingNode & destination, - std::vector & resultPath) -{ - mRoutingGraph.getShortestPath(source, destination, resultPath); -} - -void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, - am_Route_s & resultPath, std::vector & resultNodesPath) -{ - am_RoutingElement_s * element; - am_RoutingNodeData_s & sinkNodeData = aSink.getData(); - am_RoutingNodeData_s & sourceNodeData = aSource.getData(); - resultPath.sinkID = sinkNodeData.data.sink->sinkID; - resultPath.sourceID = sourceNodeData.data.source->sourceID; - - std::function cb = [&](const am_GraphPathPosition_e, CAmRoutingNode & object) - { - resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); - am_RoutingNodeData_s & routingData = object.getData(); - if(routingData.type==CAmNodeDataType::SINK) - { - auto iter = resultPath.route.emplace(resultPath.route.begin()); - element = &(*iter); - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SOURCE) - { - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - }; - mRoutingGraph.getShortestPath(aSource, aSink, cb); -} - -#endif - -am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles) -{ -#ifndef ROUTING_BUILD_CONNECTIONS - bool cycles = false; -#else - bool cycles = includeCycles; -#endif - if(((CAmRoutingNode*)&aSource)->getData().type!=CAmNodeDataType::SOURCE || - ((CAmRoutingNode*)&aSink)->getData().type!=CAmNodeDataType::SINK) - return E_NOT_POSSIBLE; - - uint8_t errorsCount = 0, successCount = 0; - generateAllPaths(aSource, aSink, cycles, [&](const std::vector & path) { - resultNodesPath.push_back(path); - resultPath.emplace_back(); - am_Route_s & nextRoute = resultPath.back(); - nextRoute.sinkID = aSink.getData().data.sink->sinkID; - nextRoute.sourceID = aSource.getData().data.source->sourceID; - am_RoutingElement_s * element; - for(auto it = path.begin(); it!=path.end(); it++) - { - am_RoutingNodeData_s & routingData = (*it)->getData(); - if(routingData.type==CAmNodeDataType::SOURCE) - { - auto iter = nextRoute.route.emplace(nextRoute.route.end()); - element = &(*iter); - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SINK) - { - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - } - - am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector &)path); - if(err!=E_OK) - { - errorsCount++; - auto last = resultPath.end()-1; - resultPath.erase(last); -#ifdef TRACE_GRAPH - std::cout<<"Error by determining connection formats for path from source:"<" - < & visitedDomains, const am_domainID_t nodeDomainID) -{ - if(visitedDomains.size()) - { - if(visitedDomains.back()==nodeDomainID) - return true; - - for(auto it=visitedDomains.begin();it!=visitedDomains.end()-1; it++) - { - if(nodeDomainID==*it) - return false; - } - } - return true; -} - -void CAmRouter::generateAllPaths(const CAmRoutingNode & src, - const CAmRoutingNode & dst, - const bool includeCycles, - std::function & path)> cb) -{ - if(!includeCycles) - { - std::vector visited; - std::vector visitedDomains; - visited.push_back((CAmRoutingNode*)&src); - visitedDomains.push_back(((CAmRoutingNode*)&src)->getData().domainID()); - ((CAmRoutingNode*)&src)->setStatus(GES_VISITED); - goThroughAllPaths(dst, visited, visitedDomains, cb); - } - else - mRoutingGraph.getAllPaths(src, dst, cb); -} - -void CAmRouter::goThroughAllPaths(const CAmRoutingNode & dst, - std::vector & visited, - std::vector & visitedDomains, - std::function & path)> cb) -{ -#ifndef ROUTING_BUILD_CONNECTIONS - CAmRoutingListVertices vertices; - getVerticesForNode(*visited.back(), vertices); - const CAmRoutingListVertices * nodes = &vertices; -#else - const CAmRoutingListVertices * nodes = mRoutingGraph.getVertexList()[visited.back()->getIndex()]; -#endif - CAmRoutingListVertices::const_iterator vItr(nodes->begin()); - for (; vItr != nodes->end(); ++vItr) - { - const CAmRoutingVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED || !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) - continue; - if (vertex.getNode()==&dst) - { - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - visitedDomains.push_back(vertex.getNode()->getData().domainID()); - //notify observer - cb(visited); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - visitedDomains.erase(visitedDomains.end()-1); - vertex.getNode()->setStatus(GES_NOT_VISITED); - break; - } - } - vItr = nodes->begin(); - //bfs like loop - for (; vItr != nodes->end(); ++vItr) - { - const CAmRoutingVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED - ||vertex.getNode()==&dst || - !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) - continue; - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - visitedDomains.push_back(vertex.getNode()->getData().domainID()); - goThroughAllPaths(dst, visited, visitedDomains, cb); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - visitedDomains.erase(visitedDomains.end()-1); - vertex.getNode()->setStatus(GES_NOT_VISITED); - } -} - -bool CAmRouter::getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - std::vector & sourceFormats, - std::vector & sinkFormats) -{ - const size_t sizeSourceFormats = listSourceFormats.size(); - const size_t sizeSinkFormats = listSinkFormats.size(); - const size_t sizeConvertionMatrix = convertionMatrix.size(); - - if(sizeSourceFormats==0||sizeSinkFormats==0||sizeConvertionMatrix==0||sizeConvertionMatrix!=sizeSinkFormats*sizeSourceFormats) - { - return false; - } - - std::vector::const_iterator iterator = convertionMatrix.begin(); - for (; iterator != convertionMatrix.end(); ++iterator) - { - if( true == *iterator ) - { - const size_t index = iterator-convertionMatrix.begin(); - size_t idx = index%sizeSourceFormats; - sourceFormats.push_back(listSourceFormats.at(idx)); - idx = index/sizeSourceFormats; - sinkFormats.push_back(listSinkFormats.at(idx)); - } - } - return sourceFormats.size()>0; -} - -void CAmRouter::listPossibleConnectionFormats(std::vector & inListSourceFormats, - std::vector & inListSinkFormats, - std::vector & outListFormats) -{ - std::sort(inListSourceFormats.begin(), inListSourceFormats.end()); - std::sort(inListSinkFormats.begin(), inListSinkFormats.end()); - std::insert_iterator > inserter(outListFormats, outListFormats.begin()); - set_intersection(inListSourceFormats.begin(), inListSourceFormats.end(), inListSinkFormats.begin(), inListSinkFormats.end(), inserter); -} - - -bool CAmRouter::getRestrictedOutputFormats(const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - const am_CustomConnectionFormat_t connectionFormat, - std::vector & listFormats) -{ - listFormats.clear(); - std::vector::const_iterator rowSinkIterator = listSinkFormats.begin(); - std::vector::const_iterator matrixIterator = convertionMatrix.begin(); - - //find the row number of the sink - rowSinkIterator = find(listSinkFormats.begin(), listSinkFormats.end(), connectionFormat); - int rowNumberSink = rowSinkIterator - 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(listSourceFormats.at((matrixIterator - convertionMatrix.begin()) / listSinkFormats.size())); - } - std::advance(matrixIterator, listSinkFormats.size()); - } while (convertionMatrix.end() - matrixIterator > 0); - - return listFormats.size(); -} - - -void CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, - std::vector::iterator iteratorSink, - std::vector & outConnectionFormats) -{ - CAmRoutingNode * nodeSink = *iteratorSink; - assert(nodeSink->getData().type==CAmNodeDataType::SINK); - - CAmRoutingNode * nodeSource = *iteratorSource; - assert(nodeSource->getData().type==CAmNodeDataType::SOURCE); - - am_Source_s *source = nodeSource->getData().data.source; - am_Sink_s *sink = nodeSink->getData().data.sink; - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats); -} - - -} diff --git a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp deleted file mode 100644 index 4189936..0000000 --- a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp +++ /dev/null @@ -1,620 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmRoutingReceiver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmRoutingReceiver.h" -#include -#include -#include "IAmDatabaseHandler.h" -#include "CAmRoutingSender.h" -#include "CAmControlSender.h" -#include "CAmDltWrapper.h" -#include "CAmSocketHandler.h" - -namespace am -{ - -CAmRoutingReceiver::CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) : - mpDatabaseHandler(iDatabaseHandler), // - mpRoutingSender(iRoutingSender), // - mpControlSender(iControlSender), // - mpSocketHandler(iSocketHandler), // - mpDBusWrapper(NULL), // - mListStartupHandles(), // - mListRundownHandles(), // - handleCount(0), // - mWaitStartup(false), // - mWaitRundown(false), // - mLastStartupError(E_OK), // - mLastRundownError(E_OK) // -{ - assert(mpDatabaseHandler!=NULL); - assert(mpRoutingSender!=NULL); - assert(mpControlSender!=NULL); - assert(mpSocketHandler!=NULL); -} - -CAmRoutingReceiver::CAmRoutingReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) : - mpDatabaseHandler(iDatabaseHandler), // - mpRoutingSender(iRoutingSender), // - mpControlSender(iControlSender), // - mpSocketHandler(iSocketHandler), // - mpDBusWrapper(iDBusWrapper), // - mListStartupHandles(), // - mListRundownHandles(), // - handleCount(0), // - mWaitStartup(false), // - mWaitRundown(false), - mLastStartupError(E_OK), // - mLastRundownError(E_OK) // -{ - assert(mpDatabaseHandler!=NULL); - assert(mpRoutingSender!=NULL); - assert(mpControlSender!=NULL); - assert(mpSocketHandler!=NULL); - assert(mpDBusWrapper!=NULL); -} - -CAmRoutingReceiver::~CAmRoutingReceiver() -{ -} - -void CAmRoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - mpRoutingSender->removeHandle(handle); - if (error == am_Error_e::E_OK) - { - mpDatabaseHandler->changeConnectionFinal(connectionID); - } - else - { - mpDatabaseHandler->removeConnection(connectionID); - mpRoutingSender->removeConnectionLookup(connectionID); - } - mpControlSender->cbAckConnect(handle, error); -} - -void CAmRoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) -{ - - //so we will remove the connection anyway no matter what is answered - mpRoutingSender->removeHandle(handle); - mpDatabaseHandler->removeConnection(connectionID); - mpRoutingSender->removeConnectionLookup(connectionID); - mpControlSender->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; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if (error== am_Error_e::E_OK || error== am_Error_e::E_ABORTED) - { - mpDatabaseHandler->changeSinkVolume(handleData.sinkID, volume); - } - - if(error == am_Error_e::E_OK || handleData.volume!=volume) - { - logError("ackSetSinkVolumeChange volumes do not match, requested volume",handleData.volume,"returned volume",volume); - } - mpControlSender->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; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if (error== am_Error_e::E_OK || error== am_Error_e::E_ABORTED) - { - mpDatabaseHandler->changeSourceVolume(handleData.sourceID, volume); - } - - if(error == E_OK || handleData.volume!=volume) - { - logError("ackSetSourceVolumeChange volumes do not match, requested volume",handleData.volume,"returned volume",volume); - } - mpControlSender->cbAckSetSourceVolumeChange(handle, volume, error); -} - -void CAmRoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - //no error, so we can write the change into the database; - if (error == am_Error_e::E_OK) - { - mpDatabaseHandler->changeSourceState(handleData.sourceID, handleData.sourceState); - } - - mpControlSender->cbAckSetSourceState(handle, error); -} - -void CAmRoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if (error==am_Error_e::E_OK) - { - mpDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery, handleData.sinkID); - } - - mpControlSender->cbAckSetSinkSoundProperty(handle, error); - -} - -void am::CAmRoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if (error==am_Error_e::E_OK) - { - std::vector::const_iterator it = handleData.soundProperties->begin(); - for (; it != handleData.soundProperties->end(); ++it) - { - mpDatabaseHandler->changeSinkSoundPropertyDB(*it, handleData.sinkID); - } - } - - try - { - delete handleData.soundProperties; - } - catch(...) - { - logError("exception while deleting handleData while ackSetSinkSoundProperties"); - } - mpControlSender->cbAckSetSinkSoundProperties(handle, error); -} - -void CAmRoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - mpDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery, handleData.sourceID); - } - mpControlSender->cbAckSetSourceSoundProperty(handle, error); -} - -void am::CAmRoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - std::vector::const_iterator it = handleData.soundProperties->begin(); - for (; it != handleData.soundProperties->end(); ++it) - { - mpDatabaseHandler->changeSourceSoundPropertyDB(*it, handleData.sourceID); - } - } - - try - { - delete handleData.soundProperties; - } - catch(...) - { - logError("exception while deleting handleData while ackSetSourceSoundProperties"); - } - mpControlSender->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; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - mpDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID, hotSink); - } - mpControlSender->cbAckCrossFade(handle, hotSink, error); -} - -void CAmRoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) -{ - mpControlSender->hookSystemSourceVolumeTick(handle, sourceID, volume); -} - -void CAmRoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) -{ - mpControlSender->hookSystemSinkVolumeTick(handle, sinkID, volume); -} - -am_Error_e CAmRoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID) -{ - return (mpDatabaseHandler->peekDomain(name, domainID)); - -} - -am_Error_e CAmRoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID) -{ - return (mpControlSender->hookSystemRegisterDomain(domainData, domainID)); -} - -am_Error_e CAmRoutingReceiver::deregisterDomain(const am_domainID_t domainID) -{ - return (mpControlSender->hookSystemDeregisterDomain(domainID)); -} - -am_Error_e CAmRoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID) -{ - return (mpControlSender->hookSystemRegisterGateway(gatewayData, gatewayID)); -} - -am_Error_e CAmRoutingReceiver::registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID) -{ - return (mpControlSender->hookSystemRegisterConverter(converterData, converterID)); -} - -am_Error_e CAmRoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID) -{ - return (mpControlSender->hookSystemDeregisterGateway(gatewayID)); -} - -am_Error_e CAmRoutingReceiver::deregisterConverter(const am_converterID_t converterID) -{ - return (mpControlSender->hookSystemDeregisterConverter(converterID)); -} - -am_Error_e CAmRoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID) -{ - return (mpDatabaseHandler->peekSink(name, sinkID)); -} - -am_Error_e CAmRoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID) -{ - return (mpControlSender->hookSystemRegisterSink(sinkData, sinkID)); -} - -am_Error_e CAmRoutingReceiver::deregisterSink(const am_sinkID_t sinkID) -{ - return (mpControlSender->hookSystemDeregisterSink(sinkID)); -} - -am_Error_e CAmRoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID) -{ - return (mpDatabaseHandler->peekSource(name, sourceID)); -} - -am_Error_e CAmRoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID) -{ - return (mpControlSender->hookSystemRegisterSource(sourceData, sourceID)); -} - -am_Error_e CAmRoutingReceiver::deregisterSource(const am_sourceID_t sourceID) -{ - return (mpControlSender->hookSystemDeregisterSource(sourceID)); -} - -am_Error_e CAmRoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID) -{ - return (mpControlSender->hookSystemRegisterCrossfader(crossfaderData, crossfaderID)); -} - -am_Error_e CAmRoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID) -{ - return (mpControlSender->hookSystemDeregisterCrossfader(crossfaderID)); -} - -void CAmRoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) -{ - return (mpControlSender->hookSystemInterruptStateChange(sourceID, interruptState)); -} - -void CAmRoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID) -{ - mpControlSender->hookSystemDomainRegistrationComplete(domainID); -} - -void CAmRoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mpControlSender->hookSystemSinkAvailablityStateChange(sinkID, availability); -} - -void CAmRoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mpControlSender->hookSystemSourceAvailablityStateChange(sourceID, availability); -} - -void CAmRoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) -{ - mpControlSender->hookSystemDomainStateChange(domainID, domainState); -} - -void CAmRoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) -{ - mpDatabaseHandler->changeConnectionTimingInformation(connectionID, delay); - mpControlSender->hookSystemSingleTimingInformationChanged(connectionID,delay); -} - -void CAmRoutingReceiver::sendChangedData(const std::vector & earlyData) -{ - mpControlSender->hookSystemReceiveEarlyData(earlyData); -} - -am_Error_e CAmRoutingReceiver::peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) -{ - return (mpDatabaseHandler->peekSinkClassID(name, sinkClassID)); -} - -am_Error_e CAmRoutingReceiver::peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) -{ - return (mpDatabaseHandler->peekSourceClassID(name, sourceClassID)); -} - -#ifdef WITH_DBUS_WRAPPER -am_Error_e CAmRoutingReceiver::getDBusConnectionWrapper(CAmDbusWrapper *& dbusConnectionWrapper) const -{ - dbusConnectionWrapper = mpDBusWrapper; - return (E_OK); -#else -am_Error_e CAmRoutingReceiver::getDBusConnectionWrapper(CAmDbusWrapper *& ) const -{ - return (E_UNKNOWN); -#endif -} - -am_Error_e CAmRoutingReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const -{ - socketHandler = mpSocketHandler; - return (E_OK); -} - -void CAmRoutingReceiver::getInterfaceVersion(std::string & version) const -{ - version = RoutingVersion; -} - -void CAmRoutingReceiver::confirmRoutingReady(const uint16_t handle, const am_Error_e error) -{ - if (error!=E_OK) - mLastStartupError=error; - mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); - if (mWaitStartup && mListStartupHandles.empty()) - mpControlSender->confirmRoutingReady(mLastStartupError); -} - -void CAmRoutingReceiver::confirmRoutingRundown(const uint16_t handle, const am_Error_e error) -{ - if (error!=E_OK) - mLastRundownError=error; - mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); - if (mWaitRundown && mListRundownHandles.empty()) - mpControlSender->confirmRoutingRundown(mLastRundownError); -} - -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; - mLastStartupError=E_OK; -} - -void CAmRoutingReceiver::ackSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - mpDatabaseHandler->changeSinkNotificationConfigurationDB(handleData.sinkID,*handleData.notificationConfiguration); - } - - try - { - delete handleData.notificationConfiguration; - } - catch(...) - { - logError("exception while deleting handleData while ackSinkNotificationConfiguration"); - } - mpControlSender->cbAckSetSinkNotificationConfiguration(handle,error); -} - -void CAmRoutingReceiver::ackSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - mpDatabaseHandler->changeSourceNotificationConfigurationDB(handleData.sourceID,*handleData.notificationConfiguration); - } - try - { - delete handleData.notificationConfiguration; - } - catch(...) - { - logError("exception while deleting handleData while ackSourceNotificationConfiguration"); - } - mpControlSender->cbAckSetSourceNotificationConfiguration(handle,error); -} - -am_Error_e CAmRoutingReceiver::updateGateway(const am_gatewayID_t gatewayID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) -{ - return (mpControlSender->hookSystemUpdateGateway(gatewayID,listSourceFormats,listSinkFormats,convertionMatrix)); -} - -am_Error_e CAmRoutingReceiver::updateConverter(const am_converterID_t converterID, const std::vector& listSourceFormats, const std::vector& listSinkFormats, const std::vector& convertionMatrix) -{ - return (mpControlSender->hookSystemUpdateConverter(converterID,listSourceFormats,listSinkFormats,convertionMatrix)); -} - -am_Error_e CAmRoutingReceiver::updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - return (mpControlSender->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -am_Error_e CAmRoutingReceiver::updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties) -{ - return (mpControlSender->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); -} - -void CAmRoutingReceiver::ackSetVolumes(const am_Handle_s handle, const std::vector& listvolumes, const am_Error_e error) -{ - CAmRoutingSender::am_handleData_c handleData; - if (mpRoutingSender->returnHandleDataAndRemove(handle,handleData)) - { - logError(__PRETTY_FUNCTION__,"Could not find handleData, handle: ",handle.handle); - return; - } - - if(error==am_Error_e::E_OK) - { - std::vector::const_iterator iterator (listvolumes.begin()); - - for (;iterator!=listvolumes.end();++iterator) - { - if (iterator->volumeType==VT_SINK) - { - mpDatabaseHandler->changeSinkVolume(iterator->volumeID.sink,iterator->volume); - } - else if (iterator->volumeType==VT_SOURCE) - { - mpDatabaseHandler->changeSourceVolume(iterator->volumeID.source,iterator->volume); - } - } - - } - - try - { - delete handleData.listVolumes; - } - catch(...) - { - logError("exception while deleting handleData while ackSetVolumes"); - } - - mpControlSender->cbAckSetVolume(handle,listvolumes,error); -} - -void CAmRoutingReceiver::hookSinkNotificationDataChange(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload) -{ - logInfo("CAmRoutingReceiver::hookSinkNotificationDataChange received, sinkID=",sinkID,"type=",payload.type,"notificationValue=",payload.value); - mpControlSender->hookSinkNotificationDataChanged(sinkID,payload); -} - -void CAmRoutingReceiver::hookSourceNotificationDataChange(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload) -{ - logInfo("CAmRoutingReceiver::hookSourceNotificationDataChange received, sinkID=",sourceID,"type=",payload.type,"notificationValue=",payload.value); - mpControlSender->hookSourceNotificationDataChanged(sourceID,payload); -} - -am_Error_e CAmRoutingReceiver::getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const -{ - return (mpDatabaseHandler->getDomainOfSink(sinkID,domainID)); -} - -am_Error_e CAmRoutingReceiver::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const -{ - return (mpDatabaseHandler->getDomainOfSource(sourceID,domainID)); -} - -am_Error_e CAmRoutingReceiver::getDomainOfCrossfader(const am_crossfaderID_t crossfader, am_domainID_t& domainID) const -{ - return (mpDatabaseHandler->getDomainOfCrossfader(crossfader,domainID)); -} - -void CAmRoutingReceiver::waitOnRundown(bool rundown) -{ - mWaitRundown = rundown; - mLastRundownError=E_OK; -} - -am_Error_e CAmRoutingSender::removeConnectionLookup(const am_connectionID_t connectionID) -{ - ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin(); - iter = mMapConnectionInterface.find(connectionID); - if (iter != mMapConnectionInterface.end()) - { - mMapConnectionInterface.erase(iter); - return (E_OK); - } - return (E_UNKNOWN); -} - -} diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp deleted file mode 100644 index efd44e1..0000000 --- a/AudioManagerDaemon/src/CAmRoutingSender.cpp +++ /dev/null @@ -1,833 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmRoutingSender.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmRoutingSender.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "CAmRoutingReceiver.h" -#include "TAmPluginTemplate.h" -#include "CAmDltWrapper.h" - -namespace am -{ - -#define REQUIRED_INTERFACE_VERSION_MAJOR 1 //!< major interface version. All versions smaller than this will be rejected -#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< minor interface version. All versions smaller than this will be rejected - -CAmRoutingSender::CAmRoutingSender(const std::vector& listOfPluginDirectories) : - mHandleCount(0), // - mlistActiveHandles(), // - mListInterfaces(), // - mMapConnectionInterface(), // - mMapCrossfaderInterface(), // - mMapDomainInterface(), // - mMapSinkInterface(), // - mMapSourceInterface(), // - mMapHandleInterface(), // - mpRoutingReceiver() -{ - - if (listOfPluginDirectories.empty()) - { - logError("CAmRoutingSender::CAmRoutingSender: List of routingplugins is empty"); - } - - 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; - std::string fullName = *dirIter + "/" + entryName; - - bool regularFile = (entryType == DT_REG || entryType == DT_LNK); - bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); - - // Handle cases where readdir() could not determine the file type - if (entryType == DT_UNKNOWN) { - struct stat buf; - - if (stat(fullName.c_str(), &buf)) { - logInfo(__PRETTY_FUNCTION__,"Failed to stat file: ", entryName, errno); - continue; - } - - regularFile = S_ISREG(buf.st_mode); - } - - 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"); - dlclose(tempLibHandle); - 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"); - dlclose(tempLibHandle); - 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) -{ - mpRoutingReceiver = 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()) - { - removeHandle(handle); - 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_CustomConnectionFormat_t 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)); - am_Error_e syncError(iter->second->asyncConnect(handle, connectionID, sourceID, sinkID, connectionFormat)); - - if (syncError) - { - removeHandle(handle); - removeConnectionLookup(connectionID); - } - return(syncError); - - } - - 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 syncError(iter->second->asyncDisconnect(handle, connectionID)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - - 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_CustomRampType_t 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)); - am_Error_e syncError(iter->second->asyncSetSinkVolume(handle, sinkID, volume, ramp, time)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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_CustomRampType_t 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)); - am_Error_e syncError(iter->second->asyncSetSourceVolume(handle, sourceID, volume, ramp, time)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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)); - am_Error_e syncError(iter->second->asyncSetSourceState(handle, sourceID, state)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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)); - am_Error_e syncError(iter->second->asyncSetSinkSoundProperty(handle, sinkID, soundProperty)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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)); - am_Error_e syncError(iter->second->asyncSetSourceSoundProperty(handle, sourceID, soundProperty)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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)); - am_Error_e syncError(iter->second->asyncSetSourceSoundProperties(handle, sourceID, listSoundProperties)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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)); - am_Error_e syncError(iter->second->asyncSetSinkSoundProperties(handle, sinkID, listSoundProperties)); - if (syncError) - { - removeHandle(handle); - delete handleData.soundProperties; - } - return(syncError); - } - 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_CustomRampType_t 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)); - am_Error_e syncError(iter->second->asyncCrossFade(handle, crossfaderID, hotSink, rampType, time)); - if (syncError) - { - removeHandle(handle); - } - return(syncError); - } - 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); -} - -/** - * @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 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); - } - } - logError(__PRETTY_FUNCTION__," Could not find busname for bus",domainData.busname); - return (E_UNKNOWN); -} - -/** - * @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 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); - } - logError(__PRETTY_FUNCTION__," Could not find domainInterface for domainID",sourceData.domainID); - return (E_UNKNOWN); -} - -/** - * @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 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); - } - logError(__PRETTY_FUNCTION__,"Could not find domainInterface for domainID",sinkData.domainID); - return (E_UNKNOWN); -} - -/** - * @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 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); - } - logError(__PRETTY_FUNCTION__," Could not find sourceInterface for source",crossfaderData.sourceID); - return (E_UNKNOWN); -} - -/** - * @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 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); -} - -/** - * @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 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); -} - -/** - * @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 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); -} - -/** - * @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 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); -} - -/** - * removes a handle from the list - * @param handle to be removed - * @return E_OK in case of success - */ -am_Error_e CAmRoutingSender::removeHandle(const am_Handle_s& handle) -{ - if (mlistActiveHandles.erase(handle)) - { - return (E_OK); - } - logError(__PRETTY_FUNCTION__,"Could not remove handle",handle.handle); - 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); -} - -/** - * 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 CAmRoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type) -{ - am_Handle_s handle; - if (++mHandleCount>=1024) //defined by 10 bit (out if structure!) - mHandleCount=1; - handle.handle = mHandleCount; - handle.handleType = type; - mlistActiveHandles.insert(std::make_pair(handle, handleData)); - if ((mlistActiveHandles.size()%100) == 0) - logInfo("CAmRoutingSender::createHandle warning: too many open handles, number of handles: ", mlistActiveHandles.size()); - logInfo(__PRETTY_FUNCTION__,handle.handle, handle.handleType); - return (handle); -} - -/** - * returns the data that belong to handles - * @param handle the handle - * @return a class holding the handle data - */ -am_Error_e CAmRoutingSender::returnHandleData(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) const -{ - HandlesMap::const_iterator it = mlistActiveHandles.begin(); - it = mlistActiveHandles.find(handle); - if (it!=mlistActiveHandles.end()) - { - handleData = it->second; - return (am_Error_e::E_OK); - } - handleData.sinkID=0; - logError(__PRETTY_FUNCTION__,"could not find handle data for handle",handle.handle,handle.handleType); - return (am_Error_e::E_NON_EXISTENT); -} - -void CAmRoutingSender::setRoutingReady() -{ - mpRoutingReceiver->waitOnStartup(false); - - //create a list of handles - std::vector listStartupHandles; - for (size_t i = 0; i < mListInterfaces.size(); i++) - { - listStartupHandles.push_back(mpRoutingReceiver->getStartupHandle()); - } - - //set the receiver ready to wait for replies - mpRoutingReceiver->waitOnStartup(true); - - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - std::vector::const_iterator handleIter(listStartupHandles.begin()); - for (; iter < iterEnd; ++iter) - { - (*iter).routingInterface->setRoutingReady(*(handleIter++)); - } -} - -void CAmRoutingSender::setRoutingRundown() -{ - mpRoutingReceiver->waitOnRundown(false); - //create a list of handles - std::vector listStartupHandles; - for (size_t i = 0; i < mListInterfaces.size(); i++) - { - listStartupHandles.push_back(mpRoutingReceiver->getRundownHandle()); - } - - //set the receiver ready to wait for replies - mpRoutingReceiver->waitOnRundown(true); - - std::vector::iterator iter = mListInterfaces.begin(); - std::vector::iterator iterEnd = mListInterfaces.end(); - std::vector::const_iterator handleIter(listStartupHandles.begin()); - for (; iter < iterEnd; ++iter) - { - (*iter).routingInterface->setRoutingRundown(*(handleIter++)); - } -} - -am_Error_e CAmRoutingSender::asyncSetVolumes(am_Handle_s& handle, const std::vector& listVolumes) -{ - am_handleData_c handleData; - IAmRoutingSend* pRoutingInterface(NULL); - if (listVolumes.empty()) - return (E_NOT_POSSIBLE); - - //we need an interface so lets get either the sink or source ID from the first entry in the listVolumes - if (listVolumes[0].volumeType==VT_SINK) - { - am_sinkID_t sinkID=listVolumes[0].volumeID.sink; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if(iter!=mMapSinkInterface.end()) - pRoutingInterface=iter->second; - else - return(E_NON_EXISTENT); - } - - else if (listVolumes[0].volumeType==VT_SOURCE) - { - am_sourceID_t sourceID=listVolumes[0].volumeID.source; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter!=mMapSourceInterface.end()) - pRoutingInterface=iter->second; - else - return(E_NON_EXISTENT); - } - else - return (E_NON_EXISTENT); - - handleData.volumeID=listVolumes[0].volumeID; - handleData.listVolumes= new std::vector(listVolumes); - handle = createHandle(handleData, H_SETVOLUMES); - - mMapHandleInterface.insert(std::make_pair(+ handle.handle, pRoutingInterface)); - am_Error_e syncError(pRoutingInterface->asyncSetVolumes(handle, listVolumes)); - if (syncError) - { - removeHandle(handle); - delete handleData.listVolumes; - } - return(syncError); - -} - -am_Error_e CAmRoutingSender::asyncSetSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - am_handleData_c handleData; - SinkInterfaceMap::iterator iter = mMapSinkInterface.begin(); - iter = mMapSinkInterface.find(sinkID); - if (iter != mMapSinkInterface.end()) - { - handleData.sinkID = sinkID; - handleData.notificationConfiguration = new am_NotificationConfiguration_s(notificationConfiguration); - handle = createHandle(handleData, H_SETSINKNOTIFICATION); - mMapHandleInterface.insert(std::make_pair(+ handle.handle, iter->second)); - am_Error_e syncError(iter->second->asyncSetSinkNotificationConfiguration(handle, sinkID,notificationConfiguration)); - if (syncError) - { - removeHandle(handle); - delete handleData.notificationConfiguration; - } - return(syncError); - } - return (E_NON_EXISTENT); -} - -am_Error_e CAmRoutingSender::asyncSetSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) -{ - am_handleData_c handleData; - SourceInterfaceMap::iterator iter = mMapSourceInterface.begin(); - iter = mMapSourceInterface.find(sourceID); - if (iter != mMapSourceInterface.end()) - { - handleData.sourceID = sourceID; - handleData.notificationConfiguration = new am_NotificationConfiguration_s(notificationConfiguration); - handle = createHandle(handleData, H_SETSOURCENOTIFICATION); - mMapHandleInterface.insert(std::make_pair(+ handle.handle, iter->second)); - am_Error_e syncError(iter->second->asyncSetSourceNotificationConfiguration(handle, sourceID,notificationConfiguration)); - if (syncError) - { - removeHandle(handle); - delete handleData.notificationConfiguration; - } - return(syncError); - } - return (E_NON_EXISTENT); -} - -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 = RoutingVersion; -} -am_Error_e CAmRoutingSender::resyncConnectionState(const am_domainID_t domainID,std::vector& listOfExistingConnections) -{ - DomainInterfaceMap::iterator iter = mMapDomainInterface.begin(); - iter = mMapDomainInterface.find(domainID); - if (iter != mMapDomainInterface.end()) - return (iter->second->resyncConnectionState(domainID, listOfExistingConnections)); - return (E_NON_EXISTENT); -} - -am_Error_e CAmRoutingSender::returnHandleDataAndRemove(const am_Handle_s handle,CAmRoutingSender::am_handleData_c& handleData) -{ - HandlesMap::const_iterator it = mlistActiveHandles.begin(); - it = mlistActiveHandles.find(handle); - if (it!=mlistActiveHandles.end()) - { - handleData = it->second; - mlistActiveHandles.erase(handle); - return (am_Error_e::E_OK); - } - handleData.sinkID=0; - logError(__PRETTY_FUNCTION__,"could not find handle data for handle",handle.handle,handle.handleType); - return (am_Error_e::E_NON_EXISTENT); - -} - -} diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp deleted file mode 100644 index 2aae4f5..0000000 --- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp +++ /dev/null @@ -1,1438 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetMenuHelper.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmTelnetMenuHelper.h" -#include -#include "audiomanagerconfig.h" -#include "CAmRouter.h" -#include "CAmTelnetServer.h" -#include "IAmDatabaseHandler.h" -#include "CAmControlSender.h" -#include "CAmCommandSender.h" -#include "CAmRoutingSender.h" -#include "CAmRoutingReceiver.h" -#include "CAmCommandReceiver.h" -#include "CAmControlReceiver.h" -#include "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"); - - -namespace am { - -CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL; - -/****************************************************************************/ -CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *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) -{ - instance = this; - createCommandMaps(); -} - -/****************************************************************************/ -CAmTelnetMenuHelper::~CAmTelnetMenuHelper() -/****************************************************************************/ -{ -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::createCommandMaps() -/****************************************************************************/ -{ - // ROOT commands - mRootCommands.clear(); - mRootCommands.insert(std::make_pair("help", sCommandPrototypeInfo("show all possible commands", &CAmTelnetMenuHelper::helpCommand))); - mRootCommands.insert(std::make_pair("list", sCommandPrototypeInfo("Go into 'list'-submenu", &CAmTelnetMenuHelper::rootListCommand))); - mRootCommands.insert(std::make_pair("info", sCommandPrototypeInfo("Go into 'info'-submenu", &CAmTelnetMenuHelper::rootInfoCommand))); - mRootCommands.insert(std::make_pair("set", sCommandPrototypeInfo("Go into 'set'-submenu", &CAmTelnetMenuHelper::rootSetCommand))); - mRootCommands.insert(std::make_pair("get", sCommandPrototypeInfo("Go into 'get'-submenu", &CAmTelnetMenuHelper::rootGetCommand))); - mRootCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("quit telnet session", &CAmTelnetMenuHelper::exitCommand))); - // List commands - mListCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); - mListCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("list all connections", &CAmTelnetMenuHelper::listConnectionsCommand))); - mListCommands.insert(std::make_pair("sources", sCommandPrototypeInfo("list all available sources", &CAmTelnetMenuHelper::listSourcesCommand))); - mListCommands.insert(std::make_pair("sinks", sCommandPrototypeInfo("list all available sinks", &CAmTelnetMenuHelper::listSinksCommands))); - mListCommands.insert(std::make_pair("crfader", sCommandPrototypeInfo("list all crossfaders", &CAmTelnetMenuHelper::listCrossfaders))); - mListCommands.insert(std::make_pair("domains", sCommandPrototypeInfo("list all domains", &CAmTelnetMenuHelper::listDomainsCommand))); - mListCommands.insert(std::make_pair("gws", sCommandPrototypeInfo("list all gateways", &CAmTelnetMenuHelper::listGatewaysCommand))); - mListCommands.insert(std::make_pair("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand))); - mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand))); - mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand))); - mListCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); - mListCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); - // Set commands - mSetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); - mSetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); - mSetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); - mSetCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink", &CAmTelnetMenuHelper::setConnection))); - mSetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("use 'routing sourceId sinkId' to get all\n\t possible routes between a sourceID and a sinkID", &CAmTelnetMenuHelper::setRoutingCommand))); - mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection", &CAmTelnetMenuHelper::setDisconnectConnId))); - mSetCommands.insert(std::make_pair("sinkvolume", sCommandPrototypeInfo("use 'sinkvolume sinkID volume' to set \n\t absorption in db of sink", &CAmTelnetMenuHelper::setSinkVolume))); - mSetCommands.insert(std::make_pair("sinkvolstep", sCommandPrototypeInfo("use 'sinkvolstep sinkID volumestep' to increment \n\t or decrement volume", &CAmTelnetMenuHelper::setVolumeStep))); - mSetCommands.insert(std::make_pair("sinkprop", sCommandPrototypeInfo("use 'sinkprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSinkSoundProperty))); - mSetCommands.insert(std::make_pair("sinkmute", sCommandPrototypeInfo("use 'sinkmute sinkid mutestate' to mute \n\t or unmute", &CAmTelnetMenuHelper::setSinkMuteState))); - mSetCommands.insert(std::make_pair("sourceprop", sCommandPrototypeInfo("use 'sourceprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSourceSoundProperty))); - // Get commands - mGetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); - mGetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("show current routing", &CAmTelnetMenuHelper::getRoutingCommand))); - mGetCommands.insert(std::make_pair("sendv", sCommandPrototypeInfo("show senderversion", &CAmTelnetMenuHelper::getSenderversionCommand))); - mGetCommands.insert(std::make_pair("recv", sCommandPrototypeInfo("show receiverversion ", &CAmTelnetMenuHelper::getReceiverversionCommand))); - mGetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); - mGetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); - // Info comands - mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand))); - mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand))); - mInfoCommands.insert(std::make_pair("dump", sCommandPrototypeInfo("create a database dump of currently used data", &CAmTelnetMenuHelper::infoDumpCommand))); - mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand))); - mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand))); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor) -/****************************************************************************/ -{ - EMainState state = eRootState; - std::map::iterator it; - std::stringstream welcome; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - // socket connection already exists, delete entry and go back to root state - mCurrentMainStateMap.erase(it); - } - it = mCurrentMainStateMap.begin(); - // insert new socket connection - mCurrentMainStateMap.insert(it, std::make_pair(filedescriptor, state)); - // Send welcome message - welcome << COLOR_WELCOME << "Welcome to GENIVI AudioManager " << DAEMONVERSION << COLOR_DEFAULT << "\n>"; - assert(send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0)>=0); - logInfo("[TN] New connection: ", filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor) -/****************************************************************************/ -{ - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - mCurrentMainStateMap.erase(it); - } - else - { - logError("[TN] socketConnectionsClosed, fd not found, ", filedescriptor); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::enterCmdQueue(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - std::map::iterator it; - std::string cmd; - tCommandMap::iterator cmditer; - // find current filedescriptor to get the current state of the telnet session - it = mCurrentMainStateMap.find(filedescriptor); - while (!CmdQueue.empty()) - { - cmd = CmdQueue.front(); - // Now remove the first command, it's stored in 'cmd' - CmdQueue.pop(); - // telnet session found. depending on the current state, different commands are available - switch (it->second) - { - case eRootState: - cmditer = mRootCommands.find(cmd); - if (mRootCommands.end() != cmditer) - cmditer->second.CommandPrototype(CmdQueue, filedescriptor); - else - sendError(filedescriptor, "Command not found\n"); - - break; - case eListState: - cmditer = mListCommands.find(cmd); - if (mListCommands.end() != cmditer) - cmditer->second.CommandPrototype(CmdQueue, filedescriptor); - else - sendError(filedescriptor, "Command not found\n"); - - break; - case eInfoState: - cmditer = mInfoCommands.find(cmd); - if (mInfoCommands.end() != cmditer) - cmditer->second.CommandPrototype(CmdQueue, filedescriptor); - else - sendError(filedescriptor, "Command not found\n"); - - break; - case eGetState: - cmditer = mGetCommands.find(cmd); - if (mGetCommands.end() != cmditer) - cmditer->second.CommandPrototype(CmdQueue, filedescriptor); - else - sendError(filedescriptor, "Command not found\n"); - - break; - case eSetState: - cmditer = mSetCommands.find(cmd); - if (mSetCommands.end() != cmditer) - cmditer->second.CommandPrototype(CmdQueue, filedescriptor); - else - sendError(filedescriptor, "Command not found\n"); - - break; - default: - break; - } - } - - sendCurrentCmdPrompt(filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::sendError(int& filedescriptor, std::string error_string) -/****************************************************************************/ -{ - assert(send(filedescriptor, error_string.c_str(), error_string.size(), 0)>=0); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::sendTelnetLine(int& filedescriptor, std::stringstream& line) -/****************************************************************************/ -{ - assert(send(filedescriptor, line.str().c_str(), line.str().size(), 0)>=0); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int& filedescriptor) -/****************************************************************************/ -{ - std::map::iterator it; - std::stringstream outputstream; - outputstream << std::endl; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - switch (it->second) - { - case eRootState: - outputstream << "\\>"; - break; - case eListState: - outputstream << "\\List>"; - break; - case eGetState: - outputstream << "\\Get>"; - break; - case eSetState: - outputstream << "\\Set>"; - break; - case eInfoState: - outputstream << "\\Info>"; - break; - default: - break; - } - assert(send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0)>=0); - } - else - { - logInfo("[TN] sendCurrentCmdPrompt, fd not found: ", filedescriptor); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::exitCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->exitCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - switch (it->second) - { - case eRootState: - it->second = eRootState; - break; - case eListState: - it->second = eRootState; - ; - break; - case eGetState: - it->second = eRootState; - ; - break; - case eSetState: - it->second = eRootState; - ; - break; - case eInfoState: - it->second = eRootState; - ; - break; - default: - it->second = eRootState; - break; - } - logInfo("[TN] oneStepBackCommandExec, state: ", it->second); - } - -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::oneStepBackCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->oneStepBackCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::exitCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - std::stringstream line; - std::stringstream output; - // Sending a last message to the client - output << "bye!" << COLOR_DEFAULT << std::endl; - sendTelnetLine(filedescriptor, output); - tCommandMap::iterator iter; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - if (NULL != mpTelenetServer) - { - logInfo("[TN] exitCommandExec, removing fd ", filedescriptor); - mpTelenetServer->disconnectClient(filedescriptor); - mCurrentMainStateMap.erase(it); - } - else - { - logError("[TN] exitCommandExec, mpTelenetServer == NULL, fd ", filedescriptor); - } - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::helpCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->helpCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::helpCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - std::stringstream line; - tCommandMap::iterator cmdIter; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl; - line << COLOR_HEAD << "###### The following commands are supported: ######" << COLOR_DEFAULT << std::endl; - line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl << std::endl; - switch (it->second) - { - case eRootState: - cmdIter = mRootCommands.begin(); - while (cmdIter != mRootCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eListState: - cmdIter = mListCommands.begin(); - while (cmdIter != mListCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eGetState: - cmdIter = mGetCommands.begin(); - while (cmdIter != mGetCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eSetState: - cmdIter = mSetCommands.begin(); - while (cmdIter != mSetCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eInfoState: - cmdIter = mInfoCommands.begin(); - while (cmdIter != mInfoCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - default: - break; - } - - sendTelnetLine(filedescriptor, line); - } - -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootGetCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootGetCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootGetCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eGetState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootSetCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootSetCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootSetCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eSetState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootListCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootListCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootListCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eListState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootInfoCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootInfoCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eInfoState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listConnectionsCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listConnectionsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Connection_s > listConnections; - if (E_OK == mpDatabasehandler->getListConnections(listConnections)) - { - std::stringstream output; - output << "\tConnections: " << listConnections.size() << std::endl; - for (std::vector::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++) - { - output << "\tID: " << iter->connectionID << "\tSrcID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << "\tFormat: " << iter->connectionFormat << "\tdelay: " << iter->delay << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListConnections"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSourcesCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listSourcesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Source_s > listSources; - if (E_OK == mpDatabasehandler->getListSources(listSources)) - { - std::stringstream output; - output << "\tSources: " << listSources.size() << std::endl; - for (std::vector::iterator iter(listSources.begin()); iter < listSources.end(); iter++) - { - output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tDomainID: " << iter->domainID << "\tState: " << iter->sourceState << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSources"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSinksCommands(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listSinksCommandsExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Sink_s > listSinks; - if (E_OK == mpDatabasehandler->getListSinks(listSinks)) - { - std::stringstream output; - output << "\tSinks: " << listSinks.size() << std::endl; - for (std::vector::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++) - { - output << "\tID: " << iter->sinkID << "\tDomainID: " << iter->domainID << "\tName: " << iter->name << "\tAvailable: " << iter->available.availability << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSinks"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listCrossfaders(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listCrossfadersExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listCrossfadersExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Crossfader_s > listCrossfaders; - if (E_OK == mpDatabasehandler->getListCrossfaders(listCrossfaders)) - { - std::stringstream output; - output << "\tCrossfader: " << listCrossfaders.size() << std::endl; - for (std::vector::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++) - { - output << "\tID: " << iter->crossfaderID << "\tName: " << iter->name << "\tSinkA: " << iter->sinkID_A << "\tSinkB: " << iter->sinkID_B << "\tSourceID: " << iter->sourceID << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListCrossfaders"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listDomainsCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listDomainsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Domain_s > listDomains; - if (E_OK == mpDatabasehandler->getListDomains(listDomains)) - { - std::stringstream output; - output << "\tDomains: " << listDomains.size() << std::endl; - for (std::vector::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++) - { - output << "\tID: " << iter->domainID << "\tName: " << iter->name << "\tBusname: " << iter->busname << "\tNodename: " << iter->nodename << "\tState: " << static_cast(iter->state) << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListDomains"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listGatewaysCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listGatewaysCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Gateway_s > listGateways; - if (E_OK == mpDatabasehandler->getListGateways(listGateways)) - { - std::stringstream output; - output << "\tGateways: " << listGateways.size(); - for (std::vector::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++) - { - output << "\tID: " << iter->gatewayID << "\tName: " << iter->name << "\tSourceID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListGateways"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getRoutingCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getRoutingCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - (void) (filedescriptor); -//TODO: fill with function -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getSenderversionCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getSenderversionCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::stringstream output; - std::string versionCommand; - std::string versionRouting; - std::string versionControl; - mpControlSender->getInterfaceVersion(versionControl); - mpRoutingSender->getInterfaceVersion(versionRouting); - mpCommandSender->getInterfaceVersion(versionCommand); - output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getReceiverversionCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::stringstream output; - std::string versionCommand; - std::string versionRouting; - std::string versionControl; - mpControlReceiver->getInterfaceVersion(versionControl); - mpRoutingReceiver->getInterfaceVersion(versionRouting); - mpCommandReceiver->getInterfaceVersion(versionCommand); - output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoDumpCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->infoDumpCommandExec(CmdQueue, filedescriptor); -} - - -/****************************************************************************/ -void CAmTelnetMenuHelper::setVolumeStep(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkVolumeExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setVolumeStepExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - int16_t volumestep = 0; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_volumestep(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_volumestep >> volumestep)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing setVolumeStep 'sinkID' or 'volumestep'"); - return; - } - if (E_OK == mpCommandReceiver->volumeStep(sinkID,volumestep)) - { - std::stringstream output; - output << "SetSinkVolumeStep set: " << sinkID << "->" << volumestep << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error SetSinkVolumeStep"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set SetSinkVolumeStep, please enter 'sinkID' and 'volumestep' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkMuteState(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkMuteStateExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkMuteStateExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - u_int16_t tmp = 0; - am_MuteState_e MuteState = MS_UNKNOWN; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_mutestate(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_mutestate >> tmp)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if(tmp < MS_MAX) - { - MuteState = static_cast(tmp); - } - else - { - sendError(filedescriptor, "You tried to set an invalid am_MuteState_e"); - error = true; - } - - if (error) - { - sendError(filedescriptor, "Error parsing setSinkMuteState 'sinkID' or 'mutestate'"); - return; - } - if (E_OK == mpCommandReceiver->setSinkMuteState(sinkID,MuteState)) - { - std::stringstream output; - output << "setSinkMuteState set: " << sinkID << "->" << MuteState << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setSinkMuteState"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setSinkMuteState, please enter 'sinkID' and 'mutestate' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundProperty(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSourceSoundPropertiesExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundPropertyExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - unsigned int tmpType = 0; - bool error = false; - if (CmdQueue.size() >= 3) - { - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_type(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_value(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_type >> tmpType)) - error = true; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing setMainSourceSoundProperty 'type', 'value' or 'sourceID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) - { - std::stringstream output; - output << "setMainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setMainSourceSoundProperty"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setMainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SystemProperty_s > listSystemProperties; - if (E_OK == mpDatabasehandler->getListSystemProperties(listSystemProperties)) - { - std::stringstream output; - output << "\tSystemproperties: " << listSystemProperties.size() << std::endl; - std::vector::iterator it; - for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++) - { - output << "\tType: " << it->type << " Value: " << it->value << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSystemProperties"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoDumpCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - - std::stringstream *pOutput = new std::stringstream(); - - mpDatabasehandler->dump(*pOutput); - - sendTelnetLine(filedescriptor, *pOutput); - - delete pOutput; -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setRoutingCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setRoutingCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - bool error = false; - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing sourcID and sinkID"); - return; - } - std::vector < am_Route_s > routingList; - if (E_OK == mpRouter->getRoute(true, sourceID, sinkID, routingList)) - { - std::stringstream output; - std::vector::iterator rlIter = routingList.begin(); - for (int rlCnt = 1; rlIter < routingList.end(); rlIter++) - { - output << "#" << rlCnt << " "; - std::vector::iterator reIter = rlIter->route.begin(); - for (; reIter < rlIter->route.end(); reIter++) - { - output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl; - } - rlCnt++; - } - - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error getting route"); - } - } - else - { - if (!CmdQueue.empty()) - CmdQueue.pop(); - - sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setConnection(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setConnectionExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setConnectionExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - bool error = false; - am_Error_e rError = E_OK; - if (CmdQueue.size() >= 2) - { - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing sinkID and/or sourceID"); - return; - } -// Try to set up connection - am_mainConnectionID_t connID = 0; - rError = mpCommandReceiver->connect(sourceID, sinkID, connID); - if (E_OK == rError) - { - std::stringstream output; - output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error connecting sourceID and sinkID"); - } - } - else - { -// remove 1 element if list is not empty - if (!CmdQueue.empty()) - CmdQueue.pop(); - - sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setDisconnectConnId(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setDisconnectConnIdExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - am_mainConnectionID_t connID = 0; - bool error = false; - am_Error_e rError = E_OK; - if (CmdQueue.size() >= 1) - { - std::istringstream istream_connID(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_connID >> connID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing connID"); - return; - } -// Try to disconnect connection id - rError = mpCommandReceiver->disconnect(connID); - if (E_OK == rError) - { - std::stringstream output; - output << "ConnID " << connID << " closed successfully! " << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error disconnecting connectionID"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setConnectionExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 3) - { - bool error = false; - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_type(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_value(CmdQueue.front()); - CmdQueue.pop(); - unsigned int tmpType = 0; - if (!(istream_type >> tmpType)) - error = true; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sinkID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) - { - std::stringstream output; - output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setMainSourceSoundProperty"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkSoundProperty(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkSoundPropertyExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkSoundPropertyExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - unsigned int tmpType = 0; - bool error = false; - if (CmdQueue.size() >= 3) - { - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_type(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_value(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_type >> tmpType)) - error = true; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID)) - { - std::stringstream output; - output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setMainSinkSoundProperty"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkVolume(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkVolumeExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkVolumeExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - am_volume_t volume = 0; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_volume(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_volume >> volume)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing SetSinkVolume 'sinkID' or 'volume'"); - return; - } - if (E_OK == mpCommandReceiver->setVolume(sinkID,volume)) - { - std::stringstream output; - output << "setVolume set: " << sinkID << "->" << volume << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setVolume"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setVolume, please enter 'sinkID' and 'volume' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listPluginsCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listPluginsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < std::string > PlugInNames; - std::vector::iterator iter; - std::stringstream output; - if (E_OK == mpCommandSender->getListPlugins(PlugInNames)) - { - output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl; - for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) - { - output << iter->c_str() << std::endl; - } - } - else - { - sendError(filedescriptor, "ERROR: mCommandSender->getListPlugins"); - } - if (E_OK == mpRoutingSender->getListPlugins(PlugInNames)) - { - output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl; - for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) - { - output << iter->c_str() << std::endl; - } - } - else - { - sendError(filedescriptor, "ERROR: mRoutingSender->getListPlugins"); - } - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainSourcesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SourceType_s > listMainSources; - if (E_OK == mpDatabasehandler->getListMainSources(listMainSources)) - { - std::stringstream output; - output << std::endl << "\tMainSources: " << listMainSources.size() << std::endl; - std::vector::iterator iter; - for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++) - { - output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tsourceClassID: " << iter->sourceClassID << "\tavailability: " << iter->availability.availability << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSources"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSinksCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainSinksCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SinkType_s > listMainSinks; - if (E_OK == mpDatabasehandler->getListMainSinks(listMainSinks)) - { - std::stringstream output; - output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl; - std::vector::iterator iter; - for (iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++) - { - output << "\tID: " << iter->sinkID << "\tsinkClassID: " << iter->sinkClassID << "\tName: " << iter->name << "\tAvailable: " << iter->availability.availability << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSinks"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainConnectionsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector listMainConnections; - - if(E_OK == mpDatabasehandler->getListMainConnections(listMainConnections)) - { - std::stringstream output; - output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl; - - std::vector::iterator iter; - for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++) - { - output << "\tID: " << iter->mainConnectionID - << "\tState: " << iter->connectionState - << "\tDelay: " << iter->delay - << "\tsourceID: " << iter->sourceID - << "\tsinkID: " << iter->sinkID << std::endl; - - output << "ConnectionIDs: "; - std::vector::iterator list_connIDs_iter = iter->listConnectionID.begin(); - for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++) - { - output << *list_connIDs_iter << " "; - } - - output << std::endl; - } - sendTelnetLine(filedescriptor,output); - } - else - { - sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks"); - } -} -} - - - - - diff --git a/AudioManagerDaemon/src/CAmTelnetServer.cpp b/AudioManagerDaemon/src/CAmTelnetServer.cpp deleted file mode 100755 index 22f7b0e..0000000 --- a/AudioManagerDaemon/src/CAmTelnetServer.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetServer.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmTelnetServer.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "CAmRoutingSender.h" -#include "CAmTelnetMenuHelper.h" -#include "CAmDltWrapper.h" - -namespace am -{ - -CAmTelnetServer* CAmTelnetServer::mpInstance = 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, IAmDatabaseHandler *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), // - mpSocketHandler(iSocketHandler), // - mpCommandSender(iCommandSender), // - mpCommandReceiver(iCommandReceiver), // - mpRoutingSender(iRoutingSender), // - mpRoutingReceiver(iRoutingReceiver), // - mpControlSender(iControlSender), // - mpControlReceiver(iControlReceiver), // - mpDatabasehandler(iDatabasehandler), // - mpRouter(iRouter), // - mConnecthandle(), // - mListMessages(), // - mListConnections(), // - mConnectFD(0), // - mServerPort(servPort), // - mMaxConnections(maxConnections), // - mTelnetMenuHelper(iSocketHandler, iCommandSender, iCommandReceiver, iRoutingSender, iRoutingReceiver, iControlSender, iControlReceiver, iDatabasehandler, iRouter, this) -{ - assert(mpSocketHandler!=NULL); - assert(mpCommandReceiver!=NULL); - assert(mpCommandSender!=NULL); - assert(mpControlSender!=NULL); - assert(mpControlReceiver!=NULL); - assert(mpRoutingSender!=NULL); - assert(mpRoutingReceiver!=NULL); - assert(mpDatabasehandler!=NULL); - assert(mpRouter!=NULL); - assert(servPort!=0); - assert(mMaxConnections!=0); - - mpInstance = this; - //mTelnetMenuHelper.setTelnetServer(this); - - int yes = 1; - struct sockaddr_in servAddr; - - //setup the port Listener - mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - assert (mConnectFD>0); - assert(setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==0); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = INADDR_ANY; - servAddr.sin_port = htons(servPort); - if(bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr))!=0) - { - logError("CAmTelnetServer::CAmTelnetServer bind failed, error",errno); - throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); - } - - if (listen(mConnectFD, mMaxConnections) < 0) - { - logError("TelnetServer::TelnetServerk cannot listen ", errno); - throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); - } - 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; - mpSocketHandler->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); - - assert(connection.filedescriptor>0); - - // Notiy menuhelper - mTelnetMenuHelper.newSocketConnection(connection.filedescriptor); - - //set the correct event: - short event = 0; - event |= POLLIN; - - //add the filedescriptor to the sockethandler and register the callbacks for receiving the data - mpSocketHandler->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 == mpSocketHandler->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, 0); - 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); - mListMessages.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()) - { - logError("CAmTelnetServer::dispatchData could not find handle !"); - return (false); - } - - std::string command; - std::queue MsgQueue; - if (!mListMessages.empty()) - { - sliceCommand(mListMessages.front(), command, MsgQueue); - mListMessages.pop(); - mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor); - } - else - { - logError("CAmTelnetServer::dispatchData Message queue was empty!"); - } - - // must return false to stop endless polling - return (false); -} - -bool CAmTelnetServer::check(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - if (mListMessages.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++; - } -} -} - diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index 795795d..d71c02b 100755 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -79,7 +79,7 @@ std::vector listCommandPluginDirs; std::vector listRoutingPluginDirs; //commandline options used by the Audiomanager itself -TCLAP::ValueArg controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending",false,CONTROLLER_PLUGIN,"string"); +TCLAP::ValueArg controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending",false,CONTROLLER_PLUGIN_DIR,"string"); TCLAP::ValueArg additionalCommandPluginDirs("L","additionalCommandPluginDirs","additional path for looking for command plugins, can be used after -l option",false," ","string"); TCLAP::ValueArg additionalRoutingPluginDirs("R","additionalRoutingPluginDirs","additional path for looking for routing plugins, can be used after -r option ",false," ","string"); TCLAP::ValueArg routingPluginDir("r","RoutingPluginDir","path for looking for routing plugins",false," ","string"); @@ -87,8 +87,8 @@ TCLAP::ValueArg commandPluginDir("l","CommandPluginDir","path for l TCLAP::ValueArg databasePath ("p","databasePath","path for sqlite database (default is in memory)",false,":memory:","string"); TCLAP::ValueArg telnetPort ("t","telnetport","The port that is used for telnet",false,DEFAULT_TELNETPORT,"int"); TCLAP::ValueArg maxConnections ("m","maxConnections","Maximal number of connections for telnet",false,MAX_TELNETCONNECTIONS,"int"); -TCLAP::SwitchArg dbusWrapperTypeBool ("t","dbusType","DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",false); -TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout",false); +TCLAP::SwitchArg dbusWrapperTypeBool ("T","dbusType","DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",false); +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon, default on",true); TCLAP::SwitchArg currentSettings("i","currentSettings","print current settings and exit",false); TCLAP::SwitchArg daemonizeAM("d","daemonize","daemonize Audiomanager. Better use systemd...",false); @@ -104,8 +104,7 @@ int fd0, fd1, fd2; void OutOfMemoryHandler() { logError("No more memory - bye"); - //todo: add gracefull dead here. Do what can be done persistence wise - exit(1); + throw std::runtime_error(std::string("SocketHandler::start_listenting ppoll returned with error.")); } /** @@ -169,9 +168,6 @@ void printCmdInformation() printf("\tTelnet portNumber:\t\t\t%i\n", telnetPort.getValue()); printf("\tTelnet maxConnections:\t\t\t%i\n", maxConnections.getValue()); #endif -#ifdef WITH_DATABASE_STORAGE - printf("\tSqlite Database path:\t\t\t%s\n", databasePath.getValue().c_str()); -#endif #ifndef WITH_DLT printf("\tDlt Command Line Output: \t\t%s\n", enableNoDLTDebug.getValue()?"enabled":"not enabled"); #endif @@ -248,9 +244,7 @@ void mainProgram(int argc, char *argv[]) cmd->add(routingPluginDir); cmd->add(currentSettings); cmd->add(daemonizeAM); -#ifndef WITH_DLT cmd->add(enableNoDLTDebug); -#endif #ifdef WITH_DBUS_WRAPPER cmd->add(dbusWrapperTypeBool); #endif diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp deleted file mode 100644 index 9f58a5a..0000000 --- a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp +++ /dev/null @@ -1,662 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmControlInterfaceTest.h" -#include -#include -#include -#include -#include "CAmDltWrapper.h" - -using namespace am; -using namespace testing; - -DLT_DECLARE_CONTEXT(AudioManager) - -ACTION(returnResyncConnection) -{ - std::vector listConnections; - am_Connection_s conn; - conn.sinkID=1; - conn.sourceID=1; - conn.connectionFormat=CF_GENIVI_ANALOG; - listConnections.push_back(conn); - arg1=listConnections; -} - -CAmControlInterfaceTest::CAmControlInterfaceTest() : - pSocketHandler(), // - plistCommandPluginDirs(), // - plistRoutingPluginDirs(), // - pDatabaseHandler(), // - pRoutingSender(plistRoutingPluginDirs), //RoutingReceiver - pCommandSender(plistCommandPluginDirs), // - pMockControlInterface(), // - pMockRoutingInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlInterfaceBackdoor(), // - pControlSender(), // - pRouter(&pDatabaseHandler,&pControlSender), // - pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler) -{ - CAmDltWrapper::instance(0)->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); - CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); - logInfo("The Audiomanager is started"); - 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 = DYNAMIC_ID_BOUNDARY; - - //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)); - //needed to be removed because logic changed here -} - -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 = DYNAMIC_ID_BOUNDARY; - - //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,ackDisconnectFailAndRetry) -{ - logInfo("ackDisconnectFailAndRetry test started"); - 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 = DYNAMIC_ID_BOUNDARY; - - //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_NON_EXISTENT)).Times(1); - pRoutingReceiver.ackDisconnect(handle, connectionID+1, E_NON_EXISTENT); - - //make sure the handle is gone - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - //make sure the connection is still there - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_FALSE(connectionList.empty()); - - ASSERT_TRUE(pDatabaseHandler.existConnectionID(1)); - - //Now let's try to disconnect now - EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); - ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); - logInfo("ackDisconnectFailAndRetry test finished"); -} - -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 = DYNAMIC_ID_BOUNDARY; - - //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)); - //needed to be removed because logic changed here -} - -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 = DYNAMIC_ID_BOUNDARY; - 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)); - //needed to be removed because logic changed here -} - -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 = DYNAMIC_ID_BOUNDARY; - 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)); - //needed to be removed because logic changed here -} - -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; - int16_t oldvalue; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = DYNAMIC_ID_BOUNDARY; - soundProperty.type = SP_GENIVI_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_GENIVI_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_GENIVI_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)); - //needed to be removed because logic changed here -} - -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; - int16_t oldvalue; - pCF.createSource(source); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - source.sourceID = 2; - source.domainID = DYNAMIC_ID_BOUNDARY; - soundProperty.type = SP_GENIVI_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_GENIVI_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_GENIVI_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)); - //needed to be removed because logic changed here -} - -TEST_F(CAmControlInterfaceTest,crossFading) -{ - //todo: implement crossfading test -} - -TEST_F(CAmControlInterfaceTest,resyncConnectionsTest) -{ - am_Domain_s domain; - am_domainID_t domainID; - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - - //prepare the scene - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - - std::vector listConnections; - - EXPECT_CALL(pMockRoutingInterface,resyncConnectionState(domainID,_)).WillOnce(DoAll(returnResyncConnection(), Return(E_OK))); - ASSERT_EQ(am_Error_e::E_OK,pControlReceiver.resyncConnectionState(domainID,listConnections)); - ASSERT_EQ(listConnections[0].sinkID,1); - ASSERT_EQ(listConnections[0].sourceID,1); - ASSERT_EQ(listConnections[0].connectionFormat,CF_GENIVI_ANALOG); -} - -TEST_F(CAmControlInterfaceTest,ackConnectNotPossible) -{ - 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 = DYNAMIC_ID_BOUNDARY; - - //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_COMMUNICATION)); - ASSERT_EQ(E_COMMUNICATION, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); - - //The list of handles shall be empty - ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); - ASSERT_TRUE(handlesList.empty()); - - - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_TRUE(connectionList.empty()); - -} - -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 deleted file mode 100644 index b7fa27a..0000000 --- a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef ROUTINGINTERFACETEST_H_ -#define ROUTINGINTERFACETEST_H_ - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -//#include "CAmDatabaseHandlerSQLite.h" -#include "CAmDatabaseHandlerMap.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 "CAmSocketHandler.h" - -namespace am -{ - -class CAmControlInterfaceTest: public ::testing::Test -{ -public: - CAmControlInterfaceTest(); - ~CAmControlInterfaceTest(); - CAmSocketHandler pSocketHandler; - std::vector plistCommandPluginDirs; - std::vector plistRoutingPluginDirs; - CAmDatabaseHandlerMap 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 deleted file mode 100644 index b21ca91..0000000 --- a/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project(AmControlInterfaceTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -if(WITH_DATABASE_STORAGE) - pkg_check_modules(SQLITE REQUIRED sqlite3) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${SQLITE_LIBRARIES}) -endif(WITH_DATABASE_STORAGE) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${STD_INCLUDE_DIRS} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR}) - -if(WITH_DLT) - INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) -endif(WITH_DLT) - - -file(GLOB CONTROL_INTERFACE_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "../CAmCommonFunctions.cpp" - "*.cpp" -) - -add_executable(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmControlInterfaceTest - ${AM_LINK_LIBS} - gtest - gmock) - -ADD_DEPENDENCIES(AmControlInterfaceTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmControlInterfaceTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests) - - - - diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp deleted file mode 100644 index ac7bd03..0000000 --- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp +++ /dev/null @@ -1,2585 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmDatabaseHandlerTest.h" -#include -#include -#include -#include -#include "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 equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_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) && // - std::equal(secondDynamicSink.listNotificationConfigurations.begin(), secondDynamicSink.listNotificationConfigurations.end(), sinkData.listNotificationConfigurations.begin(), equalNotificationConfiguration) && // - std::equal(secondDynamicSink.listMainNotificationConfigurations.begin(), secondDynamicSink.listMainNotificationConfigurations.end(), sinkData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration) // - ); - -} - -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); - } - - }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) && // - std::equal(secondDynamicSource.listMainNotificationConfigurations.begin(), secondDynamicSource.listMainNotificationConfigurations.end(), sourceData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration) && // - std::equal(secondDynamicSource.listNotificationConfigurations.begin(), secondDynamicSource.listNotificationConfigurations.end(), sourceData.listNotificationConfigurations.begin(), equalNotificationConfiguration) // - ); - -} - -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(DYNAMIC_ID_BOUNDARY, 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(DYNAMIC_ID_BOUNDARY, 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 listSourceTypes; - 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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.empty()); - ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); - - //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_FALSE(listSources.empty()); - ASSERT_TRUE(listSources.at(0).sourceID==sourceID); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_FALSE(listSourceTypes.empty()); - ASSERT_TRUE(listSourceTypes.at(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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.size()==1); - ASSERT_TRUE(listSourceTypes.at(0).sourceID==source3ID); - ASSERT_EQ(source3ID, source2ID); -} - - -TEST_F(CAmDatabaseHandlerTest, peekSourceDouble) -{ - std::vector listSourceTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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.size()==1); - ASSERT_TRUE(listSources[0].sourceID==sourceID); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.size()==1); - ASSERT_TRUE(listSourceTypes[0].sourceID==source3ID); -} - -TEST_F(CAmDatabaseHandlerTest, peekSink) -{ - std::vector listSinkTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_FALSE(listSinkTypes.empty()); - ASSERT_TRUE(listSinkTypes.at(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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_TRUE(listSinkTypes.size()==1); - ASSERT_TRUE(listSinkTypes.at(0).sinkID==sink3ID); -} - -TEST_F(CAmDatabaseHandlerTest, peekSinkDouble) -{ - std::vector listSinkTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_TRUE(listSinkTypes.size()==1); - ASSERT_TRUE(listSinkTypes[0].sinkID==sink3ID); -} - -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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - 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); - } - } - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB({property.type, 34},sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, 34); -} - -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); - } - } - - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB({property.type, 34},sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, 34); -} - -TEST_F(CAmDatabaseHandlerTest, changeSourceSoundProperty) -{ - std::vector listSources; - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - am_SoundProperty_s property; - property.type = SP_GENIVI_MID; - property.value = 33; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB(property,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - - std::vector::iterator listIterator = listSources[0].listSoundProperties.begin(); - for (; listIterator < listSources[0].listSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - ASSERT_EQ(listIterator->value, property.value); - } - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB({property.type, 34},sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, 34); -} - -TEST_F(CAmDatabaseHandlerTest, changeSinkSoundProperty) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_SoundProperty_s property; - property.type = SP_GENIVI_MID; - property.value = 33; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB(property,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - std::vector::iterator listIterator = listSinks[0].listSoundProperties.begin(); - for (; listIterator < listSinks[0].listSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - ASSERT_EQ(listIterator->value, property.value); - } - - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB({property.type, 34},sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, 34); -} - -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,getListConvertersOfDomain) -{ - am_Converter_s gateway, gateway2; - am_converterID_t gatewayID; - am_domainID_t domainID; - am_Domain_s domain; - std::vector gatewayList, gatewayCheckList; - pCF.createConverter(gateway); - gateway.converterID = 1; - gateway.name = "testGateway"; - gateway.sourceID = 1; - gateway.sinkID = 1; - gateway.domainID = 1; - pCF.createConverter(gateway2); - gateway2.converterID = 2; - gateway2.name = "testGateway2"; - gateway2.sourceID = 1; - gateway2.sinkID = 1; - gateway2.domainID = 1; - pCF.createDomain(domain); - gatewayCheckList.push_back(gateway.converterID); - gatewayCheckList.push_back(gateway2.converterID); - 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.enterConverterDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(2,gatewayList)) - << "ERROR: database error";ASSERT_TRUE(gatewayList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(1,gatewayList)) - << "ERROR: database error"; - ASSERT_TRUE(!gatewayList.empty()); - ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin())); -} - -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,removeConverter) -{ - am_Converter_s gateway; - am_converterID_t gatewayID; - std::vector listGateways; - pCF.createConverter(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.enterConverterDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(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,removeNonexistentConverter) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,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,registerConverterCorrect) -{ - //initialize gateway - std::vector returnList; - am_Converter_s gateway, gateway1, gateway2; - am_converterID_t converterID = 0, converterID1 = 0, converterID2 = 0; - - pCF.createConverter(gateway); - pCF.createConverter(gateway1); - gateway1.converterID = 20; - pCF.createConverter(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.enterConverterDB(gateway,converterID)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,converterID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,converterID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.converterID,converterID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,converterID2)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,converterID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); - bool equal = true; - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->converterID == converterID) - { - equal = equal && pCF.compareConverter(listIterator, gateway); - } - - if (listIterator->converterID == converterID1) - { - equal = equal && pCF.compareConverter(listIterator, gateway1); - } - - if (listIterator->converterID == converterID2) - { - equal = equal && pCF.compareConverter(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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,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,getConverterInfo) -{ - //initialize gateway - std::vector returnList; - am_Converter_s gateway, gateway1, gateway2; - am_converterID_t converterID = 0, converterID1 = 0, converterID2 = 0; - - pCF.createConverter(gateway); - pCF.createConverter(gateway1); - gateway1.converterID = 20; - pCF.createConverter(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.enterConverterDB(gateway,converterID)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,converterID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,converterID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.converterID,converterID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,converterID2)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,converterID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); - bool equal = true; - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->converterID == converterID) - { - equal = equal && pCF.compareConverter(listIterator, gateway); - } - - if (listIterator->converterID == converterID1) - { - equal = equal && pCF.compareConverter(listIterator, gateway1); - } - - if (listIterator->converterID == converterID2) - { - equal = equal && pCF.compareConverter(listIterator, gateway2); - } - } - - ASSERT_EQ(true, equal); - - am_Converter_s gatewayInfo; - ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo)); - ASSERT_TRUE(pCF.compareConverter1(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); -} - -TEST_F(CAmDatabaseHandlerTest,enterNotificationConfigurationCorrect) -{ - am_Sink_s testSinkData, readoutData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - testSinkData.listNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].type,notify.type); - - ASSERT_EQ(E_OK,pDatabaseHandler.getSinkInfoDB(testSinkData.sinkID,readoutData)) - << "ERROR: database error"; - - ASSERT_EQ(readoutData.listNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(readoutData.listNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(readoutData.listNotificationConfigurations[2].type,notify.type); - -} - -TEST_F(CAmDatabaseHandlerTest,enterMainNotificationConfigurationCorrect) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); -} - -TEST_F(CAmDatabaseHandlerTest,removeNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); - - //now we remove the sink - ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)); -} - -TEST_F(CAmDatabaseHandlerTest,removeNotificationsSource) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) - << "ERROR: database error"; - - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].type,notify.type); - - //now we remove the sink - ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)); -} - -TEST_F(CAmDatabaseHandlerTest,getMainNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSinkData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) - << "ERROR: database error"; - - std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - -} - -TEST_F(CAmDatabaseHandlerTest,getMainNotificationsSources) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSourceData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) - << "ERROR: database error"; - - std::equal(testSourceData.listMainNotificationConfigurations.begin(),testSourceData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - -} - -TEST_F(CAmDatabaseHandlerTest,changeMainNotificationsSources) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - std::vectorreturnList,returnList1; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - am_NotificationConfiguration_s notify2; - notify2.type=NT_UNKNOWN; - notify2.status=NS_CHANGE; - notify2.parameter=10; - - testSourceData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) - << "ERROR: database error"; - - std::equal(testSourceData.listMainNotificationConfigurations.begin(),testSourceData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - - //change a setting - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2)); - - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList1)) - << "ERROR: database error"; - - ASSERT_EQ(returnList1[3].parameter,notify2.parameter); - ASSERT_EQ(returnList1[3].status,notify2.status); - ASSERT_EQ(returnList1[3].type,notify2.type); - -} - -TEST_F(CAmDatabaseHandlerTest,changeMainNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - std::vectorreturnList,returnList1; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - am_NotificationConfiguration_s notify2; - notify2.type=NT_UNKNOWN; - notify2.status=NS_CHANGE; - notify2.parameter=27; - - testSinkData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) - << "ERROR: database error"; - - std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)) - << "ERROR: database error"; - - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList1)) - << "ERROR: database error"; - - ASSERT_EQ(returnList1[3].parameter,notify2.parameter); - ASSERT_EQ(returnList1[3].status,notify2.status); - ASSERT_EQ(returnList1[3].type,notify2.type); -} - -TEST_F(CAmDatabaseHandlerTest, peekDomain_2) -{ - 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 = "anotherdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domain2ID, 2); - - domain.name = "newdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 - ASSERT_TRUE(listDomains[0].domainID==domainID); -} - -//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 deleted file mode 100644 index 309f58c..0000000 --- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASETEST_H_ -#define DATABASETEST_H_ - -#define UNIT_TEST 1 - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "CAmDatabaseHandlerSQLite.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 "CAmSocketHandler.h" - -namespace am -{ - -class CAmDatabaseHandlerTest: public ::testing::Test -{ -public: - CAmDatabaseHandlerTest(); - ~CAmDatabaseHandlerTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - CAmSocketHandler pSocketHandler; - CAmDatabaseHandlerSQLite 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 deleted file mode 100644 index 88b1d81..0000000 --- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project(AmDatabaseHandlerTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -#only build this test if sqlite is requested -if(WITH_DATABASE_STORAGE) - - set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - - pkg_check_modules(SQLITE REQUIRED sqlite3) - - if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) - endif(WITH_DLT) - - INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} - ) - - if(WITH_DLT) - INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) - endif(WITH_DLT) - - file(GLOB DATABASE_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerSQLite.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "../CAmCommonFunctions.cpp" - "*.cpp" - ) - - - ADD_EXECUTABLE( AmDatabaseHandlerTest ${DATABASE_SRCS_CXX}) - - TARGET_LINK_LIBRARIES( AmDatabaseHandlerTest - ${AM_LINK_LIBS} - ${SQLITE_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - ${CMAKE_DL_LIBS} - gtest - gmock - ) - - ADD_DEPENDENCIES(AmDatabaseHandlerTest gtest gmock AudioManagerUtilities) - - INSTALL(TARGETS AmDatabaseHandlerTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests - ) - -endif(WITH_DATABASE_STORAGE) - diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp deleted file mode 100644 index 0f90704..0000000 --- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp +++ /dev/null @@ -1,3265 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmMapHandlerTest.h" -#include -#include -#include -#include -#include -#include "CAmDltWrapper.h" - -using namespace am; -using namespace testing; - - -extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b); -extern bool equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b); -extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b); -extern std::string int2string(int i); - -int16_t const TEST_MAX_CONNECTION_ID = 20; -int16_t const TEST_MAX_MAINCONNECTION_ID = 20; -int16_t const TEST_MAX_SINK_ID = 40; - - -CAmMapBasicTest::CAmMapBasicTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(),// - pDatabaseHandler(), // - pRoutingSender(plistRoutingPluginDirs), // - pCommandSender(plistCommandPluginDirs), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlSender(), // - pRouter(&pDatabaseHandler, &pControlSender), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pCF() -{ -} - -CAmMapBasicTest::~CAmMapBasicTest() -{ -} - -void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection) -{ - //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 - 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)); - std::vector::iterator listIterator = mainConnectionList.begin(); - for (; listIterator < mainConnectionList.end(); ++listIterator) - { - if (listIterator->mainConnectionID == mainConnectionID) - { - ASSERT_EQ(listIterator->connectionState, mainConnection.connectionState); - ASSERT_EQ(listIterator->sinkID, mainConnection.sinkID); - ASSERT_EQ(listIterator->sourceID, mainConnection.sourceID); - ASSERT_EQ(listIterator->delay, mainConnection.delay); - ASSERT_TRUE(std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); - } - } -} - -void CAmMapBasicTest::SetUp() -{ - ::testing::FLAGS_gmock_verbose = "error"; -} - -void CAmMapBasicTest::TearDown() -{ - ::testing::FLAGS_gmock_verbose = "warning"; -} - - - -CAmMapHandlerTest::CAmMapHandlerTest() : - pMockInterface(), // - pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&pObserver); - pDatabaseHandler.setConnectionIDRange(1, TEST_MAX_CONNECTION_ID); - pDatabaseHandler.setMainConnectionIDRange(1, TEST_MAX_MAINCONNECTION_ID); - pDatabaseHandler.setSinkIDRange(DYNAMIC_ID_BOUNDARY, DYNAMIC_ID_BOUNDARY+TEST_MAX_SINK_ID); - pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); -} - -CAmMapHandlerTest::~CAmMapHandlerTest() -{ -} - -TEST_F(CAmMapHandlerTest,getMainConnectionInfo) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection, mainConnectionT; - createMainConnectionSetup(mainConnectionID, mainConnection); - - ASSERT_EQ(E_OK, pDatabaseHandler.getMainConnectionInfoDB(mainConnectionID,mainConnectionT)); - ASSERT_TRUE(mainConnection.connectionState == mainConnectionT.connectionState); - ASSERT_TRUE(mainConnection.delay == mainConnectionT.delay); - ASSERT_TRUE(std::equal(mainConnection.listConnectionID.begin(),mainConnection.listConnectionID.end(),mainConnectionT.listConnectionID.begin())); - ASSERT_TRUE(mainConnection.sinkID == mainConnectionT.sinkID); - ASSERT_TRUE(mainConnection.sourceID == mainConnectionT.sourceID); - ASSERT_TRUE(mainConnectionID == mainConnectionT.mainConnectionID); -} - -TEST_F(CAmMapHandlerTest,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"; - - std::vector::iterator listIterator = sinkList.begin(); - for (; listIterator < sinkList.end(); ++listIterator) - { - if (listIterator->sinkID == staticSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); - } - - if (listIterator->sinkID == firstDynamicSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); - } - - if (listIterator->sinkID == secondDynamicSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); - } - } - - am_Sink_s sinkData; - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkInfoDB(secondDynamicSinkID,sinkData)); - ASSERT_EQ(secondDynamicSink.available.availability, sinkData.available.availability); - ASSERT_EQ(secondDynamicSink.available.availabilityReason, sinkData.available.availabilityReason); - ASSERT_EQ(secondDynamicSink.sinkClassID, sinkData.sinkClassID); - ASSERT_EQ(secondDynamicSink.domainID, sinkData.domainID); - ASSERT_EQ(secondDynamicSink.visible, sinkData.visible); - ASSERT_EQ(0, secondDynamicSink.name.compare(sinkData.name)); - ASSERT_EQ(secondDynamicSink.volume, sinkData.volume); - ASSERT_TRUE(std::equal(secondDynamicSink.listConnectionFormats.begin(), secondDynamicSink.listConnectionFormats.end(), sinkData.listConnectionFormats.begin())); - ASSERT_TRUE(std::equal(secondDynamicSink.listMainSoundProperties.begin(), secondDynamicSink.listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty)); - ASSERT_TRUE(std::equal(secondDynamicSink.listNotificationConfigurations.begin(), secondDynamicSink.listNotificationConfigurations.end(), sinkData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); - ASSERT_TRUE(std::equal(secondDynamicSink.listMainNotificationConfigurations.begin(), secondDynamicSink.listMainNotificationConfigurations.end(), sinkData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); -} - -TEST_F(CAmMapHandlerTest,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"; - - std::vector::iterator listIterator = sourceList.begin(); - for (; listIterator < sourceList.end(); ++listIterator) - { - if (listIterator->sourceID == staticSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); - } - - if (listIterator->sourceID == firstDynamicSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); - } - - if (listIterator->sourceID == secondDynamicSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); - } - } - - am_Source_s sourceData; - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceInfoDB(secondDynamicSourceID,sourceData)); - ASSERT_EQ(secondDynamicSource.available.availability, sourceData.available.availability); - ASSERT_EQ(secondDynamicSource.available.availabilityReason, sourceData.available.availabilityReason); - ASSERT_EQ(secondDynamicSource.sourceClassID, sourceData.sourceClassID); - ASSERT_EQ(secondDynamicSource.domainID, sourceData.domainID); - ASSERT_EQ(secondDynamicSource.interruptState, sourceData.interruptState); - ASSERT_EQ(secondDynamicSource.visible, sourceData.visible); - ASSERT_EQ(0, secondDynamicSource.name.compare(sourceData.name)); - ASSERT_EQ(secondDynamicSource.volume, sourceData.volume); - ASSERT_TRUE(std::equal(secondDynamicSource.listConnectionFormats.begin(), secondDynamicSource.listConnectionFormats.end(), sourceData.listConnectionFormats.begin())); - ASSERT_TRUE(std::equal(secondDynamicSource.listMainSoundProperties.begin(), secondDynamicSource.listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty)); - ASSERT_TRUE(std::equal(secondDynamicSource.listMainNotificationConfigurations.begin(), secondDynamicSource.listMainNotificationConfigurations.end(), sourceData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); - ASSERT_TRUE(std::equal(secondDynamicSource.listNotificationConfigurations.begin(), secondDynamicSource.listNotificationConfigurations.end(), sourceData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); -} - -TEST_F(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY, listCrossfaders[0].crossfaderID); - ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0); -} - -TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY, listCrossfaders[0]); - -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest, peekSource) -{ - std::vector listSourceTypes; - 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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.empty()); - ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); - - //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_FALSE(listSources.empty()); - ASSERT_TRUE(listSources.at(0).sourceID==sourceID); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_FALSE(listSourceTypes.empty()); - ASSERT_TRUE(listSourceTypes.at(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(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.size()==1); - ASSERT_TRUE(listSourceTypes.at(0).sourceID==source3ID); - ASSERT_EQ(source3ID, source2ID); -} - -TEST_F(CAmMapHandlerTest, peekSourceDouble) -{ - std::vector listSourceTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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.size()==1); - ASSERT_TRUE(listSources[0].sourceID==sourceID); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); - ASSERT_TRUE(listSourceTypes.size()==1); - ASSERT_TRUE(listSourceTypes[0].sourceID==source3ID); -} - -TEST_F(CAmMapHandlerTest, peekSink) -{ - std::vector listSinkTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_FALSE(listSinkTypes.empty()); - ASSERT_TRUE(listSinkTypes.at(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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_TRUE(listSinkTypes.size()==1); - ASSERT_TRUE(listSinkTypes.at(0).sinkID==sink3ID); -} - -TEST_F(CAmMapHandlerTest, peekSinkDouble) -{ - std::vector listSinkTypes; - 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, DYNAMIC_ID_BOUNDARY); - 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); - - ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); - ASSERT_TRUE(listSinkTypes.size()==1); - ASSERT_TRUE(listSinkTypes[0].sinkID==sink3ID); -} - -TEST_F(CAmMapHandlerTest,changeConnectionTimingInformationCheckMainConnection) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - std::vector connectionList; - std::vector mainList; - - //prepare the test, it is one mainconnection, so we expect one callback - createMainConnectionSetup(mainConnectionID, mainConnection); - - //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->connectionID,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); -} - -TEST_F(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); - ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); - 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(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); - 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, DYNAMIC_ID_BOUNDARY); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); -} - -TEST_F(CAmMapHandlerTest,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, DYNAMIC_ID_BOUNDARY); - ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,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"; - - std::vector::iterator listIterator = sourceList.begin(); - for (; listIterator < sourceList.end(); ++listIterator) - { - if (listIterator->sourceID == staticSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); - } - - if (listIterator->sourceID == firstDynamicSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); - } - - if (listIterator->sourceID == secondDynamicSourceID) - { - ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); - } - - } -} - -TEST_F(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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); - } - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB({property.type, 34},sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, 34); - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, 1000, value)); -} - -TEST_F(CAmMapHandlerTest, 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); - } - - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB({property.type, 34},sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, 34); - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, 1000, value)); -} - -TEST_F(CAmMapHandlerTest, changeSourceSoundProperty) -{ - std::vector listSources; - am_Source_s source; - am_sourceID_t sourceID; - pCF.createSource(source); - am_SoundProperty_s property; - property.type = SP_GENIVI_MID; - property.value = 33; - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB(property,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - - std::vector::iterator listIterator = listSources[0].listSoundProperties.begin(); - for (; listIterator < listSources[0].listSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - ASSERT_EQ(listIterator->value, property.value); - } - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB({property.type, 34},sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); - ASSERT_EQ(value, 34); - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, 1000, value)); -} - -TEST_F(CAmMapHandlerTest, changeSinkSoundProperty) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_SoundProperty_s property; - property.type = SP_GENIVI_MID; - property.value = 33; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB(property,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - std::vector::iterator listIterator = listSinks[0].listSoundProperties.begin(); - for (; listIterator < listSinks[0].listSoundProperties.end(); ++listIterator) - { - if (listIterator->type == property.type) - ASSERT_EQ(listIterator->value, property.value); - } - - int16_t value; - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, property.value); - - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB({property.type, 34},sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); - ASSERT_EQ(value, 34); - ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, 1000, value)); -} - -TEST_F(CAmMapHandlerTest, 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, DYNAMIC_ID_BOUNDARY); - 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, changeMainConnectionState) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - std::vector listMainConnections; - createMainConnectionSetup(mainConnectionID, mainConnection); - - 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(CAmMapHandlerTest, 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(CAmMapHandlerTest, 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(CAmMapHandlerTest,changeMainConnectionRoute) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - std::vector originalList; - std::vector newList; - createMainConnectionSetup(mainConnectionID, mainConnection); - - //fill the connection database - am_Connection_s connection; - am_Source_s source; - am_Sink_s sink; - std::vector listConnectionID; - - uint16_t i = 1; - for (; 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(mainConnectionID,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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"; - 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) - { - ASSERT_TRUE(pCF.compareSinkMainSink(listIterator, listSinks)); - } -} - -TEST_F(CAmMapHandlerTest,getVisibleMainConnections) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - createMainConnectionSetup(mainConnectionID, mainConnection); - - 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(CAmMapHandlerTest,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 = DYNAMIC_ID_BOUNDARY; - 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(DYNAMIC_ID_BOUNDARY,sourceList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty()); -} - -TEST_F(CAmMapHandlerTest,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 = DYNAMIC_ID_BOUNDARY; - 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(DYNAMIC_ID_BOUNDARY+1,sinkList)) - << "ERROR: database error";ASSERT_TRUE(sinkList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(DYNAMIC_ID_BOUNDARY,sinkList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty()); -} - -TEST_F(CAmMapHandlerTest,getListGatewaysOfDomain) -{ - am_Gateway_s gateway, gateway2; - am_gatewayID_t gatewayID1, gatewayID2; - am_domainID_t domainID; - am_Domain_s domain; - std::vector gatewayList, gatewayCheckList; - - pCF.createDomain(domain); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - - pCF.createGateway(gateway); - gateway.gatewayID = 1; - gateway.name = "testGateway"; - gateway.controlDomainID = domainID; - gateway.sourceID = 1; - gateway.sinkID = 1; - gateway.domainSinkID = 1; - gateway.domainSourceID = 1; - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID1)) - << "ERROR: database error"; - ASSERT_EQ(true, gatewayID1==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; - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) - << "ERROR: database error"; - ASSERT_EQ(true, gatewayID2==2); - gatewayCheckList.push_back(gatewayID1); - - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - sink.sinkID = sinkID; - - pCF.createSource(source); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - source.sourceID = sourceID; - - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList)) - << "ERROR: database error"; - ASSERT_TRUE(gatewayList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(domainID,gatewayList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty()); -} - -TEST_F(CAmMapHandlerTest,getListConvertersOfDomain) -{ - am_Converter_s converter, converter2; - am_converterID_t converterID1, converterID2; - am_domainID_t domainID; - am_Domain_s domain; - std::vector converterList, converterCheckList; - - pCF.createDomain(domain); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); - - pCF.createConverter(converter); - converter.converterID = 1; - converter.name = "testGateway"; - converter.sourceID = 1; - converter.sinkID = 1; - converter.domainID = domainID; - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID1)) - << "ERROR: database error"; - ASSERT_EQ(true, converterID1==1); - - pCF.createConverter(converter2); - converter2.converterID = 2; - converter2.name = "testGateway2"; - converter2.domainID = 4; - converter2.sourceID = 1; - converter2.sinkID = 1; - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter2,converterID2)) - << "ERROR: database error"; - ASSERT_EQ(true, converterID2==2); - converterCheckList.push_back(converterID1); - - am_Sink_s sink; - am_Source_s source; - am_sinkID_t sinkID; - am_sourceID_t sourceID; - pCF.createSink(sink); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - sink.sinkID = sinkID; - - pCF.createSource(source); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - source.sourceID = sourceID; - - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(4,converterList)) - << "ERROR: database error"; - ASSERT_TRUE(converterList.empty()); - ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(domainID,converterList)) - << "ERROR: database error"; - ASSERT_TRUE(std::equal(converterList.begin(),converterList.end(),converterCheckList.begin()) && !converterList.empty()); -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,removeConverter) -{ - am_Converter_s converter; - am_converterID_t converterID; - std::vector listConverters; - pCF.createConverter(converter); - 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.enterConverterDB(converter,converterID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(converterID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(listConverters)) - << "ERROR: database error"; - ASSERT_TRUE(listConverters.empty()); -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest, removeMainConnection) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - createMainConnectionSetup(mainConnectionID, mainConnection); - - ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,removeNonexistentMainConnectionFail) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,removeNonexistentSource) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,removeNonexistentSink) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,removeNonexistentGateway) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,removeNonexistentConverter) -{ - ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(12)) - << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->gatewayID == gatewayID) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); - } - - if (listIterator->gatewayID == gatewayID1) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); - } - - if (listIterator->gatewayID == gatewayID2) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); - } - } -} - -TEST_F(CAmMapHandlerTest,registerConverterCorrect) -{ - //initialize gateway - std::vector returnList; - am_Converter_s gateway, gateway1, gateway2; - am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; - - pCF.createConverter(gateway); - pCF.createConverter(gateway1); - gateway1.converterID = 20; - pCF.createConverter(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.enterConverterDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.converterID,gatewayID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->converterID == gatewayID) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); - } - - if (listIterator->converterID == gatewayID1) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); - } - - if (listIterator->converterID == gatewayID2) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); - } - } -} - -TEST_F(CAmMapHandlerTest,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(DYNAMIC_ID_BOUNDARY,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(DYNAMIC_ID_BOUNDARY+1,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->gatewayID == gatewayID) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); - } - - if (listIterator->gatewayID == gatewayID1) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); - } - - if (listIterator->gatewayID == gatewayID2) - { - ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); - } - } - - am_Gateway_s gatewayInfo; - ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo)); - ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo)); - -} - -TEST_F(CAmMapHandlerTest,getConverterInfo) -{ - //initialize gateway - std::vector returnList; - am_Converter_s gateway, gateway1, gateway2; - am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; - - pCF.createConverter(gateway); - pCF.createConverter(gateway1); - gateway1.converterID = 20; - pCF.createConverter(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.enterConverterDB(gateway,gatewayID)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) - << "ERROR: database error"; - ASSERT_EQ(gateway1.converterID,gatewayID1) - << "ERROR: domainID zero"; - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) - << "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) - << "ERROR: domainID zero"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); - std::vector::iterator listIterator = returnList.begin(); - - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->converterID == gatewayID) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); - } - - if (listIterator->converterID == gatewayID1) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); - } - - if (listIterator->converterID == gatewayID2) - { - ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); - } - } - - am_Converter_s gatewayInfo; - ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo)); - ASSERT_TRUE(pCF.compareConverter1(gateway1,gatewayInfo)); - -} - -TEST_F(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,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(CAmMapHandlerTest,registerDomainPredefined) -{ - //initialize domain - std::vector returnList; - am_Domain_s domain; - am_domainID_t domainID = 10; - pCF.createDomain(domain); - - ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) - << "ERROR: database error"; - ASSERT_NE(10,domainID) - << "ERROR: domainID not predefined one"; - - //now check if we read out the correct values - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); - std::vector::iterator listIterator = returnList.begin(); - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->domainID == domainID) - { - ASSERT_EQ(0, listIterator->name.compare(domain.name)); - ASSERT_EQ(0, listIterator->busname.compare(domain.busname)); - ASSERT_EQ(domain.complete, listIterator->complete); - ASSERT_EQ(domain.early, listIterator->early); - ASSERT_EQ(domain.state, listIterator->state); - } - } -} - -TEST_F(CAmMapHandlerTest,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)); - std::vector::iterator listIterator = returnList.begin(); - for (; listIterator < returnList.end(); ++listIterator) - { - if (listIterator->connectionID == connectionID) - { - ASSERT_EQ(connection.sourceID, listIterator->sourceID); - ASSERT_EQ(connection.sinkID, listIterator->sinkID); - ASSERT_EQ(connection.delay, listIterator->delay); - ASSERT_EQ(connection.connectionFormat, listIterator->connectionFormat); - } - } -} - -TEST_F(CAmMapHandlerTest,enterMainConnectionCorrect) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - createMainConnectionSetup(mainConnectionID, mainConnection); -} - -TEST_F(CAmMapHandlerTest,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"; - - std::vector::iterator listIterator = sinkList.begin(); - for (; listIterator < sinkList.end(); ++listIterator) - { - if (listIterator->sinkID == staticSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); - } - - if (listIterator->sinkID == firstDynamicSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); - } - - if (listIterator->sinkID == secondDynamicSinkID) - { - ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); - } - } -} - -TEST_F(CAmMapHandlerTest,enterNotificationConfigurationCorrect) -{ - am_Sink_s testSinkData, readoutData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - testSinkData.listNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].type,notify.type); - - ASSERT_EQ(E_OK,pDatabaseHandler.getSinkInfoDB(testSinkData.sinkID,readoutData)) - << "ERROR: database error"; - - ASSERT_EQ(readoutData.listNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(readoutData.listNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(readoutData.listNotificationConfigurations[2].type,notify.type); - -} - -TEST_F(CAmMapHandlerTest,enterMainNotificationConfigurationCorrect) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); -} - -TEST_F(CAmMapHandlerTest,removeNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) - << "ERROR: database error"; - - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); - - //now we remove the sink - ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)); -} - -TEST_F(CAmMapHandlerTest,removeNotificationsSource) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) - << "ERROR: database error"; - - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].status,notify.status); - ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].type,notify.type); - - //now we remove the sink - ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)); -} - -TEST_F(CAmMapHandlerTest,getMainNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSinkData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) - << "ERROR: database error"; - - std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - -} - -TEST_F(CAmMapHandlerTest,getMainNotificationsSources) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_UNKNOWN; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSourceData.listMainNotificationConfigurations.push_back(notify1); - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) - << "ERROR: database error"; - - std::equal(testSourceData.listMainNotificationConfigurations.begin(),testSourceData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - -} - -TEST_F(CAmMapHandlerTest,changeMainNotificationsSources) -{ - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - std::vectorreturnList,returnList1; - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) - << "ERROR: database error"; - - ASSERT_EQ(true, std::equal(testSourceData.listMainNotificationConfigurations.begin(), - testSourceData.listMainNotificationConfigurations.end(), - returnList.begin(), - equalNotificationConfiguration)); - - //change notification which is not available - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=10; - ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); - //change a setting - notify.type=NT_TEST_2; - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); - - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList1)) - << "ERROR: database error"; - - ASSERT_EQ(returnList1[1].parameter,notify.parameter); - ASSERT_EQ(returnList1[1].status,notify.status); - ASSERT_EQ(returnList1[1].type,notify.type); - -} - -TEST_F(CAmMapHandlerTest,changeMainNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - std::vectorreturnList,returnList1; - - //enter the sink in the database - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - - //read it again - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) - << "ERROR: database error"; - - std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); - - //change notification which is not available - am_NotificationConfiguration_s notify; - notify.type=NT_UNKNOWN; - notify.status=NS_CHANGE; - notify.parameter=27; - ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) - << "ERROR: database error"; - //change a setting - notify.type=NT_TEST_2; - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) - << "ERROR: database error"; - - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList1)) - << "ERROR: database error"; - - ASSERT_EQ(returnList1[1].parameter,notify.parameter); - ASSERT_EQ(returnList1[1].status,notify.status); - ASSERT_EQ(returnList1[1].type,notify.type); -} - -TEST_F(CAmMapHandlerTest, peekDomain_2) -{ - 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, DYNAMIC_ID_BOUNDARY); - - domain.name = "anotherdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); - - domain.name = "newdomain"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 - bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { - return ref.domainID==domainID; - })!=listDomains.end(); - ASSERT_TRUE(containsDomainID); -} - -TEST_F(CAmMapHandlerTest, connectionIDBoundary) -{ - am_Sink_s sink; - am_Source_s source; - am_Connection_s connection; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; - connection.connectionID = 0; - am_sinkID_t forgetSink; - am_sourceID_t forgetSource; - am_connectionID_t connectionID; - for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) - { - pCF.createSink(sink); - sink.sinkID = 0; - sink.name = "sink" + int2string(i); - sink.domainID = 4; - pCF.createSource(source); - source.sourceID = 0; - source.name = "source" + int2string(i); - source.domainID = 4; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); - connection.sinkID = forgetSink; - connection.sourceID = forgetSource; - if( i < TEST_MAX_CONNECTION_ID ) - { - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - ASSERT_EQ(i, connectionID); - } - } - std::vector connectionList; - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast(connectionList.size())); - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - logInfo("here"); - ASSERT_EQ(0, connectionID); - - ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(10)); - ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(12)); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(10, connectionID); - connection.sinkID = 77; - connection.sourceID = 77; - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(12, connectionID); - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(0, connectionID); -} - -TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) -{ - am_Sink_s sink; - am_Source_s source; - am_Connection_s connection; - connection.delay = -1; - connection.connectionFormat = CF_GENIVI_ANALOG; - connection.connectionID = 0; - am_sinkID_t forgetSink; - am_sourceID_t forgetSource; - am_connectionID_t connectionID; - std::vector connectionIDList; - for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) - { - pCF.createSink(sink); - sink.sinkID = 0; - sink.name = "sink" + int2string(i); - sink.domainID = 4; - pCF.createSource(source); - source.sourceID = 0; - source.name = "source" + int2string(i); - source.domainID = 4; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); - connection.sinkID = forgetSink; - connection.sourceID = forgetSource; - if( i < TEST_MAX_CONNECTION_ID ) - { - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - ASSERT_EQ(i, connectionID); - connectionIDList.push_back(i); - } - } - std::vector connectionList; - ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); - ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast(connectionList.size())); - - //create a mainConnection - - am_MainConnection_s mainConnection; - am_mainConnectionID_t mainConnectionID; - mainConnection.listConnectionID = connectionIDList; - mainConnection.mainConnectionID = 0; - mainConnection.connectionState = CS_CONNECTED; - mainConnection.delay = -1; - - for (uint16_t i = 1; i < TEST_MAX_MAINCONNECTION_ID; i++) - { - mainConnection.sinkID = DYNAMIC_ID_BOUNDARY + i; - mainConnection.sourceID = DYNAMIC_ID_BOUNDARY + i; - ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_EQ(i, mainConnectionID); - } - ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(10)); - ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(12)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_EQ(10, mainConnectionID); - mainConnection.sinkID = 77; - mainConnection.sourceID = 77; - ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_EQ(12, mainConnectionID); - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); - ASSERT_EQ(0, mainConnectionID); -} - -TEST_F(CAmMapHandlerTest, increaseID) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - for (uint16_t i = 0; i < TEST_MAX_SINK_ID; i++) - { - pCF.createSink(sink); - sink.sinkID = 0; - sink.name = "sink" + int2string(i); - sink.domainID = 4; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+i, sinkID); - } - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); - - ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+10)); - ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+12)); - - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); - ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); -} - - -CAmMapHandlerObserverCallbacksTest::CAmMapHandlerObserverCallbacksTest() : - mMockObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&mMockObserver); -} - -CAmMapHandlerObserverCallbacksTest::~CAmMapHandlerObserverCallbacksTest() -{ -} - -MATCHER_P(IsDomainDataEqualTo, value, "") { - auto lh = arg; - return lh.domainID == value.domainID && - lh.name == value.name && - lh.nodename == value.nodename && - lh.early == value.early && - lh.complete == value.complete && - lh.state == value.state; -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_removeDomain) -{ - 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, DYNAMIC_ID_BOUNDARY); - - domain.name = "anotherdomain"; - const am_Domain_s expDomain1 = {DYNAMIC_ID_BOUNDARY+1, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain1))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); - EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); - domain.name = "newdomain"; - const am_Domain_s expDomain2 = {DYNAMIC_ID_BOUNDARY, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain2))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); - ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 - bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { - return ref.domainID==domainID; - })!=listDomains.end(); - ASSERT_TRUE(containsDomainID); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeDomain(domainID)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID))<< "ERROR: database error"; - EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSource) -{ - 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, DYNAMIC_ID_BOUNDARY); - - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY+2))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); - ASSERT_EQ(source3ID, DYNAMIC_ID_BOUNDARY+2); - - 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 - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); - ASSERT_EQ(sourceID, source3ID); - bool containsSourceID = std::find_if(listSources.begin(), listSources.end(), [&](const am_Source_s & ref) { - return ref.sourceID==sourceID; - })!=listSources.end(); - ASSERT_TRUE(containsSourceID); - - std::vector listSoundProperties; - std::vector listConnectionFormats; - std::vector listMainSoundProperties; -#ifndef WITH_DATABASE_CHANGE_CHECK - //check no change - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; -#else - //check no change - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(0); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; - //check change of class id - source.sourceClassID++; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, source.sourceClassID, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; - //check change of main sound properties - am_MainSoundProperty_s mainSoundProperties; - mainSoundProperties.type = MSP_GENIVI_TREBLE; - mainSoundProperties.value = 0; - listMainSoundProperties.push_back(mainSoundProperties); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; -#endif - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSource(sourceID, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID))<< "ERROR: database error"; - EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSink) -{ - 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, DYNAMIC_ID_BOUNDARY); - - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY+2))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); - ASSERT_EQ(sink3ID, DYNAMIC_ID_BOUNDARY+2); - - 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 - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(sinkID, sink3ID); - bool containsSourceID = std::find_if(listSinks.begin(), listSinks.end(), [&](const am_Sink_s & ref) { - return ref.sinkID==sinkID; - })!=listSinks.end(); - ASSERT_TRUE(containsSourceID); - - std::vector listSoundProperties; - std::vector listConnectionFormats; - std::vector listMainSoundProperties; -#ifndef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; -#else - //check no change - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(0); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; - //check change of class id - sink.sinkClassID++; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, sink.sinkClassID, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; - //check change of main sound properties - am_MainSoundProperty_s mainSoundProperties; - mainSoundProperties.type = MSP_GENIVI_TREBLE; - mainSoundProperties.value = 0; - listMainSoundProperties.push_back(mainSoundProperties); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; -#endif - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(sinkID, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID))<< "ERROR: database error"; - EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) -{ - 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 - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); - 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(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) -{ - 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 - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); - 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(CAmMapHandlerObserverCallbacksTest, enter_removeGateway) -{ - //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; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, 20))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))<< "ERROR: database error"; - ASSERT_EQ(gateway1.gatewayID,gatewayID1)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY+1))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeGateway(gatewayID2)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID2))<< "ERROR: database error"; -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter) -{ - //initialize gateway - std::vector returnList; - am_Converter_s gateway, gateway1, gateway2; - am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; - pCF.createConverter(gateway); - pCF.createConverter(gateway1); - gateway1.converterID = 20; - pCF.createConverter(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; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))<< "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 20))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))<< "ERROR: database error"; - ASSERT_EQ(gateway1.converterID,gatewayID1)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY+1))).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))<< "ERROR: database error"; - ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeConverter(gatewayID2)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID2))<< "ERROR: database error"; -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader) -{ - 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); - - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - 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; - - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newCrossfader(Field(&am_Crossfader_s::crossfaderID, DYNAMIC_ID_BOUNDARY))).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeCrossfader(crossfaderID)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeCrossfaderDB(crossfaderID))<< "ERROR: database error"; -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_update_removeMainConnection) -{ - am_mainConnectionID_t mainConnectionID; - am_MainConnection_s mainConnection; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(9); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(9); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(Field(&am_MainConnectionType_s::mainConnectionID, 1))).Times(1); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, CS_CONNECTED)).Times(1); -#ifndef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(1); -#else - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(0); -#endif - createMainConnectionSetup(mainConnectionID, mainConnection); - - //change delay of first connection - am_timeSync_t delay = 20; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 20)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); -#ifdef WITH_DATABASE_CHANGE_CHECK - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); -#endif - - //change delay of route - delay = 40; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 40)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); -#ifdef WITH_DATABASE_CHANGE_CHECK - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); -#endif - - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(1)).Times(1); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, _)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) << "ERROR: database error"; -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, 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; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); - 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); - -#ifdef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); - availability.availability = A_AVAILABLE; - availability.availabilityReason = AR_GENIVI_TEMPERATURE; - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); -#endif -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, 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; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); - 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); - -#ifdef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); - availability.availability = A_AVAILABLE; - availability.availabilityReason = AR_GENIVI_TEMPERATURE; - ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); -#endif -} - -TEST_F(CAmMapHandlerObserverCallbacksTest,changeMainSinkVolume) -{ - am_Sink_s sink; - am_sinkID_t sinkID; - am_mainVolume_t newVol = 20; - std::vector listSinks; - pCF.createSink(sink); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged(sinkID, newVol)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(listSinks[0].mainVolume, newVol); - -#ifdef WITH_DATABASE_CHANGE_CHECK - am_mainVolume_t incVol = 21; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged( sinkID, incVol)).Times(1); - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(incVol,sinkID)); -#endif -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkMuteState) -{ - std::vector listSinks; - am_Sink_s sink; - am_sinkID_t sinkID; - pCF.createSink(sink); - am_MuteState_e muteState = MS_MUTED; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, muteState)).Times(1); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); - ASSERT_EQ(muteState, listSinks[0].muteState); - -#ifdef WITH_DATABASE_CHANGE_CHECK - am_MuteState_e newMuteState = MS_UNMUTED; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, newMuteState)).Times(1); - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(newMuteState,sinkID)); -#endif -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, 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; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); - 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); - -#ifdef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); - ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); - systemProperty.value = 33; - ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); -#endif -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSink) -{ - am_Sink_s testSinkData; - pCF.createSink(testSinkData); - testSinkData.sinkID = 4; - am_sinkID_t sinkID; - std::vector listSinks; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_TEST_1; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSinkData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_TEST_1; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSinkData.listMainNotificationConfigurations.push_back(notify1); - - am_NotificationConfiguration_s notify2; - notify2.type=NT_TEST_2; - notify2.status=NS_CHANGE; - notify2.parameter=27; - - testSinkData.listMainNotificationConfigurations.push_back(notify2); - - //enter the sink in the database - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID, returnList)) - << "ERROR: database error"; - ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; - - //change a setting - notify2.parameter++; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMainNotificationConfigurationChanged(sinkID, _)).Times(1); -#ifdef WITH_DATABASE_CHANGE_CHECK - ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify1)); -#endif - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)); -} - -TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSources) -{ - - am_Source_s testSourceData; - pCF.createSource(testSourceData); - testSourceData.sourceID = 4; - am_sourceID_t sourceID; - std::vector listSources; - std::vectorreturnList; - - am_NotificationConfiguration_s notify; - notify.type=NT_TEST_1; - notify.status=NS_CHANGE; - notify.parameter=25; - - testSourceData.listMainNotificationConfigurations.push_back(notify); - - am_NotificationConfiguration_s notify1; - notify1.type=NT_TEST_1; - notify1.status=NS_PERIODIC; - notify1.parameter=5; - - testSourceData.listMainNotificationConfigurations.push_back(notify1); - - am_NotificationConfiguration_s notify2; - notify2.type=NT_TEST_2; - notify2.status=NS_CHANGE; - notify2.parameter=10; - - testSourceData.listMainNotificationConfigurations.push_back(notify2); - - //enter the sink in the database - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) - << "ERROR: database error"; - ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) - << "ERROR: database error"; - ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; - - //change a setting - notify2.parameter++; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceMainNotificationConfigurationChanged(sourceID, _)).Times(1); -#ifdef WITH_DATABASE_CHANGE_CHECK - ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify1)); -#endif - ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2)); -} - -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/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h deleted file mode 100644 index e3cc0ef..0000000 --- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MAPHANDLERTEST_H_ -#define MAPHANDLERTEST_H_ - -#define UNIT_TEST 1 - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "CAmSocketHandler.h" -#include "CAmDatabaseHandlerMap.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 "MockDatabaseObserver.h" - -namespace am -{ - -class CAmMapBasicTest : public ::testing::Test -{ -public: - CAmMapBasicTest(); - ~CAmMapBasicTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - CAmRoutingSender pRoutingSender; - CAmCommandSender pCommandSender; - IAmRoutingBackdoor pRoutingInterfaceBackdoor; - IAmCommandBackdoor pCommandInterfaceBackdoor; - CAmSocketHandler pSocketHandler; - CAmDatabaseHandlerMap pDatabaseHandler; - CAmControlSender pControlSender; - CAmRouter pRouter; - CAmControlReceiver pControlReceiver; - CAmCommonFunctions pCF; - void SetUp(); - void TearDown(); - void createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection); -}; - -class CAmMapHandlerTest: public CAmMapBasicTest -{ -public: - CAmMapHandlerTest(); - ~CAmMapHandlerTest(); - MockIAmCommandSend pMockInterface; - CAmDatabaseObserver pObserver; -}; - -class CAmMapHandlerObserverCallbacksTest : public CAmMapBasicTest -{ -public: - CAmMapHandlerObserverCallbacksTest(); - ~CAmMapHandlerObserverCallbacksTest(); - CAmDatabaseObserver mMockObserver; -}; - - -} - -#endif /* MAPHANDLERTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp deleted file mode 100644 index a035cee..0000000 --- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file CAmTestDatabaseObserver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmDatabaseObserver.h" -#include "MockDatabaseObserver.h" - -namespace am { - -CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : -mCommandSender(iCommandSender), // -mRoutingSender(iRoutingSender), // -mTelnetServer(NULL), // -mSerializer(iSocketHandler) // -{} - -CAmDatabaseObserver::~CAmDatabaseObserver() {} - - -void CAmDatabaseObserver::numberOfSinkClassesChanged() -{ MockDatabaseObserver::getMockObserverObject()->numberOfSinkClassesChanged(); } -void CAmDatabaseObserver::numberOfSourceClassesChanged() -{ MockDatabaseObserver::getMockObserverObject()->numberOfSourceClassesChanged(); } -void CAmDatabaseObserver::newSink(const am_Sink_s& sink) -{ MockDatabaseObserver::getMockObserverObject()->newSink(sink); } -void CAmDatabaseObserver::newSource(const am_Source_s& source) -{ MockDatabaseObserver::getMockObserverObject()->newSource(source); } -void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) -{ MockDatabaseObserver::getMockObserverObject()->newDomain(domain); } -void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) -{ MockDatabaseObserver::getMockObserverObject()->newGateway(gateway); } -void CAmDatabaseObserver::newConverter(const am_Converter_s& coverter) -{ MockDatabaseObserver::getMockObserverObject()->newConverter(coverter); } -void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) -{ MockDatabaseObserver::getMockObserverObject()->newCrossfader(crossfader); } -void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) -{ MockDatabaseObserver::getMockObserverObject()->newMainConnection(mainConnection); } -void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) -{ MockDatabaseObserver::getMockObserverObject()->removedMainConnection(mainConnection); } -void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->removedSink(sinkID, visible); } -void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->removedSource(sourceID, visible); } -void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) -{ MockDatabaseObserver::getMockObserverObject()->removeDomain(domainID); } -void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) -{ MockDatabaseObserver::getMockObserverObject()->removeGateway(gatewayID); } -void CAmDatabaseObserver::removeConverter(const am_converterID_t converterID) -{ MockDatabaseObserver::getMockObserverObject()->removeConverter(converterID); } -void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) -{ MockDatabaseObserver::getMockObserverObject()->removeCrossfader(crossfaderID); } -void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ MockDatabaseObserver::getMockObserverObject()->mainConnectionStateChanged(connectionID, connectionState); } -void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) -{ MockDatabaseObserver::getMockObserverObject()->mainSinkSoundPropertyChanged(sinkID, SoundProperty); } -void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) -{ MockDatabaseObserver::getMockObserverObject()->mainSourceSoundPropertyChanged(sourceID, SoundProperty); } -void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) -{ MockDatabaseObserver::getMockObserverObject()->sinkAvailabilityChanged(sinkID, availability); } -void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) -{ MockDatabaseObserver::getMockObserverObject()->sourceAvailabilityChanged(sourceID, availability); } -void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ MockDatabaseObserver::getMockObserverObject()->volumeChanged(sinkID, volume); } -void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ MockDatabaseObserver::getMockObserverObject()->sinkMuteStateChanged(sinkID, muteState); } -void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) -{ MockDatabaseObserver::getMockObserverObject()->systemPropertyChanged(SystemProperty); } -void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) -{ MockDatabaseObserver::getMockObserverObject()->timingInformationChanged(mainConnection,time); } -void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->sinkUpdated(sinkID,sinkClassID,listMainSoundProperties, visible); } -void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->sourceUpdated(sourceID,sourceClassID,listMainSoundProperties, visible); } -void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ MockDatabaseObserver::getMockObserverObject()->sinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration); } -void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ MockDatabaseObserver::getMockObserverObject()->sourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration); } -} - diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt deleted file mode 100644 index 760be6c..0000000 --- a/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project(AmMapHandlerTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} -) - -if(WITH_DLT) - INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) -endif(WITH_DLT) - -file(GLOB DATABASE_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "../CAmCommonFunctions.cpp" - "CAmTestDatabaseObserver.cpp" - "*.cpp" - ) - -ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES( AmMapHandlerTest - ${AM_LINK_LIBS} - ${CMAKE_THREAD_LIBS_INIT} - ${CMAKE_DL_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmMapHandlerTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmMapHandlerTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h deleted file mode 100644 index da1b3b4..0000000 --- a/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h +++ /dev/null @@ -1,120 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \file MockDatabaseObserver.h - * For further information see http://www.genivi.org/. - * - */ - - -#ifndef MOCKDATABASEOBSERVER_H_ -#define MOCKDATABASEOBSERVER_H_ - -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include "CAmDatabaseObserver.h" - -class CAmCommandSender; -class CAmRoutingSender; -class CAmSocketHandler; -class CAmTelnetServer; - -namespace am { -using namespace testing; - -class IAmDatabaseObserver -{ -public: - IAmDatabaseObserver() {}; - virtual ~IAmDatabaseObserver() {}; - - virtual void numberOfSinkClassesChanged() = 0; - virtual void numberOfSourceClassesChanged() = 0; - virtual void newSink(const am_Sink_s& sink) = 0; - virtual void newSource(const am_Source_s& source) = 0; - virtual void newDomain(const am_Domain_s& domain) = 0; - virtual void newGateway(const am_Gateway_s& gateway) = 0; - virtual void newConverter(const am_Converter_s& coverter) = 0; - virtual void newCrossfader(const am_Crossfader_s& crossfader) = 0; - virtual void newMainConnection(const am_MainConnectionType_s& mainConnection) = 0; - virtual void removedMainConnection(const am_mainConnectionID_t mainConnection) = 0; - virtual void removedSink(const am_sinkID_t sinkID, const bool visible) = 0; - virtual void removedSource(const am_sourceID_t sourceID, const bool visible) = 0; - virtual void removeDomain(const am_domainID_t domainID) = 0; - virtual void removeGateway(const am_gatewayID_t gatewayID) = 0; - virtual void removeConverter(const am_converterID_t converterID) = 0; - virtual void removeCrossfader(const am_crossfaderID_t crossfaderID) = 0; - virtual void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) = 0; - virtual void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) = 0; - virtual void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) = 0; - virtual void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) = 0; - virtual void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) = 0; - virtual void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) = 0; - virtual void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) = 0; - virtual void systemPropertyChanged(const am_SystemProperty_s& SystemProperty) = 0; - virtual void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) = 0; - virtual void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) = 0; - virtual void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) = 0; - virtual void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; - virtual void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; - -}; - -class MockDatabaseObserver : public IAmDatabaseObserver{ - public: - MOCK_METHOD0(numberOfSinkClassesChanged, void()); - MOCK_METHOD0(numberOfSourceClassesChanged, void()); - MOCK_METHOD1(newSink, void(const am_Sink_s& sink)); - MOCK_METHOD1(newSource, void(const am_Source_s& source)); - MOCK_METHOD1(newDomain, void(const am_Domain_s& domain)); - MOCK_METHOD1(newGateway, void(const am_Gateway_s& gateway)); - MOCK_METHOD1(newConverter, void(const am_Converter_s& converter)); - MOCK_METHOD1(newCrossfader, void(const am_Crossfader_s& crossfader)); - MOCK_METHOD1(newMainConnection, void(const am_MainConnectionType_s & mainConnection)); - MOCK_METHOD1(removedMainConnection, void(const am_mainConnectionID_t mainConnection)); - MOCK_METHOD2(removedSink, void(const am_sinkID_t sinkID, const bool visible)); - MOCK_METHOD2(removedSource, void(const am_sourceID_t sourceID, const bool visible)); - MOCK_METHOD1(removeDomain, void(const am_domainID_t domainID)); - MOCK_METHOD1(removeGateway, void(const am_gatewayID_t gatewayID)); - MOCK_METHOD1(removeConverter, void(const am_converterID_t converterID)); - MOCK_METHOD1(removeCrossfader, void(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD2(mainConnectionStateChanged, void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); - MOCK_METHOD2(mainSinkSoundPropertyChanged, void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty)); - MOCK_METHOD2(mainSourceSoundPropertyChanged, void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty)); - MOCK_METHOD2(sinkAvailabilityChanged, void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(sourceAvailabilityChanged, void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(volumeChanged, void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); - MOCK_METHOD2(sinkMuteStateChanged, void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD1(systemPropertyChanged, void(const am_SystemProperty_s& SystemProperty)); - MOCK_METHOD2(timingInformationChanged, void(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)); - MOCK_METHOD4(sinkUpdated, void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible)); - MOCK_METHOD4(sourceUpdated, void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible)); - MOCK_METHOD2(sinkMainNotificationConfigurationChanged, void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration)); - MOCK_METHOD2(sourceMainNotificationConfigurationChanged, void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration)); - - static MockDatabaseObserver *getMockObserverObject() - { - static MockDatabaseObserver glMockObserverObject; - return &glMockObserverObject; - } -}; - - - -} // namespace am -#endif /* MOCKDATABASEOBSERVER_H_ */ diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp deleted file mode 100644 index 647dad5..0000000 --- a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ /dev/null @@ -1,3178 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 - * - * For further information see http://www.genivi.org/. - * - */ - -#include -#include -#include "CAmRouterMapTest.h" -#include -#include "CAmDltWrapper.h" - - - - -using namespace am; -using namespace testing; - -CAmRouterMapTest::CAmRouterMapTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pControlSender(), // - pDatabaseHandler(), - 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); -} - -CAmRouterMapTest::~CAmRouterMapTest() -{ - -} - -void CAmRouterMapTest::SetUp() -{ - logInfo("Routing Test started "); -} - -void CAmRouterMapTest::TearDown() -{ -} - -ACTION(returnConnectionFormat){ - arg4=arg3; -} - -void CAmRouterMapTest::enterDomainDB(const std::string & domainName, am_domainID_t & domainID) -{ - am_Domain_s domain1; - domain1.domainID = 0; - domain1.name = domainName; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID)); -} - -void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID) -{ - am_Source_s source; - source.domainID = domainID; - source.name = sourceName; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats = connectionFormats; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); -} - -void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID) -{ - am_Sink_s sink; - sink.domainID = domainID; - sink.name = sinkName; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats = connectionFormats; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); -} - -void CAmRouterMapTest::enterGatewayDB(const std::string & gwName, - const am_domainID_t domainSourceID, - const am_domainID_t domainSinkID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_gatewayID_t & gatewayID) -{ - am_Gateway_s gateway; - gateway.controlDomainID = domainSourceID; - gateway.gatewayID = 0; - gateway.sinkID = sinkID; - gateway.sourceID = sourceID; - gateway.domainSourceID = domainSourceID; - gateway.domainSinkID = domainSinkID; - gateway.listSinkFormats = sinkConnectionFormats; - gateway.listSourceFormats = sourceConnectionFormats; - gateway.convertionMatrix = matrix; - gateway.name = gwName; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); -} - -void CAmRouterMapTest::enterConverterDB(const std::string & gwName, - const am_domainID_t domainID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_converterID_t & converterID) -{ - am_Converter_s converter; - converter.converterID = 0; - converter.sinkID = sinkID; - converter.sourceID = sourceID; - converter.domainID = domainID; - converter.listSinkFormats = sinkConnectionFormats; - converter.listSourceFormats = sourceConnectionFormats; - converter.convertionMatrix = matrix; - converter.name = gwName; - ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter,converterID)); -} - -void CAmRouterMapTest::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) -{ - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, aSource, aSink, listRoutes)); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << "getRoute did find " << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); -} - -void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList) -{ - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, sourceID, sinkID, returnList)); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << "getRoute by id did find " << returnList.size() <<" routes from " << sourceID << " to " << sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); -} - -void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles) -{ - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getAllPaths(aSource, aSink, resultPath, resultNodesPath, includeCycles)); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << "getAllPaths did find " << resultPath.size() - << " routes from " << aSource.getData().data.source->sourceID - << " to " << aSink.getData().data.sink->sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); -} - -TEST_F(CAmRouterMapTest,checkInsertedDomain) -{ - std::vector domains; - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); - domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); - domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50)); - domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); - domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60)); -} - -//test that checks just sinks and source in a domain but connectionformats do not match -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); -} - -//test that checks just sinks and source in a domain -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - - getRoute(true,sourceID,sinkID,listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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)); - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks just 2 domains, with gateway for each direction (possible circular route) -TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) -{ - 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, gwSource2; - am_sourceID_t sourceID, gwSourceID, gwSourceID2; - - 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); - - gwSource2.domainID = domainID1; - gwSource2.name = "gwsource2"; - gwSource2.sourceState = SS_ON; - gwSource2.sourceID = 0; - gwSource2.sourceClassID = 5; - gwSource2.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(gwSource2,gwSourceID2)); - - am_Sink_s sink, gwSink, gwSink2; - am_sinkID_t sinkID, gwSinkID, gwSinkID2; - - 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); - - gwSink2.domainID = domainID2; - gwSink2.name = "gwSink2"; - gwSink2.sinkID = 0; - gwSink2.sinkClassID = 5; - gwSink2.muteState = MS_MUTED; - gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); - - am_Gateway_s gateway, gateway2; - am_gatewayID_t gatewayID, 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"; - - gateway2.controlDomainID = domainID1; - gateway2.gatewayID = 0; - gateway2.sinkID = gwSinkID2; - gateway2.sourceID = gwSourceID2; - gateway2.domainSourceID = domainID1; - gateway2.domainSinkID = domainID2; - 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(gateway2,gatewayID2)); - - 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::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(2), listRoutes.size()); - - bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { - return pCF.compareRoute(compareRoute, ref); - })!=listRoutes.end(); - bool containsRoute2 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { - return pCF.compareRoute(compareRoute1, ref); - })!=listRoutes.end(); - - ASSERT_TRUE(containsRoute1); - ASSERT_TRUE(containsRoute2); -} - -//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); -} -//test that checks just 2 domains, one sink one source with only one connection format each -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(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(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); - } - -//test that checks 3 domains, one sink one source. -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks 4 domains, one sink and one source. -TEST_F(CAmRouterMapTest,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; - - am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,getAllowedFormatsFromConvMatrix) -{ - std::vector convertionMatrix; - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - convertionMatrix.push_back(0); - convertionMatrix.push_back(1); - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - - std::vector listSourceFormats; - listSourceFormats.push_back(CF_GENIVI_ANALOG); - listSourceFormats.push_back(CF_GENIVI_STEREO); - - std::vector listSinkFormats; - listSinkFormats.push_back(CF_GENIVI_MONO); - listSinkFormats.push_back(CF_GENIVI_AUTO); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - std::vector sourceFormats; - std::vector sinkFormats; - - ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - ASSERT_TRUE(sourceFormats.size()==3); - ASSERT_TRUE(sinkFormats.size()==3); - ASSERT_TRUE(sourceFormats.at(0)==CF_GENIVI_ANALOG); - ASSERT_TRUE(sourceFormats.at(1)==CF_GENIVI_STEREO); - ASSERT_TRUE(sourceFormats.at(2)==CF_GENIVI_ANALOG); - ASSERT_TRUE(sinkFormats.at(0)==CF_GENIVI_MONO); - ASSERT_TRUE(sinkFormats.at(1)==CF_GENIVI_AUTO); - ASSERT_TRUE(sinkFormats.at(2)==CF_GENIVI_STEREO); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - listSinkFormats.push_back(CF_GENIVI_STEREO); - listSourceFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - listSourceFormats.push_back(CF_GENIVI_STEREO); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); -} - -TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); - - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - cf1.push_back(CF_GENIVI_ANALOG); - enterSourceDB("source1", domainID1, cf1, sourceID); - - am_sinkID_t sinkID; - std::vector cf2; - cf2.push_back(CF_GENIVI_ANALOG); - cf2.push_back(CF_GENIVI_MONO); - enterSinkDB("sink1", domainID1, cf2, sinkID); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - - hopp1.sourceID = sourceID; - hopp1.sinkID = sinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = cf2[0]; - - listRoutingElements.push_back(hopp1); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); - - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - cf1.push_back(CF_GENIVI_AUTO); - enterSourceDB("source1", domainID1, cf1, sourceID); - - am_sinkID_t sinkID1, sinkID2; - std::vector cf2; - cf2.push_back(CF_GENIVI_MONO); - cf2.push_back(CF_GENIVI_ANALOG); - enterSinkDB("sink1", domainID1, cf2, sinkID1); - enterSinkDB("sink2", domainID1, cf2, sinkID2); - - am_sourceID_t gwSourceID; - std::vector cf3; - cf3.push_back(CF_GENIVI_MONO); - cf3.push_back(CF_GENIVI_ANALOG); - enterSourceDB("gwSource1", domainID1, cf3, gwSourceID); - - am_sinkID_t gwSinkID; - std::vector cf4; - cf4.push_back(CF_GENIVI_STEREO); - cf4.push_back(CF_GENIVI_ANALOG); - enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); - - am_converterID_t converterID; - std::vector matrix; - matrix.resize(4, false); - matrix[0]=(true); - matrix[1]=(true); - enterConverterDB("converter", domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, converterID); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sinkID1, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = CF_GENIVI_STEREO; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = sinkID1; - hopp2.domainID = domainID1; - hopp2.connectionFormat = CF_GENIVI_MONO; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID1; - compareRoute.sourceID = sourceID; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); - - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - std::vector cf2; - cf2.push_back(CF_GENIVI_MONO); - std::vector cf3; - cf3.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cf1, sourceID); - - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID1, cf3, sinkID); - - am_sourceID_t gwSourceID; - enterSourceDB("gwSource1", domainID1, cf2, gwSourceID); - am_sinkID_t gwSinkID; - enterSinkDB("gwSink1", domainID1, cf1, gwSinkID); - am_converterID_t converterID; - std::vector matrix; - matrix.push_back(true); - enterConverterDB("converter1", domainID1, cf2, cf1, matrix, gwSourceID, gwSinkID, converterID); - - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource2", domainID1, cf2, gwSourceID1); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink2", domainID1, cf1, gwSinkID1); - am_converterID_t converterID1; - enterConverterDB("converter2", domainID1, cf2, cf1, matrix, gwSourceID1, gwSinkID1, converterID1); - - am_sourceID_t gwSourceID2; - enterSourceDB("gwSource3", domainID1, cf3, gwSourceID2); - am_sinkID_t gwSinkID2; - enterSinkDB("gwSink3", domainID1, cf2, gwSinkID2); - am_converterID_t converterID2; - enterConverterDB("converter3", domainID1, cf3, cf2, matrix, gwSourceID2, gwSinkID2, converterID2); - - am::am_Source_s source; - am::am_Sink_s sink; - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - - std::vector listRoutes; - std::vector listRoutingElements1; - std::vector listRoutingElements2; - am_RoutingElement_s hopp11; - am_RoutingElement_s hopp12; - am_RoutingElement_s hopp13; - am_RoutingElement_s hopp21; - am_RoutingElement_s hopp22; - - hopp11.sourceID = sourceID; - hopp11.sinkID = gwSinkID; - hopp11.domainID = domainID1; - hopp11.connectionFormat = CF_GENIVI_STEREO; - - hopp12.sourceID = gwSourceID; - hopp12.sinkID = gwSinkID2; - hopp12.domainID = domainID1; - hopp12.connectionFormat = CF_GENIVI_MONO; - - hopp21.sourceID = sourceID; - hopp21.sinkID = gwSinkID1; - hopp21.domainID = domainID1; - hopp21.connectionFormat = CF_GENIVI_STEREO; - - hopp22.sourceID = gwSourceID1; - hopp22.sinkID = gwSinkID2; - hopp22.domainID = domainID1; - hopp22.connectionFormat = CF_GENIVI_MONO; - - hopp13.sourceID = gwSourceID2; - hopp13.sinkID = sinkID; - hopp13.domainID = domainID1; - hopp13.connectionFormat = CF_GENIVI_AUTO; - - listRoutingElements1.push_back(hopp11); - listRoutingElements1.push_back(hopp12); - listRoutingElements1.push_back(hopp13); - - listRoutingElements2.push_back(hopp21); - listRoutingElements2.push_back(hopp22); - listRoutingElements2.push_back(hopp13); - - am_Route_s compareRoute1; - compareRoute1.route = listRoutingElements1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(2), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); - - am_Route_s compareRoute2; - compareRoute2.route = listRoutingElements2; - compareRoute2.sinkID = sinkID; - compareRoute2.sourceID = sourceID; - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])||pCF.compareRoute(compareRoute2,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - enterSourceDB("source1", domainID1, cf1, sourceID); - - am_sinkID_t sinkID; - std::vector cf2; - cf2.push_back(CF_GENIVI_ANALOG); - enterSinkDB("sink1", domainID2, cf2, sinkID); - - am_sourceID_t gwSourceID; - std::vector cf3; - cf3.push_back(CF_GENIVI_ANALOG); - enterSourceDB("gwSource1", domainID2, cf3, gwSourceID); - - am_sinkID_t gwSinkID; - std::vector cf4; - cf4.push_back(CF_GENIVI_STEREO); - enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); - - am_gatewayID_t gatewayID; - std::vector matrix; - matrix.push_back(true); - enterGatewayDB("gateway", domainID2, domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, gatewayID); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - std::vector listRoutes; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID, sinkID, domainID2, CF_GENIVI_ANALOG}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1, domainID2, domainID3; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - enterDomainDB("domain3", domainID3); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); - - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); - - std::vector matrix; - matrix.push_back(true); - - am_gatewayID_t gatewayID; - enterGatewayDB("gateway", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); - - am_sourceID_t gwSourceID2; - enterSourceDB("gwSource2", domainID3, cfStereo, gwSourceID2); - - am_sinkID_t gwSinkID2; - enterSinkDB("gwSink2", domainID2, cfMono, gwSinkID2); - - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID3, cfStereo, sinkID); - - am_gatewayID_t gatewayID1; - enterGatewayDB("gateway", domainID3, domainID2, cfStereo, cfMono, matrix, gwSourceID2, gwSinkID2, gatewayID1); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID1, gwSinkID2, domainID2, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID2, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1); - - am_sinkID_t coSinkID21; - enterSinkDB("coSink21", domainID1, cfStereo, coSinkID21); - - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID1, cfMono, coSourceID21); - - am_converterID_t converterID1; - enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1); - - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource21", domainID2, cfAuto, gwSourceID1); - - am_gatewayID_t gatewayID; - enterGatewayDB("gateway1", domainID2, domainID1, cfAuto, cfMono, matrix, gwSourceID1, gwSinkID1, gatewayID); - - am_sinkID_t sinkID1; - enterSinkDB("sink1", domainID2, cfAuto, sinkID1); - - am_sinkID_t sinkID2; - enterSinkDB("sink2", domainID1, cfAuto, sinkID2); - - am::am_Source_s source; - am::am_Sink_s sink1; - pDatabaseHandler.getSinkInfoDB(sinkID1, sink1); - am::am_Sink_s sink2; - pDatabaseHandler.getSinkInfoDB(sinkID2, sink2); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - - getRoute(false, source, sink1, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID1; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, coSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({coSourceID21, gwSinkID1, domainID1, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID1, sinkID1, domainID2, CF_GENIVI_AUTO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); - - listRoutes.clear(); - getRoute(false, source, sink2, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); -} - -TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t gwSinkID11; - enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); - am_sourceID_t gwSourceID11; - enterSourceDB("gwSource11", domainID2, cfAnalog, gwSourceID11); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID11, gwSinkID11, gatewayID1); - - am_sinkID_t gwSinkID21; - enterSinkDB("gwSink21", domainID2, cfAnalog, gwSinkID21); - am_sourceID_t gwSourceID12; - enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); - am_gatewayID_t gatewayID2; - enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfAnalog, matrix, gwSourceID12, gwSinkID21, gatewayID2); - - am_sinkID_t sink1ID; - enterSinkDB("sink1", domainID1, cfAuto, sink1ID); - am_sinkID_t sink2ID; - enterSinkDB("sink2", domainID2, cfAnalog, sink2ID); - - std::vector listRoutes; - - am::am_Source_s source; - am::am_Sink_s sink1; - pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - getRoute(false, source, sink1, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - am::am_Sink_s sink2; - pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); - - getRoute(false, source, sink2, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sink2ID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID11, sink2ID, domainID2, CF_GENIVI_ANALOG}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t gwSinkID11; - enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); - - am_sourceID_t gwSourceID21; - enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); - - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1); - - am_sinkID_t gwSinkID21; - enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); - - am_sourceID_t gwSourceID12; - enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); - - am_sinkID_t coSinkID21; - enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); - - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); - - am_converterID_t converterID2; - enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); - - am_gatewayID_t gatewayID2; - enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); - - am_sinkID_t sink1ID; - enterSinkDB("sink1", domainID1, cfAuto, sink1ID); - am_sinkID_t sink2ID; - enterSinkDB("sink2", domainID2, cfStereo, sink2ID); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sink1ID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - am::am_Sink_s sink1; - pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); - getRoute(false, source, sink1, listRoutes); - - ASSERT_EQ(static_cast(1), listRoutes.size()); - am_Route_s compareRoute1; - compareRoute1.sinkID = sink2ID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - compareRoute1.route.push_back({coSourceID21, sink2ID, domainID2, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); -} - -TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - std::vector cfFuture1; - cfFuture1.push_back(5); - std::vector cfFuture2; - cfFuture2.push_back(6); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t coSinkID11; - enterSinkDB("coSink11", domainID1, cfStereo, coSinkID11); - am_sourceID_t coSourceID11; - enterSourceDB("coSource11", domainID1, cfFuture1, coSourceID11); - am_converterID_t converterID11; - enterConverterDB("converter11", domainID1, cfFuture1, cfStereo, matrix, coSourceID11, coSinkID11, converterID11); - - am_sinkID_t coSinkID12; - enterSinkDB("coSink12", domainID1, cfStereo, coSinkID12); - am_sourceID_t coSourceID12; - enterSourceDB("coSource12", domainID1, cfFuture2, coSourceID12); - am_converterID_t converterID12; - enterConverterDB("converter12", domainID1, cfFuture2, cfStereo, matrix, coSourceID12, coSinkID12, converterID12); - - am_sinkID_t coSinkID13; - enterSinkDB("coSink13", domainID1, cfFuture2, coSinkID13); - am_sourceID_t coSourceID13; - enterSourceDB("coSource13", domainID1, cfFuture1, coSourceID13); - am_converterID_t converterID13; - enterConverterDB("converter13", domainID1, cfFuture1, cfFuture2, matrix, coSourceID13, coSinkID13, converterID13); - - am_sinkID_t gwSinkID11; - enterSinkDB("gwSink11", domainID1, cfFuture1, gwSinkID11); - am_sourceID_t gwSourceID21; - enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfFuture1, matrix, gwSourceID21, gwSinkID11, gatewayID1); - - am_sinkID_t gwSinkID21; - enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); - - am_sourceID_t gwSourceID12; - enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); - - am_sinkID_t coSinkID21; - enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); - - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); - - am_converterID_t converterID2; - enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); - - - am_gatewayID_t gatewayID2; - enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); - - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID1, cfAuto, sinkID); - - am::am_Source_s source; - am::am_Sink_s sink; - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - am::am_Sink_s sink2; - pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); - pRouter.getRoute(false, source, sink2, listRoutes); - ASSERT_EQ(static_cast(2), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = coSinkID21; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, coSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({coSourceID11, gwSinkID11, domainID1, 5}); - compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - - am_Route_s compareRoute2; - compareRoute2.sinkID = coSinkID21; - compareRoute2.sourceID = sourceID; - compareRoute2.route.push_back({sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO}); - compareRoute2.route.push_back({coSourceID12, coSinkID13, domainID1, 6}); - compareRoute2.route.push_back({coSourceID13, gwSinkID11, domainID1, 5}); - compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])||pCF.compareRoute(compareRoute1,listRoutes[0])); - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); -} - -TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domain1ID, domain2ID, domain3ID; - enterDomainDB("domain1", domain1ID); - enterDomainDB("domain2", domain2ID); - enterDomainDB("domain3", domain3ID); - - //just make so many cycles as possible - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog = cfStereo; - std::vector cfMono = cfStereo; - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t source1ID; - enterSourceDB("source1", domain1ID, cfStereo, source1ID); - am_sinkID_t gw1SinkID; - enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); - am_sinkID_t gw2SinkID; - enterSinkDB("gw2Sink", domain1ID, cfStereo, gw2SinkID); - am_sourceID_t gw3SourceID; - enterSourceDB("gw3Source", domain1ID, cfAnalog, gw3SourceID); - am_sourceID_t gw4SourceID; - enterSourceDB("gw4Source", domain1ID, cfAnalog, gw4SourceID); - am_sinkID_t gw5SinkID; - enterSinkDB("gw5Sink", domain1ID, cfAnalog, gw5SinkID); - - am_sourceID_t gw1SourceID; - enterSourceDB("gw1Source", domain2ID, cfMono, gw1SourceID); - am_sourceID_t gw2SourceID; - enterSourceDB("gw2Source", domain2ID, cfMono, gw2SourceID); - am_sinkID_t gw3SinkID; - enterSinkDB("gw3Sink", domain2ID, cfMono, gw3SinkID); - am_sinkID_t gw4SinkID; - enterSinkDB("gw4Sink", domain2ID, cfMono, gw4SinkID); - - am_sourceID_t gw5SourceID; - enterSourceDB("gw5Source", domain3ID, cfStereo, gw5SourceID); - am_sinkID_t sink1ID; - enterSinkDB("sink1", domain3ID, cfStereo, sink1ID); - - std::vector matrixT; - matrixT.push_back(true); - std::vector matrixF; - matrixF.push_back(false); - - am_gatewayID_t gateway1ID; - enterGatewayDB("gateway1", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); - am_gatewayID_t gateway2ID; - enterGatewayDB("gateway2", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw2SourceID, gw2SinkID, gateway2ID); - am_gatewayID_t gateway3ID; - enterGatewayDB("gateway3", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw3SourceID, gw3SinkID, gateway3ID); - am_gatewayID_t gateway4ID; - enterGatewayDB("gateway4", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw4SourceID, gw4SinkID, gateway4ID); - am_gatewayID_t gateway5ID; - enterGatewayDB("gateway5", domain3ID, domain1ID, cfStereo, cfAnalog, matrixT, gw5SourceID, gw5SinkID, gateway5ID); - - pRouter.load(false); - - CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); - CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); - - ASSERT_TRUE(sourceNode); - ASSERT_TRUE(sinkNode); - - std::vector listRoutes; - std::vector> resultNodesPath; - - am_Route_s compareRoute1; - compareRoute1.sinkID = sink1ID; - compareRoute1.sourceID = source1ID; - -#define DO_ASSERT() \ - {\ - bool didMatch = false; \ - for(auto it = listRoutes.begin(); it!=listRoutes.end(); it++) \ - didMatch|=pCF.compareRoute(compareRoute1,*it); \ - ASSERT_TRUE(didMatch); \ - } - -#ifdef ROUTING_BUILD_CONNECTIONS - getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, true); - ASSERT_EQ(static_cast(9), listRoutes.size()); - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() -#else - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); -#endif - - listRoutes.clear(); - resultNodesPath.clear(); - getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, false); - ASSERT_EQ(static_cast(1), listRoutes.size()); - DO_ASSERT() -} - -TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) -{ - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - - am_domainID_t domainID1, domainID2, domainID3; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - enterDomainDB("domain3", domainID3); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); - am_sinkID_t gwSinkID21; - enterSinkDB("gwSink21", domainID1, cfStereo, gwSinkID21); - - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); - am_sinkID_t gwSinkID22; - enterSinkDB("gwSink22", domainID2, cfMono, gwSinkID22); - - am_sourceID_t gwSourceID21; - enterSourceDB("gwSource21", domainID3, cfAuto, gwSourceID21); - - am_sourceID_t gwSourceID22; - enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22); - am_sourceID_t gwSourceID5; - enterSourceDB("gwSource5", domainID3, cfStereo, gwSourceID5); - am_sinkID_t gwSinkID5; - enterSinkDB("gwSink5", domainID3, cfAnalog, gwSinkID5); - am_sourceID_t gwSourceID3; - enterSourceDB("gwSource3", domainID3, cfAnalog, gwSourceID3); - am_sinkID_t gwSinkID3; - enterSinkDB("gwSink3", domainID3, cfAuto, gwSinkID3); - am_sourceID_t gwSourceID4; - enterSourceDB("gwSource4", domainID3, cfStereo, gwSourceID4); - am_sinkID_t gwSinkID4; - enterSinkDB("gwSink4", domainID3, cfAnalog, gwSinkID4); - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID3, cfStereo, sinkID); - - std::vector matrix; - matrix.push_back(true); - am_gatewayID_t gatewayID; - enterGatewayDB("gateway1", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); - am_gatewayID_t gatewayID22; - enterGatewayDB("gateway22", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID22, gwSinkID22, gatewayID22); - am_gatewayID_t gatewayID21; - enterGatewayDB("gateway21", domainID3, domainID1, cfAuto, cfStereo, matrix, gwSourceID21, gwSinkID21, gatewayID21); - am_converterID_t converterID1; - enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, gwSourceID3, gwSinkID3, converterID1); - am_converterID_t converterID2; - enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, gwSourceID4, gwSinkID4, converterID2); - am_converterID_t converterID3; - enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, gwSourceID5, gwSinkID5, converterID3); - - am::am_Source_s source; - am::am_Sink_s sink; - - pDatabaseHandler.getSinkInfoDB(sinkID, sink); - pDatabaseHandler.getSourceInfoDB(sourceID, source); - - std::vector listRoutes; - - getRoute(false, source, sink, listRoutes); - ASSERT_EQ(static_cast(4), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute1.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute1.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute2; - compareRoute2.sinkID = sinkID; - compareRoute2.sourceID = sourceID; - compareRoute2.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute2.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute2.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute2.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute2.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute3; - compareRoute3.sinkID = sinkID; - compareRoute3.sourceID = sourceID; - compareRoute3.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute3.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute3.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute3.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute4; - compareRoute4.sinkID = sinkID; - compareRoute4.sourceID = sourceID; - compareRoute4.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute4.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute4.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute4.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| - pCF.compareRoute(compareRoute1,listRoutes[1])|| - pCF.compareRoute(compareRoute1,listRoutes[2])|| - pCF.compareRoute(compareRoute1,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])|| - pCF.compareRoute(compareRoute2,listRoutes[1])|| - pCF.compareRoute(compareRoute2,listRoutes[2])|| - pCF.compareRoute(compareRoute2,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])|| - pCF.compareRoute(compareRoute3,listRoutes[1])|| - pCF.compareRoute(compareRoute3,listRoutes[2])|| - pCF.compareRoute(compareRoute3,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[0])|| - pCF.compareRoute(compareRoute4,listRoutes[1])|| - pCF.compareRoute(compareRoute4,listRoutes[2])|| - pCF.compareRoute(compareRoute4,listRoutes[3])); -} - -int main(int argc, char **argv) -{ -#ifdef WITH_DLT - CAmDltWrapper::instance()->registerApp("routing", "CAmRouterMapTest"); -#else - CAmDltWrapper::instance(true)->registerApp("routing", "CAmRouterMapTest"); -#endif - logInfo("Routing Test started "); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h deleted file mode 100644 index 65ff97b..0000000 --- a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MAPTEST_H_ -#define MAPTEST_H_ - -#define UNIT_TEST 1 - -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include -#include -#include -#include -#include "CAmDatabaseHandlerMap.h" -#include "CAmControlReceiver.h" -#include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" -#include "CAmRoutingSender.h" -#include "CAmRouter.h" -#include "CAmSocketHandler.h" -#include "../IAmControlBackdoor.h" -#include "../IAmCommandBackdoor.h" -#include "../CAmCommonFunctions.h" -#include "../MockIAmControlSend.h" -#include "../MockIAmCommandSend.h" - - -namespace am -{ - -class CAmRouterMapTest: public ::testing::Test -{ -public: - CAmRouterMapTest(); - ~CAmRouterMapTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - CAmSocketHandler pSocketHandler; - CAmControlSender pControlSender; - CAmDatabaseHandlerMap pDatabaseHandler; - 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(); - - void enterDomainDB(const std::string & domainName, am_domainID_t & domainID); - void enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID); - void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID); - void enterGatewayDB(const std::string & gwName, - const am_domainID_t domainSourceID, - const am_domainID_t domainSinkID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_gatewayID_t & gatewayID); - void enterConverterDB(const std::string & gwName, - const am_domainID_t domainID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_converterID_t & converterID); - void getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - void getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); - void getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles); -}; - -} - -#endif /* MAPTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt deleted file mode 100644 index 720ef64..0000000 --- a/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project (AmRouterMapTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} -) - -file(GLOB ROUTINGMAP_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "../CAmCommonFunctions.cpp" - "*.cpp" - ) - -ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmRouterMapTest - ${AM_LINK_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmRouterMapTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmRouterMapTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp deleted file mode 100644 index e88d54b..0000000 --- a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp +++ /dev/null @@ -1,1960 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmRouterTest.h" -#include -#include "CAmDltWrapper.h" - -using namespace am; -using namespace testing; - -CAmRouterTest::CAmRouterTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pControlSender(), // - pDatabaseHandler(), - 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)); - source.sourceID=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)); - sink.sinkID=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(static_cast(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(static_cast(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; - - std::vector listConnections; - pDatabaseHandler.getListConnections(listConnections); - ASSERT_EQ(0, listConnections.size()); - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(static_cast(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(static_cast(0), listRoutes.size()); - - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -//test that checks just 2 domains, with gateway for each direction (possible circular route) -TEST_F(CAmRouterTest,simpleRoute2DomainsCircularGWOnlyFree) -{ - - 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, gwSource2; - am_sourceID_t sourceID, gwSourceID, gwSourceID2; - - 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); - - gwSource2.domainID = domainID1; - gwSource2.name = "gwsource2"; - gwSource2.sourceState = SS_ON; - gwSource2.sourceID = 0; - gwSource2.sourceClassID = 5; - gwSource2.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(gwSource2,gwSourceID2)); - - am_Sink_s sink, gwSink, gwSink2; - am_sinkID_t sinkID, gwSinkID, gwSinkID2; - - 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); - - gwSink2.domainID = domainID2; - gwSink2.name = "gwSink2"; - gwSink2.sinkID = 0; - gwSink2.sinkClassID = 5; - gwSink2.muteState = MS_MUTED; - gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); - - am_Gateway_s gateway, gateway2; - am_gatewayID_t gatewayID, 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"; - - gateway2.controlDomainID = domainID1; - gateway2.gatewayID = 0; - gateway2.sinkID = gwSinkID2; - gateway2.sourceID = gwSourceID2; - gateway2.domainSourceID = domainID1; - gateway2.domainSinkID = domainID2; - 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(gateway2,gatewayID2)); - - 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(static_cast(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(static_cast(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(static_cast(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(static_cast(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(static_cast(2), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]) || pCF.compareRoute(compareRoute,listRoutes[1]) ); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1]) || pCF.compareRoute(compareRoute1,listRoutes[0]) ); -} - -//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(static_cast(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(static_cast(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(static_cast(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(static_cast(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)); - size_t size(1); - ASSERT_EQ(size, listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); -} - -int main(int argc, char **argv) -{ -#ifdef WITH_DLT - CAmDltWrapper::instance()->registerApp("routing", "CAmRouterTest"); -#else - CAmDltWrapper::instance(true)->registerApp("routing", "CAmRouterTest"); -#endif - 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 deleted file mode 100644 index 4a4e35b..0000000 --- a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h +++ /dev/null @@ -1,81 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASETEST_H_ -#define DATABASETEST_H_ - -#define UNIT_TEST 1 - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include -#include -#include -#include -#include "CAmDatabaseHandlerMap.h" -#include "CAmControlReceiver.h" -#include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" -#include "CAmRoutingSender.h" -#include "CAmRouter.h" -#include "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; - CAmControlSender pControlSender; - CAmDatabaseHandlerMap pDatabaseHandler; - 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 deleted file mode 100644 index e9b0e80..0000000 --- a/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project(AmRouterTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} -) - -file(GLOB ROUTING_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "../CAmCommonFunctions.cpp" - "*.cpp" - ) - -ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmRouterTest - ${AM_LINK_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmRouterTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmRouterTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp deleted file mode 100644 index 347b65a..0000000 --- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmRoutingInterfaceTest.h" -#include "CAmDltWrapper.h" - -using namespace am; -using namespace testing; - -CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pDatabaseHandler(), // - 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 = DYNAMIC_ID_BOUNDARY; - - //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 = DYNAMIC_ID_BOUNDARY; - 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_GENIVI_TREBLE; - soundProperty.value = 23; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = DYNAMIC_ID_BOUNDARY; - 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(1).WillOnce(Return(E_NO_CHANGE)); - 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 = DYNAMIC_ID_BOUNDARY; - 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 = DYNAMIC_ID_BOUNDARY; - 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; - soundProperty.value=5; - soundProperty.type=SP_GENIVI_MID; - std::vector listHandles; - pCF.createSink(sink); - pCF.createDomain(domain); - domain.name = "mock"; - domain.busname = "mock"; - sink.sinkID = 2; - sink.domainID = DYNAMIC_ID_BOUNDARY; - 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,_)).WillOnce(Return(E_OK)); - soundProperty.value=10; - 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,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_CustomRampType_t 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 = DYNAMIC_ID_BOUNDARY; - 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,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_CustomRampType_t 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 = DYNAMIC_ID_BOUNDARY; - 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 = DYNAMIC_ID_BOUNDARY; - 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 = DYNAMIC_ID_BOUNDARY; - 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()); -} - - -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 deleted file mode 100644 index 75a7511..0000000 --- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef ROUTINGINTERFACETEST_H_ -#define ROUTINGINTERFACETEST_H_ - -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include -#include -#include -#include -#include "CAmDatabaseHandlerMap.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 "CAmSocketHandler.h" - -namespace am -{ - -class CAmRoutingInterfaceTest: public ::testing::Test -{ -public: - CAmRoutingInterfaceTest(); - ~CAmRoutingInterfaceTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - CAmSocketHandler pSocketHandler; - CAmDatabaseHandlerMap 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 deleted file mode 100644 index 426ac7a..0000000 --- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project (AmRoutingInterfaceTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -find_package(PkgConfig) - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${STD_INCLUDE_DIRS} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} -) - -if(WITH_DLT) - INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) -endif(WITH_DLT) - -file(GLOB ROUTING_INTERFACE_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "../CAmCommonFunctions.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest - ${AM_LINK_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmRoutingInterfaceTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmRoutingInterfaceTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - diff --git a/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp deleted file mode 100644 index 50e2aa9..0000000 --- a/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmSocketHandlerTest.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "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; - mSocketHandler->updateTimer(handle,timeout); -} - -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 = 011110000; - timeout.tv_sec = 1; - mSocketHandler->updateTimer(handle,timeout); -} - -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,playWithTimers) -{ - CAmSocketHandler myHandler; - CAmTimerCb testCallback(&myHandler); - timespec timeoutTime, timeout2, timeout3, timeout4; - timeoutTime.tv_sec = 1; - timeoutTime.tv_nsec = 02223234; - timeout2.tv_nsec = 333000; - timeout2.tv_sec = 0; - timeout3.tv_nsec = 333; - timeout3.tv_sec = 3; - timeout4.tv_nsec = 0; - timeout4.tv_sec = 20; - sh_timerHandle_t handle; - myHandler.addTimer(timeoutTime, &testCallback.pTimer1Callback, handle, NULL); - myHandler.addTimer(timeout2, &testCallback.pTimer2Callback, handle, NULL); - myHandler.addTimer(timeout3, &testCallback.pTimer3Callback, handle, NULL); - myHandler.addTimer(timeout4, &testCallback.pTimer4Callback, handle, NULL); - myHandler.start_listenting(); - -} - - -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); -} - - -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, 0); - 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 deleted file mode 100644 index 95e5446..0000000 --- a/AudioManagerDaemon/test/AmSocketHandlerTest/CAmSocketHandlerTest.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef SOCKETHANDLERTEST_H_ -#define SOCKETHANDLERTEST_H_ - -#define WITH_DLT - -#include "gtest/gtest.h" -#include -#include "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 deleted file mode 100644 index bff74b6..0000000 --- a/AudioManagerDaemon/test/AmSocketHandlerTest/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -project(AmSocketHandlerTest) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${AUDIOMANAGER_UTILITIES_INCLUDE} - ${GMOCK_INCLUDE_DIR} -) - -if(WITH_DLT) - INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) -endif(WITH_DLT) - -file(GLOB Socket_SRCS_CXX - "*.cpp" -) - -ADD_EXECUTABLE(AmSocketHandlerTest ${Socket_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmSocketHandlerTest - ${AM_LINK_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmSocketHandlerTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmSocketHandlerTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - - diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp deleted file mode 100644 index f91a2d0..0000000 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include -#include -#include -#include - -#include "CAmTelnetServerTest.h" -#include "CAmCommandReceiver.h" -#include "CAmRoutingReceiver.h" -#include "CAmControlReceiver.h" -#include "audiomanagerconfig.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); - Env->setSocketHandler(&Env->mSocketHandler); - Env->mSocketHandler.start_listenting(); - Env->setSocketHandler(NULL); - return (NULL); -} - -CAmEnvironment::CAmEnvironment() -: mlistRoutingPluginDirs() -, mlistCommandPluginDirs() -, mSocketHandler() -, mDatabasehandler() -, mRoutingSender(mlistRoutingPluginDirs) -, mCommandSender(mlistRoutingPluginDirs) -, 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() -{ - pthread_cancel(mSocketHandlerThread); -} - -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() -{ - -} - -void CAmTelnetServerTest::sendCmd(std::string & command ) -{ - ssize_t sizesent = send(staticSocket, command.c_str(), command.size(), 0); - ASSERT_EQ(static_cast(sizesent),command.size()); - - char buffer[1000]; - memset(buffer,0,sizeof(buffer)); - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); -} - -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 cmd("help"); - sendCmd(cmd); -} - -TEST_F(CAmTelnetServerTest,sendDumpCmdTelnetServer) -{ - std::string cmd1("info"); - std::string cmd3("dump"); - sendCmd(cmd1); - sendCmd(cmd3); -} - -TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) -{ - std::string cmd("exit"); - mpSocketHandler->stop_listening(); - sendCmd(cmd); - 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 deleted file mode 100644 index 02f98a3..0000000 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CAMTELNETSERVERTEST_H_ -#define CAMTELNETSERVERTEST_H_ - -#include "gtest/gtest.h" -#include "CAmTelnetServer.h" -#include "CAmRoutingSender.h" -#include "CAmCommandSender.h" -#include "CAmControlSender.h" -#include "CAmRouter.h" -#include "audiomanagerconfig.h" -#include "CAmDatabaseHandlerMap.h" - - - - - -namespace am -{ - -class CAmSocketHandler; -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; - - CAmSocketHandler mSocketHandler; - CAmDatabaseHandlerMap 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() ; - void sendCmd(std::string & command ); - //int mSocket; -}; - -} - - - - -#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt deleted file mode 100644 index 7f1cc2c..0000000 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - -PROJECT(AmTelnetServerTest) - -set (AM_LINK_LIBS - ${CMAKE_DL_LIBS} - AudioManagerUtilities - rt) - -IF (WITH_CAPI_WRAPPER) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - -Wl,--as-needed CommonAPI - ) -ENDIF (WITH_CAPI_WRAPPER) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") - - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DLT_LIBRARIES}) -endif(WITH_DLT) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${AUDIO_INCLUDE_FOLDER} - ${CMAKE_SOURCE_DIR} - ${INCLUDE_FOLDER} - ${GOOGLE_TEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} -) - -if(WITH_DLT) -INCLUDE_DIRECTORIES( - ${INCLUDE_DIRECTORIES} - ${DLT_INCLUDE_DIRS}) -endif(WITH_DLT) - -file(GLOB TELNET_SRCS_CXX - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmCommandSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmControlSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseObserver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingReceiver.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRoutingSender.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmTelnetServer.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmRouter.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmTelnetMenuHelper.cpp" - "${AUDIOMANAGER_DAEMON_FOLDER}/src/CAmDatabaseHandlerMap.cpp" - "*.cpp" -) - -ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmTelnetServerTest - ${AM_LINK_LIBS} - gtest - gmock -) - -ADD_DEPENDENCIES(AmTelnetServerTest gtest gmock AudioManagerUtilities) - -INSTALL(TARGETS AmTelnetServerTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - - diff --git a/AudioManagerDaemon/test/CAmCommonFunctions.cpp b/AudioManagerDaemon/test/CAmCommonFunctions.cpp deleted file mode 100644 index 22331d4..0000000 --- a/AudioManagerDaemon/test/CAmCommonFunctions.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#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 controlSender->mController == newController; -} - -//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 equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b) -{ - return (a.parameter == b.parameter && a.status == b.status && a.type == b.type); -} - -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::compareConverter(std::vector::iterator listIterator, const am_Converter_s& gatewayData) -{ - return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->domainID == gatewayData.domainID) && 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::compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData) -{ - return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.domainID == gatewayData.domainID) && 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_GENIVI_BASS; - soundProperty.value = 23; - soundPropertyList.push_back(soundProperty); - soundProperty.type = SP_GENIVI_MID; - soundProperty.value = 2; - soundPropertyList.push_back(soundProperty); - return soundPropertyList; -} - -std::vector CAmCommonFunctions::getStandardMainSoundPropertyList() -{ - std::vector mainSoundPropertyList; - am_MainSoundProperty_s mainSoundProperty; - mainSoundProperty.type = MSP_GENIVI_BASS; - 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.listNotificationConfigurations = getStandardNotificationConfigurationList(); - sink.listMainNotificationConfigurations = getStandardNotificationConfigurationList(); - 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.listMainNotificationConfigurations=getStandardNotificationConfigurationList(); - source.listNotificationConfigurations=getStandardNotificationConfigurationList(); - 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::createConverter(am_Converter_s & converter) const -{ - converter.name = "AnyConverter"; - converter.sinkID = 1; - converter.sourceID = 2; - converter.domainID = 1; - converter.convertionMatrix = getStandardConvertionMatrix(); - converter.listSourceFormats = getStandardConnectionFormatList(); - converter.listSinkFormats = getStandardConnectionFormatList(); - converter.converterID = 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; -} - -std::vector am::CAmCommonFunctions::getStandardNotificationConfigurationList() -{ - std::vector listNotificationConfigurations; - am_NotificationConfiguration_s tempNotificationConfiguration; - tempNotificationConfiguration.type=NT_TEST_1; - tempNotificationConfiguration.parameter=12; - tempNotificationConfiguration.status=NS_PERIODIC; - listNotificationConfigurations.push_back(tempNotificationConfiguration); - - tempNotificationConfiguration.type=NT_TEST_2; - tempNotificationConfiguration.parameter=16; - tempNotificationConfiguration.status=NS_CHANGE; - listNotificationConfigurations.push_back(tempNotificationConfiguration); - - return (listNotificationConfigurations); -} - -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 deleted file mode 100644 index 9dbdc8f..0000000 --- a/AudioManagerDaemon/test/CAmCommonFunctions.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef COMMONHEADERS_H_ -#define COMMONHEADERS_H_ - -#include "audiomanagertypes.h" - -namespace am -{ - -static const am_CustomNotificationType_t NT_TEST_1 = 1; -static const am_CustomNotificationType_t NT_TEST_2 = 2; - - -class CAmCommonFunctions -{ -public: - - static std::vector getStandardConnectionFormatList(); - static std::vector getStandardSoundPropertyList(); - static std::vector getStandardMainSoundPropertyList(); - static std::vector getStandardConvertionMatrix(); - static std::vector getStandardNotificationConfigurationList(); - 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 compareConverter(std::vector::iterator listIterator, const am_Converter_s& gatewayData); - bool compareConverter1(const am_Converter_s gateway1, const am_Converter_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 createConverter(am_Converter_s & converter) 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_CustomAvailabilityReason_t & a, const am_CustomAvailabilityReason_t & 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 deleted file mode 100644 index a52f5ae..0000000 --- a/AudioManagerDaemon/test/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 2.8.8) - - -set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) - - -if(USE_BUILD_LIBS) - execute_process(COMMAND mkdir -p "${EXECUTABLE_OUTPUT_PATH}") -endif(USE_BUILD_LIBS) - -#make aunt google stop complaining -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") - -add_subdirectory (AmControlInterfaceTest) -add_subdirectory (AmDatabaseHandlerTest) -add_subdirectory (AmMapHandlerTest) -add_subdirectory (AmRouterTest) -add_subdirectory (AmRouterMapTest) -add_subdirectory (AmRoutingInterfaceTest) -add_subdirectory (AmSocketHandlerTest) - -IF(WITH_TELNET) - add_subdirectory (AmTelnetServerTest) -ENDIF(WITH_TELNET) - diff --git a/AudioManagerDaemon/test/IAmCommandBackdoor.h b/AudioManagerDaemon/test/IAmCommandBackdoor.h deleted file mode 100644 index b7d2b20..0000000 --- a/AudioManagerDaemon/test/IAmCommandBackdoor.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#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 deleted file mode 100644 index b5ba3ef..0000000 --- a/AudioManagerDaemon/test/IAmControlBackdoor.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CONTROLINTERFACEBACKDOOR_H_ -#define CONTROLINTERFACEBACKDOOR_H_ - -#include "IAmControl.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 deleted file mode 100644 index cbdb070..0000000 --- a/AudioManagerDaemon/test/IAmRoutingBackdoor.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#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 deleted file mode 100644 index 36bc1cb..0000000 --- a/AudioManagerDaemon/test/MockIAmCommandSend.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MOCKCOMMANDINTERFACE_H_ -#define MOCKCOMMANDINTERFACE_H_ - -#include "IAmCommand.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -namespace am { - -class MockIAmCommandSend : public IAmCommandSend { - public: - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - 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_METHOD3(cbSinkUpdated, - void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties)); - MOCK_METHOD3(cbSourceUpdated, - void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties)); - MOCK_METHOD2(cbSinkNotification, - void(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification)); - MOCK_METHOD2(cbSourceNotification, - void(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification)); - MOCK_METHOD2(cbMainSinkNotificationConfigurationChanged, - void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); - MOCK_METHOD2(cbMainSourceNotificationConfigurationChanged, - void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); - - - -}; - -} // namespace am -#endif /* MOCKCOMMANDINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/MockIAmControlSend.h b/AudioManagerDaemon/test/MockIAmControlSend.h deleted file mode 100644 index e628068..0000000 --- a/AudioManagerDaemon/test/MockIAmControlSend.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MOCKCONTROLINTERFACE_H_ -#define MOCKCONTROLINTERFACE_H_ - -#include "IAmControl.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -namespace am { - -class MockIAmControlSend : public IAmControlSend { - public: - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD1(startupController, - am_Error_e(IAmControlReceive* controlreceiveinterface)); - MOCK_METHOD0(setControllerReady, - void()); - MOCK_METHOD1(setControllerRundown, - void(const int16_t signal)); - 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(hookSystemRegisterConverter, - am_Error_e(const am_Converter_s& converterData, am_converterID_t& converterID)); - MOCK_METHOD2(hookSystemRegisterGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(hookSystemDeregisterConverter, - am_Error_e(const am_converterID_t converterID)); - 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_METHOD1(confirmCommandReady, - void(const am_Error_e error)); - MOCK_METHOD1(confirmRoutingReady, - void(const am_Error_e error)); - MOCK_METHOD1(confirmCommandRundown, - void(const am_Error_e error)); - MOCK_METHOD1(confirmRoutingRundown, - void(const am_Error_e error)); - MOCK_METHOD5(hookSystemUpdateSink, - am_Error_e(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties)); - MOCK_METHOD5(hookSystemUpdateSource, - am_Error_e(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listSoundProperties, const std::vector& listConnectionFormats, const std::vector& listMainSoundProperties)); - MOCK_METHOD4(hookSystemUpdateConverter, - am_Error_e(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix)); - MOCK_METHOD4(hookSystemUpdateGateway, - am_Error_e(const am_gatewayID_t gatewayID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix)); - MOCK_METHOD3(cbAckSetVolumes, - void(const am_Handle_s handle, const std::vector& listVolumes, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSinkNotificationConfiguration, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(cbAckSetSourceNotificationConfiguration, - void(const am_Handle_s handle, const am_Error_e error)); - MOCK_METHOD2(hookSinkNotificationDataChanged, - void(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload)); - MOCK_METHOD2(hookSourceNotificationDataChanged, - void(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload)); - MOCK_METHOD2(hookUserSetMainSinkNotificationConfiguration, - am_Error_e(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); - MOCK_METHOD2(hookUserSetMainSourceNotificationConfiguration, - am_Error_e(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); - MOCK_METHOD2(hookSystemSingleTimingInformationChanged, - void(const am_connectionID_t connectionID, const am_timeSync_t time)); -}; - - -} // namespace am -#endif /* MOCKCONTROLINTERFACE_H_ */ diff --git a/AudioManagerDaemon/test/MockIAmRoutingSend.h b/AudioManagerDaemon/test/MockIAmRoutingSend.h deleted file mode 100644 index 748e64e..0000000 --- a/AudioManagerDaemon/test/MockIAmRoutingSend.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef MOCKROUTINGINTERFACE_H_ -#define MOCKROUTINGINTERFACE_H_ - -#include "IAmRouting.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -namespace am { - -class MockIAmRoutingSend : public IAmRoutingSend { - public: - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - 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_CustomAvailabilityReason_t 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_CustomRampType_t 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_CustomRampType_t 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_CustomRampType_t 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_METHOD2(asyncSetVolumes, - am_Error_e(const am_Handle_s handle, const std::vector& listVolumes)); - MOCK_METHOD3(asyncSetSinkNotificationConfiguration, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); - MOCK_METHOD3(asyncSetSourceNotificationConfiguration, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); - MOCK_METHOD2(resyncConnectionState, - am_Error_e(const am_domainID_t domainID, std::vector& listOfExistingConnections)); - - -}; - -} // namespace am - - -#endif /* MOCKROUTINGINTERFACE_H_ */ diff --git a/AudioManagerUtilities/CMakeLists.txt b/AudioManagerUtilities/CMakeLists.txt index 69555fa..f859026 100644 --- a/AudioManagerUtilities/CMakeLists.txt +++ b/AudioManagerUtilities/CMakeLists.txt @@ -15,25 +15,22 @@ # For further information see http://www.genivi.org/. # -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) -PROJECT(AudioManagerUtilities) - -set(AudioManagerUtilities_VERSION_MAJOR 1) -set(AudioManagerUtilities_VERSION_MINOR 0) -set(AudioManagerUtilities_VERSION_PATCH 0) -set(AudioManagerUtilities_VERSION_STRING ${AudioManagerUtilities_VERSION_MAJOR}.${AudioManagerUtilities_VERSION_MINOR}.${AudioManagerUtilities_VERSION_PATCH}) +PROJECT(AudioManagerUtilities LANGUAGES CXX VERSION ${DAEMONVERSION}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -SET(INCLUDE_FOLDER "include") -INCLUDE_DIRECTORIES( - ${INCLUDE_FOLDER} +SET(AUDIOMANAGER_UTILITIES_INCLUDE + ${AUDIOMANAGER_UTILITIES}/include ${AUDIO_INCLUDE_FOLDER} - ${AUDIOMANAGER_INCLUDE_FOLDER} - ${DBUS_INCLUDE_DIRS} ${TCLAP_INCLUDE_DIR} -) + ${AUDIOMANAGER_INCLUDE_FOLDER} + CACHE INTERNAL "AUDIOMANAGER_INCLUDE directories" FORCE) + +SET(AUDIO_MANAGER_UTILITIES_LIBS + ${CMAKE_DL_LIBS} + CACHE INTERNAL "AUDIO_MANAGER_UTILITIES_LIBS libs" FORCE) IF (WITH_SHARED_UTILITIES) SET(LIBRARY_TYPE SHARED) @@ -47,79 +44,117 @@ SET(AUDIO_MANAGER_UTILITIES_SRCS_CXX src/CAmSocketHandler.cpp) if(WITH_SYSTEMD_WATCHDOG) - - pkg_check_modules(SYSTEMD libsystemd>=44) - if (SYSTEMD_FOUND) - message(STATUS "Found libsystemd-daemon, version: ${SYSTEMD_VERSION}") - else (SYSTEMD_FOUND) - message(STATUS "Did not find libsystemd-daemon, using own lib") - endif(SYSTEMD_FOUND) - + pkg_check_modules(SYSTEMD REQUIRED "libsystemd >= 44") + + message(STATUS "Found libsystemd-daemon, version: ${SYSTEMD_VERSION}") + set (AUDIO_MANAGER_UTILITIES_LIBS + ${AUDIO_MANAGER_UTILITIES_LIBS} + ${SYSTEMD_LIBRARIES} + CACHE INTERNAL "AUDIO_MANAGER_UTILITIES_LIBS libs" FORCE) + set(AUDIOMANAGER_UTILITIES_INCLUDE + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${SYSTEMD_INCLUDEDIR}) set (AUDIO_MANAGER_UTILITIES_SRCS_CXX ${AUDIO_MANAGER_UTILITIES_SRCS_CXX} src/CAmWatchdog.cpp) - set (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${SYSTEMD_LIBRARIES}) -endif(WITH_SYSTEMD_WATCHDOG) - - -if (NOT SYSTEMD_FOUND) - set (AUDIO_MANAGER_UTILITIES_SRCS_CXX - ${AUDIO_MANAGER_UTILITIES_SRCS_CXX} - src/sd-daemon.c) -endif (NOT SYSTEMD_FOUND) - - -IF (WITH_DBUS_WRAPPER) - pkg_check_modules (DBUS "dbus-1 >= 1.4") -ENDIF (WITH_DBUS_WRAPPER) -IF (WITH_CAPI_WRAPPER) - FIND_PACKAGE(CommonAPI REQUIRED) -ENDIF (WITH_CAPI_WRAPPER) +endif(WITH_SYSTEMD_WATCHDOG) IF (WITH_DBUS_WRAPPER) - SET (AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DBUS_LIBRARIES}) - SET(AUDIO_MANAGER_UTILITIES_SRCS_CXX + pkg_check_modules (DBUS REQUIRED "dbus-1 >= 1.4") + + set(AUDIOMANAGER_UTILITIES_INCLUDE + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${DBUS_INCLUDE_DIRS} + CACHE INTERNAL "AUDIOMANAGER_INCLUDE directories" FORCE) + + set (AUDIO_MANAGER_UTILITIES_LIBS + ${AUDIO_MANAGER_UTILITIES_LIBS} + ${DBUS_LIBRARIES} + CACHE INTERNAL "AUDIO_MANAGER_UTILITIES_LIBS libs" FORCE) + + set(AUDIO_MANAGER_UTILITIES_SRCS_CXX ${AUDIO_MANAGER_UTILITIES_SRCS_CXX} src/CAmDbusWrapper.cpp) ENDIF (WITH_DBUS_WRAPPER) IF (WITH_CAPI_WRAPPER) - SET(AM_LINK_LIBS - ${AM_LINK_LIBS} - ${DBUS_LIBRARIES} - ${COMMON_API_LIBRARIES} - ${COMMON_API_DBUS_LIBRARIES}) - SET(AUDIO_MANAGER_UTILITIES_SRCS_CXX + pkg_check_modules(COMMONAPI REQUIRED "CommonAPI >= 3.1.5") + + set(AUDIO_MANAGER_UTILITIES_LIBS + ${AUDIO_MANAGER_UTILITIES_LIBS} + ${COMMONAPI_LIBRARIES} + ${COMMONAPI_DBUS_LIBRARIES} + CACHE INTERNAL "AUDIO_MANAGER_UTILITIES_LIBS libs" FORCE) + + set(AUDIO_MANAGER_UTILITIES_SRCS_CXX ${AUDIO_MANAGER_UTILITIES_SRCS_CXX} src/CAmCommonAPIWrapper.cpp) - INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} - ${COMMONAPI_INCLUDE_DIRS}) + + set(AUDIOMANAGER_UTILITIES_INCLUDE + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${COMMONAPI_INCLUDE_DIRS} + CACHE INTERNAL "AUDIOMANAGER_INCLUDE directories" FORCE) ENDIF (WITH_CAPI_WRAPPER) +if(WITH_DLT) + pkg_check_modules(DLT REQUIRED "automotive-dlt >= 2.2.0") + + add_definitions(${DLT_CFLAGS_OTHER}) + + set(AUDIO_MANAGER_UTILITIES_LIBS + ${AUDIO_MANAGER_UTILITIES_LIBS} + ${DLT_LIBRARIES} + CACHE INTERNAL "AUDIO_MANAGER_UTILITIES_LIBS libs" FORCE) + + SET(AUDIOMANAGER_UTILITIES_INCLUDE + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${DLT_LIBRARY_DIRS} + CACHE INTERNAL "AUDIOMANAGER_INCLUDE directories" FORCE) +endif(WITH_DLT) + + +INCLUDE_DIRECTORIES(${AUDIOMANAGER_UTILITIES_INCLUDE}) + ADD_LIBRARY(AudioManagerUtilities ${LIBRARY_TYPE} ${AUDIO_MANAGER_UTILITIES_SRCS_CXX}) -TARGET_LINK_LIBRARIES(AudioManagerUtilities ${AM_LINK_LIBS}) +TARGET_LINK_LIBRARIES(AudioManagerUtilities ${AUDIO_MANAGER_UTILITIES_LIBS}) -set_target_properties(AudioManagerUtilities PROPERTIES VERSION ${AudioManagerUtilities_VERSION_STRING} SOVERSION ${AudioManagerUtilities_VERSION_MAJOR}) +set_target_properties(AudioManagerUtilities PROPERTIES VERSION ${AudioManagerUtilities_VERSION} SOVERSION ${AudioManagerUtilities_VERSION_MAJOR}) IF (WITH_SHARED_UTILITIES) INSTALL(TARGETS AudioManagerUtilities LIBRARY DESTINATION lib PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ COMPONENT bin) - configure_file( ${CMAKE_SOURCE_DIR}/cmake/audiomanagerutilities.pc.in ${CMAKE_BINARY_DIR}/audiomanagerutilities.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/audiomanagerutilities.pc DESTINATION lib/pkgconfig COMPONENT devel) ELSE (WITH_SHARED_UTILITIES) INSTALL(TARGETS AudioManagerUtilities ARCHIVE DESTINATION lib COMPONENT dev) ENDIF (WITH_SHARED_UTILITIES) -INSTALL(DIRECTORY "${AUDIOMANAGER_UTILITIES_INCLUDE}/" - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${LIB_INSTALL_SUFFIX} +configure_file( ${CMAKE_SOURCE_DIR}/cmake/audiomanagerutilities.pc.in ${CMAKE_BINARY_DIR}/audiomanagerutilities.pc @ONLY ) +install(FILES ${CMAKE_BINARY_DIR}/audiomanagerutilities.pc DESTINATION lib/pkgconfig COMPONENT devel) + +configure_package_config_file ( + ${CMAKE_SOURCE_DIR}/cmake/AudioManagerUtilitiesConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerUtilitiesConfig.cmake + INSTALL_DESTINATION lib/${LIB_INSTALL_SUFFIX}/cmake + PATH_VARS AUDIO_INCLUDE_FOLDER ) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerUtilitiesConfigVersion.cmake + VERSION ${DAEMONVERSION} + COMPATIBILITY SameMajorVersion ) + +install( +FILES ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerUtilitiesConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerUtilitiesConfigVersion.cmake +DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/AudioManagerUtilities-${DAEMONVERSION}) + +INSTALL(DIRECTORY "include/" + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${LIB_INSTALL_SUFFIX}/AudioManagerUtilities COMPONENT dev) + +if(WITH_TESTS) + add_subdirectory (test) +endif(WITH_TESTS) diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h index f9a6b01..82328d6 100644 --- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h +++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h @@ -35,10 +35,6 @@ #include "audiomanagerconfig.h" #include "CAmSocketHandler.h" -#if COMMONAPI_VERSION_NUMBER < 300 -#error "CommonAPI versions < 300 are not supported." -#endif - /** * A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects. * It is implemented as singleton and usually instantiated at the beginning with CAmSocketHandler as parameter. diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h index 7e4d2d4..d227929 100644 --- a/AudioManagerUtilities/include/CAmDltWrapper.h +++ b/AudioManagerUtilities/include/CAmDltWrapper.h @@ -131,7 +131,10 @@ public: template void append(const char* value) { #ifdef WITH_DLT - dlt_user_log_write_string(&mDltContextData, value); + if(mEnableNoDLTDebug) + { + dlt_user_log_write_string(&mDltContextData, value); + } #else mDltContextData.buffer << value; #endif @@ -153,7 +156,8 @@ public: "E_ABORTED", "E_WRONG_FORMAT" }; - append(str_error[value]); + if(mEnableNoDLTDebug) + append(str_error[value]); } // Template to print unknown pointer types with their address @@ -188,10 +192,10 @@ 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 + bool mEnableNoDLTDebug; static CAmDltWrapper* mpDLTWrapper; //!< pointer to the wrapper instance static pthread_mutex_t mMutex; diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 5e11fa5..1a988c5 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -441,16 +441,7 @@ private: bool mRecreatePollfds; //!::iterator it(mListActiveTimer.begin()); -// for(;it!=mListActiveTimer.end();++it) -// { -// std::cout<< "Handle " << it->handle << "sec " << it->countdown.tv_sec << "nsec " << it->countdown.tv_nsec< -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Reference implementation of a few systemd related interfaces for - writing daemons. These interfaces are trivial to implement. To - simplify porting we provide this reference implementation. - Applications are welcome to reimplement the algorithms described - here if they do not want to include these two source files. - - The following functionality is provided: - - - Support for logging with log levels on stderr - - File descriptor passing for socket-based activation - - Daemon startup and status notification - - Detection of systemd boots - - You may compile this with -DDISABLE_SYSTEMD to disable systemd - support. This makes all those calls NOPs that are directly related to - systemd (i.e. only sd_is_xxx() will stay useful). - - Since this is drop-in code we don't want any of our symbols to be - exported in any case. Hence we declare hidden visibility for all of - them. - - You may find an up-to-date version of these source files online: - - http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h - http://cgit.freedesktop.org/systemd/systemd/plain/src/sd-daemon.c - - This should compile on non-Linux systems, too, but with the - exception of the sd_is_xxx() calls all functions will become NOPs. - - See sd-daemon(7) for more information. -*/ - -#ifndef _sd_printf_attr_ -#if __GNUC__ >= 4 -#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b))) -#else -#define _sd_printf_attr_(a,b) -#endif -#endif - -/* - Log levels for usage on stderr: - - fprintf(stderr, SD_NOTICE "Hello World!\n"); - - This is similar to printk() usage in the kernel. -*/ -#define SD_EMERG "<0>" /* system is unusable */ -#define SD_ALERT "<1>" /* action must be taken immediately */ -#define SD_CRIT "<2>" /* critical conditions */ -#define SD_ERR "<3>" /* error conditions */ -#define SD_WARNING "<4>" /* warning conditions */ -#define SD_NOTICE "<5>" /* normal but significant condition */ -#define SD_INFO "<6>" /* informational */ -#define SD_DEBUG "<7>" /* debug-level messages */ - -/* The first passed file descriptor is fd 3 */ -#define SD_LISTEN_FDS_START 3 - -/* - Returns how many file descriptors have been passed, or a negative - errno code on failure. Optionally, removes the $LISTEN_FDS and - $LISTEN_PID file descriptors from the environment (recommended, but - problematic in threaded environments). If r is the return value of - this function you'll find the file descriptors passed as fds - SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative - errno style error code on failure. This function call ensures that - the FD_CLOEXEC flag is set for the passed file descriptors, to make - sure they are not passed on to child processes. If FD_CLOEXEC shall - not be set, the caller needs to unset it after this call for all file - descriptors that are used. - - See sd_listen_fds(3) for more information. -*/ -int sd_listen_fds(int unset_environment); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is a FIFO in the file system stored under the - specified path, 0 otherwise. If path is NULL a path name check will - not be done and the call only verifies if the file descriptor - refers to a FIFO. Returns a negative errno style error code on - failure. - - See sd_is_fifo(3) for more information. -*/ -int sd_is_fifo(int fd, const char *path); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is a special character device on the file - system stored under the specified path, 0 otherwise. - If path is NULL a path name check will not be done and the call - only verifies if the file descriptor refers to a special character. - Returns a negative errno style error code on failure. - - See sd_is_special(3) for more information. -*/ -int sd_is_special(int fd, const char *path); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is a socket of the specified family (AF_INET, - ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If - family is 0 a socket family check will not be done. If type is 0 a - socket type check will not be done and the call only verifies if - the file descriptor refers to a socket. If listening is > 0 it is - verified that the socket is in listening mode. (i.e. listen() has - been called) If listening is == 0 it is verified that the socket is - not in listening mode. If listening is < 0 no listening mode check - is done. Returns a negative errno style error code on failure. - - See sd_is_socket(3) for more information. -*/ -int sd_is_socket(int fd, int family, int type, int listening); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is an Internet socket, of the specified family - (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM, - SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version - check is not done. If type is 0 a socket type check will not be - done. If port is 0 a socket port check will not be done. The - listening flag is used the same way as in sd_is_socket(). Returns a - negative errno style error code on failure. - - See sd_is_socket_inet(3) for more information. -*/ -int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is an AF_UNIX socket of the specified type - (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0 - a socket type check will not be done. If path is NULL a socket path - check will not be done. For normal AF_UNIX sockets set length to - 0. For abstract namespace sockets set length to the length of the - socket name (including the initial 0 byte), and pass the full - socket path in path (including the initial 0 byte). The listening - flag is used the same way as in sd_is_socket(). Returns a negative - errno style error code on failure. - - See sd_is_socket_unix(3) for more information. -*/ -int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length); - -/* - Helper call for identifying a passed file descriptor. Returns 1 if - the file descriptor is a POSIX Message Queue of the specified name, - 0 otherwise. If path is NULL a message queue name check is not - done. Returns a negative errno style error code on failure. -*/ -int sd_is_mq(int fd, const char *path); - -/* - Informs systemd about changed daemon state. This takes a number of - newline separated environment-style variable assignments in a - string. The following variables are known: - - READY=1 Tells systemd that daemon startup is finished (only - relevant for services of Type=notify). The passed - argument is a boolean "1" or "0". Since there is - little value in signaling non-readiness the only - value daemons should send is "READY=1". - - STATUS=... Passes a single-line status string back to systemd - that describes the daemon state. This is free-from - and can be used for various purposes: general state - feedback, fsck-like programs could pass completion - percentages and failing programs could pass a human - readable error message. Example: "STATUS=Completed - 66% of file system check..." - - ERRNO=... If a daemon fails, the errno-style error code, - formatted as string. Example: "ERRNO=2" for ENOENT. - - BUSERROR=... If a daemon fails, the D-Bus error-style error - code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut" - - MAINPID=... The main pid of a daemon, in case systemd did not - fork off the process itself. Example: "MAINPID=4711" - - WATCHDOG=1 Tells systemd to update the watchdog timestamp. - Services using this feature should do this in - regular intervals. A watchdog framework can use the - timestamps to detect failed services. - - Daemons can choose to send additional variables. However, it is - recommended to prefix variable names not listed above with X_. - - Returns a negative errno-style error code on failure. Returns > 0 - if systemd could be notified, 0 if it couldn't possibly because - systemd is not running. - - Example: When a daemon finished starting up, it could issue this - call to notify systemd about it: - - sd_notify(0, "READY=1"); - - See sd_notifyf() for more complete examples. - - See sd_notify(3) for more information. -*/ -int sd_notify(int unset_environment, const char *state); - -/* - Similar to sd_notify() but takes a format string. - - Example 1: A daemon could send the following after initialization: - - sd_notifyf(0, "READY=1\n" - "STATUS=Processing requests...\n" - "MAINPID=%lu", - (unsigned long) getpid()); - - Example 2: A daemon could send the following shortly before - exiting, on failure: - - sd_notifyf(0, "STATUS=Failed to start up: %s\n" - "ERRNO=%i", - strerror(errno), - errno); - - See sd_notifyf(3) for more information. -*/ -int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3); - -/* - Returns > 0 if the system was booted with systemd. Returns < 0 on - error. Returns 0 if the system was not booted with systemd. Note - that all of the functions above handle non-systemd boots just - fine. You should NOT protect them with a call to this function. Also - note that this function checks whether the system, not the user - session is controlled by systemd. However the functions above work - for both user and system services. - - See sd_booted(3) for more information. -*/ -int sd_booted(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp index 33baa46..3b10ef4 100644 --- a/AudioManagerUtilities/src/CAmDltWrapper.cpp +++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp @@ -48,7 +48,10 @@ CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug) void CAmDltWrapper::unregisterContext(DltContext & handle) { #ifdef WITH_DLT - dlt_unregister_context(&handle); + if (mEnableNoDLTDebug) + { + dlt_unregister_context(&handle); + } #else (void) handle; #endif @@ -57,16 +60,17 @@ void CAmDltWrapper::unregisterContext(DltContext & handle) void CAmDltWrapper::deinit() { #ifdef WITH_DLT - unregisterContext(mDltContext); + if (mEnableNoDLTDebug) + { + unregisterContext(mDltContext); + } #endif } -CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) : -#ifndef WITH_DLT - mEnableNoDLTDebug(enableNoDLTDebug), -#endif +CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug=true) : mDltContext(), // - mDltContextData() + mDltContextData(), // + mEnableNoDLTDebug(enableNoDLTDebug) { (void) enableNoDLTDebug; #ifndef WITH_DLT @@ -77,9 +81,12 @@ CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) : 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"); + if (mEnableNoDLTDebug) + { + dlt_register_app(appid, description); + //register a default context + dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass"); + } #else (void) appid; (void) description; @@ -89,7 +96,10 @@ void CAmDltWrapper::registerApp(const char *appid, const char *description) void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description) { #ifdef WITH_DLT - dlt_register_context(&handle, contextid, description); + if (mEnableNoDLTDebug) + { + dlt_register_context(&handle, contextid, description); + } #else strncpy(handle.contextID,contextid,4); @@ -115,7 +125,10 @@ void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, c const DltLogLevelType level, const DltTraceStatusType status) { #ifdef WITH_DLT - dlt_register_context_ll_ts(&handle, contextid, description, level, status); + if (mEnableNoDLTDebug) + { + dlt_register_context_ll_ts(&handle, contextid, description, level, status); + } #else strncpy(handle.contextID,contextid,4); @@ -144,14 +157,15 @@ bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context) if (!context) context = &mDltContext; #ifdef WITH_DLT - if (dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0) + if (mEnableNoDLTDebug) + if(dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0) #else if((mEnableNoDLTDebug == false) || (loglevel > context->log_level_user)) #endif - { - pthread_mutex_unlock(&mMutex); - return false; - } + { + pthread_mutex_unlock(&mMutex); + return false; + } #ifndef WITH_DLT std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t"; #endif @@ -161,7 +175,10 @@ bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context) void CAmDltWrapper::send() { #ifdef WITH_DLT - dlt_user_log_write_finish(&mDltContextData); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_finish(&mDltContextData); + } #else if(mEnableNoDLTDebug) std::cout << mDltContextData.buffer.str().c_str() << std::endl; @@ -175,7 +192,10 @@ void CAmDltWrapper::send() void CAmDltWrapper::append(const int8_t value) { #ifdef WITH_DLT - dlt_user_log_write_int8(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_int8(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -184,7 +204,10 @@ void CAmDltWrapper::append(const int8_t value) void CAmDltWrapper::append(const uint8_t value) { #ifdef WITH_DLT - dlt_user_log_write_uint8(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_uint8(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -193,7 +216,10 @@ void CAmDltWrapper::append(const uint8_t value) void CAmDltWrapper::append(const int16_t value) { #ifdef WITH_DLT - dlt_user_log_write_int16(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_int16(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -202,7 +228,10 @@ void CAmDltWrapper::append(const int16_t value) void CAmDltWrapper::append(const uint16_t value) { #ifdef WITH_DLT - dlt_user_log_write_uint16(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_uint16(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -211,7 +240,10 @@ void CAmDltWrapper::append(const uint16_t value) void CAmDltWrapper::append(const int32_t value) { #ifdef WITH_DLT - dlt_user_log_write_int32(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_int32(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -220,7 +252,10 @@ void CAmDltWrapper::append(const int32_t value) void CAmDltWrapper::append(const uint32_t value) { #ifdef WITH_DLT - dlt_user_log_write_uint32(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_uint32(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -228,13 +263,17 @@ void CAmDltWrapper::append(const uint32_t value) void CAmDltWrapper::append(const std::string& value) { - append(value.c_str()); + if (mEnableNoDLTDebug) + append(value.c_str()); } void CAmDltWrapper::append(const bool value) { #ifdef WITH_DLT - dlt_user_log_write_bool(&mDltContextData, static_cast(value)); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_bool(&mDltContextData, static_cast(value)); + } #else appendNoDLT(value); #endif @@ -243,7 +282,10 @@ void CAmDltWrapper::append(const bool value) void CAmDltWrapper::append(const int64_t value) { #ifdef WITH_DLT - dlt_user_log_write_int64(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_int64(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -252,7 +294,10 @@ void CAmDltWrapper::append(const int64_t value) void CAmDltWrapper::append(const uint64_t value) { #ifdef WITH_DLT - dlt_user_log_write_uint64(&mDltContextData, value); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_uint64(&mDltContextData, value); + } #else appendNoDLT(value); #endif @@ -261,7 +306,10 @@ void CAmDltWrapper::append(const uint64_t value) void CAmDltWrapper::append(const std::vector & data) { #ifdef WITH_DLT - dlt_user_log_write_raw(&mDltContextData,(void*)data.data(),data.size()); + if (mEnableNoDLTDebug) + { + dlt_user_log_write_raw(&mDltContextData,(void*)data.data(),data.size()); + } #else mDltContextData.buffer << data.data(); #endif @@ -281,7 +329,7 @@ void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug) CAmDltWrapper::~CAmDltWrapper() { - if (mpDLTWrapper) + if (mpDLTWrapper && mEnableNoDLTDebug) { mpDLTWrapper->unregisterContext(mDltContext); delete mpDLTWrapper; diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp index 4b113fa..8947a5a 100644 --- a/AudioManagerUtilities/src/CAmSocketHandler.cpp +++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp @@ -22,7 +22,6 @@ */ #include "CAmSocketHandler.h" -//#include #include #include #include @@ -113,7 +112,7 @@ void CAmSocketHandler::start_listenting() else { logError("SocketHandler::start_listenting ppoll returned with error", errno); - exit(0); + throw std::runtime_error(std::string("SocketHandler::start_listenting ppoll returned with error.")); } } diff --git a/AudioManagerUtilities/src/CAmWatchdog.cpp b/AudioManagerUtilities/src/CAmWatchdog.cpp index db65095..9de2a85 100755 --- a/AudioManagerUtilities/src/CAmWatchdog.cpp +++ b/AudioManagerUtilities/src/CAmWatchdog.cpp @@ -27,12 +27,7 @@ #include #include "audiomanagerconfig.h" #include "CAmDltWrapper.h" - -#ifdef SYSTEMD_FOUND - #include -#else - #include "sd-daemon.h" -#endif +#include namespace am { @@ -61,7 +56,7 @@ CAmWatchdog::CAmWatchdog(CAmSocketHandler* CAmSocketHandler) : timeout.tv_sec = (watchdogTimeout / 2) / 1000000; timeout.tv_nsec = ((watchdogTimeout / 2) % 1000000) * 1000; logInfo("CAmWatchdog::CAmWatchdog setting watchdog timeout:", watchdogTimeout, "us. Notification set to:", - timeout.tv_sec, "sec and", timeout.tv_nsec, "ns"); + (int)timeout.tv_sec, "sec and", (int)timeout.tv_nsec, "ns"); //add the timer here if (mpCAmSocketHandler->addTimer(timeout, &TimerCallback, mHandle, NULL)) diff --git a/AudioManagerUtilities/src/sd-daemon.c b/AudioManagerUtilities/src/sd-daemon.c deleted file mode 100644 index cf35148..0000000 --- a/AudioManagerUtilities/src/sd-daemon.c +++ /dev/null @@ -1,534 +0,0 @@ -/** - * SPDX license identifier: MIT - */ - -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - Copyright 2010 Lennart Poettering - - 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 _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#ifdef __BIONIC__ -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(__linux__) -#include -#endif - -#include "sd-daemon.h" - -#if (__GNUC__ >= 4) -#ifdef SD_EXPORT_SYMBOLS -/* Export symbols */ -#define _sd_export_ __attribute__ ((visibility("default"))) -#else -/* Don't export the symbols */ -#define _sd_export_ __attribute__ ((visibility("hidden"))) -#endif -#else -#define _sd_export_ -#endif - -_sd_export_ int sd_listen_fds(int unset_environment) { - -#if defined(DISABLE_SYSTEMD) || !defined(__linux__) - return 0; -#else - int r, fd; - const char *e; - char *p = NULL; - unsigned long l; - - if (!(e = getenv("LISTEN_PID"))) { - r = 0; - goto finish; - } - - errno = 0; - l = strtoul(e, &p, 10); - - if (errno != 0) { - r = -errno; - goto finish; - } - - if (!p || *p || l <= 0) { - r = -EINVAL; - goto finish; - } - - /* Is this for us? */ - if (getpid() != (pid_t) l) { - r = 0; - goto finish; - } - - if (!(e = getenv("LISTEN_FDS"))) { - r = 0; - goto finish; - } - - errno = 0; - l = strtoul(e, &p, 10); - - if (errno != 0) { - r = -errno; - goto finish; - } - - if (!p || *p) { - r = -EINVAL; - goto finish; - } - - for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) { - int flags; - - if ((flags = fcntl(fd, F_GETFD)) < 0) { - r = -errno; - goto finish; - } - - if (flags & FD_CLOEXEC) - continue; - - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { - r = -errno; - goto finish; - } - } - - r = (int) l; - -finish: - if (unset_environment) { - unsetenv("LISTEN_PID"); - unsetenv("LISTEN_FDS"); - } - - return r; -#endif -} - -_sd_export_ int sd_is_fifo(int fd, const char *path) { - struct stat st_fd; - - if (fd < 0) - return -EINVAL; - - memset(&st_fd, 0, sizeof(st_fd)); - if (fstat(fd, &st_fd) < 0) - return -errno; - - if (!S_ISFIFO(st_fd.st_mode)) - return 0; - - if (path) { - struct stat st_path; - - memset(&st_path, 0, sizeof(st_path)); - if (stat(path, &st_path) < 0) { - - if (errno == ENOENT || errno == ENOTDIR) - return 0; - - return -errno; - } - - return - st_path.st_dev == st_fd.st_dev && - st_path.st_ino == st_fd.st_ino; - } - - return 1; -} - -_sd_export_ int sd_is_special(int fd, const char *path) { - struct stat st_fd; - - if (fd < 0) - return -EINVAL; - - if (fstat(fd, &st_fd) < 0) - return -errno; - - if (!S_ISREG(st_fd.st_mode) && !S_ISCHR(st_fd.st_mode)) - return 0; - - if (path) { - struct stat st_path; - - if (stat(path, &st_path) < 0) { - - if (errno == ENOENT || errno == ENOTDIR) - return 0; - - return -errno; - } - - if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode)) - return - st_path.st_dev == st_fd.st_dev && - st_path.st_ino == st_fd.st_ino; - else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode)) - return st_path.st_rdev == st_fd.st_rdev; - else - return 0; - } - - return 1; -} - -static int sd_is_socket_internal(int fd, int type, int listening) { - struct stat st_fd; - - if (fd < 0 || type < 0) - return -EINVAL; - - if (fstat(fd, &st_fd) < 0) - return -errno; - - if (!S_ISSOCK(st_fd.st_mode)) - return 0; - - if (type != 0) { - int other_type = 0; - socklen_t l = sizeof(other_type); - - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0) - return -errno; - - if (l != sizeof(other_type)) - return -EINVAL; - - if (other_type != type) - return 0; - } - - if (listening >= 0) { - int accepting = 0; - socklen_t l = sizeof(accepting); - - if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0) - return -errno; - - if (l != sizeof(accepting)) - return -EINVAL; - - if (!accepting != !listening) - return 0; - } - - return 1; -} - -union sockaddr_union { - struct sockaddr sa; - struct sockaddr_in in4; - struct sockaddr_in6 in6; - struct sockaddr_un un; - struct sockaddr_storage storage; -}; - -_sd_export_ int sd_is_socket(int fd, int family, int type, int listening) { - int r; - - if (family < 0) - return -EINVAL; - - if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) - return r; - - if (family > 0) { - union sockaddr_union sockaddr; - socklen_t l; - - memset(&sockaddr, 0, sizeof(sockaddr)); - l = sizeof(sockaddr); - - if (getsockname(fd, &sockaddr.sa, &l) < 0) - return -errno; - - if (l < sizeof(sa_family_t)) - return -EINVAL; - - return sockaddr.sa.sa_family == family; - } - - return 1; -} - -_sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) { - union sockaddr_union sockaddr; - socklen_t l; - int r; - - if (family != 0 && family != AF_INET && family != AF_INET6) - return -EINVAL; - - if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) - return r; - - memset(&sockaddr, 0, sizeof(sockaddr)); - l = sizeof(sockaddr); - - if (getsockname(fd, &sockaddr.sa, &l) < 0) - return -errno; - - if (l < sizeof(sa_family_t)) - return -EINVAL; - - if (sockaddr.sa.sa_family != AF_INET && - sockaddr.sa.sa_family != AF_INET6) - return 0; - - if (family > 0) - if (sockaddr.sa.sa_family != family) - return 0; - - if (port > 0) { - if (sockaddr.sa.sa_family == AF_INET) { - if (l < sizeof(struct sockaddr_in)) - return -EINVAL; - - return htons(port) == sockaddr.in4.sin_port; - } else { - if (l < sizeof(struct sockaddr_in6)) - return -EINVAL; - - return htons(port) == sockaddr.in6.sin6_port; - } - } - - return 1; -} - -_sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) { - union sockaddr_union sockaddr; - socklen_t l; - int r; - - if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) - return r; - - memset(&sockaddr, 0, sizeof(sockaddr)); - l = sizeof(sockaddr); - - if (getsockname(fd, &sockaddr.sa, &l) < 0) - return -errno; - - if (l < sizeof(sa_family_t)) - return -EINVAL; - - if (sockaddr.sa.sa_family != AF_UNIX) - return 0; - - if (path) { - if (length <= 0) - length = strlen(path); - - if (length <= 0) - /* Unnamed socket */ - return l == offsetof(struct sockaddr_un, sun_path); - - if (path[0]) - /* Normal path socket */ - return - (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) && - memcmp(path, sockaddr.un.sun_path, length+1) == 0; - else - /* Abstract namespace socket */ - return - (l == offsetof(struct sockaddr_un, sun_path) + length) && - memcmp(path, sockaddr.un.sun_path, length) == 0; - } - - return 1; -} - -_sd_export_ int sd_is_mq(int fd, const char *path) { -#if !defined(__linux__) - return 0; -#else - struct mq_attr attr; - - if (fd < 0) - return -EINVAL; - - if (mq_getattr(fd, &attr) < 0) - return -errno; - - if (path) { - char fpath[PATH_MAX]; - struct stat a, b; - - if (path[0] != '/') - return -EINVAL; - - if (fstat(fd, &a) < 0) - return -errno; - - strncpy(stpcpy(fpath, "/dev/mqueue"), path, sizeof(fpath) - 12); - fpath[sizeof(fpath)-1] = 0; - - if (stat(fpath, &b) < 0) - return -errno; - - if (a.st_dev != b.st_dev || - a.st_ino != b.st_ino) - return 0; - } - - return 1; -#endif -} - -_sd_export_ int sd_notify(int unset_environment, const char *state) { -#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC) - return 0; -#else - int fd = -1, r; - struct msghdr msghdr; - struct iovec iovec; - union sockaddr_union sockaddr; - const char *e; - - if (!state) { - r = -EINVAL; - goto finish; - } - - if (!(e = getenv("NOTIFY_SOCKET"))) - return 0; - - /* Must be an abstract socket, or an absolute path */ - if ((e[0] != '@' && e[0] != '/') || e[1] == 0) { - r = -EINVAL; - goto finish; - } - - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) { - r = -errno; - goto finish; - } - - memset(&sockaddr, 0, sizeof(sockaddr)); - sockaddr.sa.sa_family = AF_UNIX; - strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path)); - - if (sockaddr.un.sun_path[0] == '@') - sockaddr.un.sun_path[0] = 0; - - memset(&iovec, 0, sizeof(iovec)); - iovec.iov_base = (char*) state; - iovec.iov_len = strlen(state); - - memset(&msghdr, 0, sizeof(msghdr)); - msghdr.msg_name = &sockaddr; - msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e); - - if (msghdr.msg_namelen > sizeof(struct sockaddr_un)) - msghdr.msg_namelen = sizeof(struct sockaddr_un); - - msghdr.msg_iov = &iovec; - msghdr.msg_iovlen = 1; - - if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) { - r = -errno; - goto finish; - } - - r = 1; - -finish: - if (unset_environment) - unsetenv("NOTIFY_SOCKET"); - - if (fd >= 0) - close(fd); - - return r; -#endif -} - -_sd_export_ int sd_notifyf(int unset_environment, const char *format, ...) { -#if defined(DISABLE_SYSTEMD) || !defined(__linux__) - return 0; -#else - va_list ap; - char *p = NULL; - int r; - - va_start(ap, format); - r = vasprintf(&p, format, ap); - va_end(ap); - - if (r < 0 || !p) - return -ENOMEM; - - r = sd_notify(unset_environment, p); - free(p); - - return r; -#endif -} - -_sd_export_ int sd_booted(void) { -#if defined(DISABLE_SYSTEMD) || !defined(__linux__) - return 0; -#else - - struct stat a, b; - - /* We simply test whether the systemd cgroup hierarchy is - * mounted */ - - if (lstat("/sys/fs/cgroup", &a) < 0) - return 0; - - if (lstat("/sys/fs/cgroup/systemd", &b) < 0) - return 0; - - return a.st_dev != b.st_dev; -#endif -} diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp new file mode 100644 index 0000000..50e2aa9 --- /dev/null +++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp @@ -0,0 +1,357 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmSocketHandlerTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "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; + mSocketHandler->updateTimer(handle,timeout); +} + +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 = 011110000; + timeout.tv_sec = 1; + mSocketHandler->updateTimer(handle,timeout); +} + +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,playWithTimers) +{ + CAmSocketHandler myHandler; + CAmTimerCb testCallback(&myHandler); + timespec timeoutTime, timeout2, timeout3, timeout4; + timeoutTime.tv_sec = 1; + timeoutTime.tv_nsec = 02223234; + timeout2.tv_nsec = 333000; + timeout2.tv_sec = 0; + timeout3.tv_nsec = 333; + timeout3.tv_sec = 3; + timeout4.tv_nsec = 0; + timeout4.tv_sec = 20; + sh_timerHandle_t handle; + myHandler.addTimer(timeoutTime, &testCallback.pTimer1Callback, handle, NULL); + myHandler.addTimer(timeout2, &testCallback.pTimer2Callback, handle, NULL); + myHandler.addTimer(timeout3, &testCallback.pTimer3Callback, handle, NULL); + myHandler.addTimer(timeout4, &testCallback.pTimer4Callback, handle, NULL); + myHandler.start_listenting(); + +} + + +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); +} + + +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, 0); + 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/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h new file mode 100644 index 0000000..95e5446 --- /dev/null +++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h @@ -0,0 +1,87 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef SOCKETHANDLERTEST_H_ +#define SOCKETHANDLERTEST_H_ + +#define WITH_DLT + +#include "gtest/gtest.h" +#include +#include "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/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt b/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt new file mode 100644 index 0000000..2a3b9d8 --- /dev/null +++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmSocketHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${GMOCK_INCLUDE_DIRS} +) + + +file(GLOB Socket_SRCS_CXX + "*.cpp" +) + +ADD_EXECUTABLE(AmSocketHandlerTest ${Socket_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmSocketHandlerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerUtilities +) + +ADD_TEST(AmSocketHandlerTest AmSocketHandlerTest ${Socket_SRCS_CXX}) + +ADD_DEPENDENCIES(AmSocketHandlerTest AudioManagerUtilities) + +INSTALL(TARGETS AmSocketHandlerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + + diff --git a/AudioManagerUtilities/test/CMakeLists.txt b/AudioManagerUtilities/test/CMakeLists.txt new file mode 100644 index 0000000..fb55831 --- /dev/null +++ b/AudioManagerUtilities/test/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory (AmSocketHandlerTest) + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c0a238..b977b76 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,24 +16,19 @@ # -cmake_minimum_required(VERSION 2.8.8) - -project(AudioManagerDeamon) +cmake_minimum_required(VERSION 3.0) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) +include ( MacroVersionFromGit ) + +project(AudioManager LANGUAGES CXX VERSION ${DAEMONVERSION}) include ( CMakeDependentOption ) -include ( MacroVersionFromGit ) include ( MacroInterfaceVersions ) include ( CMakePackageConfigHelpers ) include ( GNUInstallDirs ) - -if (NOT ${CMAKE_TOOLCHAIN_FILE} EQUAL "") - message(STATUS "Using CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'" ) -endif (NOT ${CMAKE_TOOLCHAIN_FILE} EQUAL "") - +include ( CTest ) find_package(PkgConfig) -find_package(CommonAPI) option( WITH_TESTS "Build together with all available unitTest" ON ) @@ -53,9 +48,6 @@ option( WITH_TELNET option ( WITH_SYSTEMD_WATCHDOG "Build with systemD support & watchdog" OFF) -option ( USE_BUILD_LIBS - "Build with default library path = build path" ON) - option ( GLIB_DBUS_TYPES_TOLERANT "Build dbus with tolerance towards glib 16bit/32bit handling" ON) @@ -66,11 +58,12 @@ option ( WITH_DBUS_WRAPPER "Build with Dbus wrapper" OFF) option ( WITH_SHARED_UTILITIES - "Build audio manager utilities as dynamic library" OFF) - -option ( WITH_DATABASE_STORAGE - "Build with sqlite as in memory storage" OFF) - + "Build audio manager utilities as dynamic library" OFF) + +option ( WITH_SHARED_CORE + "Build audio manager core as dynamic library" OFF) + + set(DBUS_SERVICE_PREFIX "org.genivi.audiomanager" CACHE PROPERTY "The dbus service prefix for the AM - only changable for legacy dbus") @@ -86,32 +79,32 @@ set(MAX_TELNETCONNECTIONS 3 set(DYNAMIC_ID_BOUNDARY 100 CACHE INTEGER "The ID boundary between static and dynamic ID ranges") -set(PLUGINS_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/plugins - CACHE STRINGS "The output path of the plugins") - set(LIB_INSTALL_SUFFIX "audiomanager" CACHE STRINGS "The suffix used for installation of the plugins") -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin - CACHE STRINGS "The binary will be placed here") - -set(TEST_EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/tests - CACHE STRINGS "The test binaries will be placed here") - -set(TEST_EXECUTABLE_INSTALL_PATH "~/tests" +set(TEST_EXECUTABLE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin CACHE STRINGS "The test binaries will be installed here") -set(DOC_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/doc +set(DOC_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/doc/AudioManager CACHE STRINGS "The doxygen documentation will be placed here") set(AM_SHARE_FOLDER ${CMAKE_INSTALL_PREFIX}/share/audiomanager CACHE STRINGS "The share folder for the AM. Some DBus xmls will be placed here and so on") +set(AM_MAP_CAPACITY 10 + CACHE INTEGER "Number of preallocations for datastorage") + +set(AM_MAX_CONNECTIONS 0x1000 + CACHE INTEGER "Number of max connections before rollover") + +set(AM_MAX_MAIN_CONNECTIONS 0x1000 + CACHE INTEGER "Number of max Mainconnections before rollover") + set(AUDIOMANAGER_INCLUDE_FOLDER ${CMAKE_BINARY_DIR}/include) set(AUDIO_INCLUDE_FOLDER ${CMAKE_SOURCE_DIR}/include) set(AUDIOMANAGER_UTILITIES ${CMAKE_SOURCE_DIR}/AudioManagerUtilities) -set(AUDIOMANAGER_UTILITIES_INCLUDE ${AUDIOMANAGER_UTILITIES}/include) -set(AUDIOMANAGER_UTILITIES_SRC ${AUDIOMANAGER_UTILITIES}/src) +set(AUDIOMANAGER_CORE ${CMAKE_SOURCE_DIR}/AudioManagerCore) +set(AUDIOMANAGER_CORE_INCLUDE ${AUDIOMANAGER_CORE}/include) set(DOXY_PROTOTYPE ${CMAKE_SOURCE_DIR}/cmake/DoxyFile.in) set(DOXY_FILE ${CMAKE_CURRENT_BINARY_DIR}/DoxyFile) set(AUDIOMANAGER_DAEMON_FOLDER ${CMAKE_SOURCE_DIR}/AudioManagerDaemon) @@ -121,80 +114,65 @@ set(TCLAP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/tclap-1.2.1/include) GET_COMMAND_INTERFACE_VERSION(${AUDIO_INCLUDE_FOLDER}) GET_ROUTING_INTERFACE_VERSION(${AUDIO_INCLUDE_FOLDER}) GET_CONTROL_INTERFACE_VERSION(${AUDIO_INCLUDE_FOLDER}) -message( STATUS "CommandInterface version: ${LIB_COMMAND_INTERFACE_VERSION}") -message( STATUS "ControlInterface version: ${LIB_CONTROL_INTERFACE_VERSION}") -message( STATUS "RoutingInterface version: ${LIB_ROUTING_INTERFACE_VERSION}") - -if(USE_BUILD_LIBS) - if(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) - set(DEFAULT_PLUGIN_COMMAND_DIR "${PLUGINS_OUTPUT_PATH}/command") - endif(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) - if(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) - set(DEFAULT_PLUGIN_ROUTING_DIR "${PLUGINS_OUTPUT_PATH}/routing") - endif(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) - if(NOT DEFINED CONTROLLER_PLUGIN) - set(CONTROLLER_PLUGIN "${PLUGINS_OUTPUT_PATH}/control/libPluginControlInterface.so") - endif(NOT DEFINED CONTROLLER_PLUGIN) -else(USE_BUILD_LIBS) - if(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) - set(DEFAULT_PLUGIN_COMMAND_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/command") - endif(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) - if(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) - set(DEFAULT_PLUGIN_ROUTING_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/routing") - endif(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) - if(NOT DEFINED CONTROLLER_PLUGIN) - set(CONTROLLER_PLUGIN "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/control/libPluginControlInterface.so") - endif(NOT DEFINED CONTROLLER_PLUGIN) -endif(USE_BUILD_LIBS) - - -if(USE_BUILD_LIBS) - execute_process(COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/bin") -endif(USE_BUILD_LIBS) - -if(WITH_DLT) - pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) - add_definitions(${DLT_CFLAGS_OTHER}) - include_directories(${DLT_INCLUDE_DIRS}) - link_directories(${DLT_LIBRARY_DIRS}) -endif(WITH_DLT) -if(WITH_TESTS) - add_subdirectory(googleMock) - set(GMOCK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/googleMock/include") - set(GOOGLE_TEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/googleMock/gtest/include") -endif(WITH_TESTS) +if(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) + set(DEFAULT_PLUGIN_COMMAND_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/command") +endif(NOT DEFINED DEFAULT_PLUGIN_COMMAND_DIR) +if(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) + set(DEFAULT_PLUGIN_ROUTING_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/routing") +endif(NOT DEFINED DEFAULT_PLUGIN_ROUTING_DIR) +if(NOT DEFINED CONTROLLER_PLUGIN_DIR) + set(CONTROLLER_PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/control") +endif(NOT DEFINED CONTROLLER_PLUGIN_DIR) ##global build flags set(CPACK_RPM_COMPONENT_INSTALL ON) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -rdynamic -Wno-variadic-macros") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -pedantic -rdynamic -Wno-variadic-macros") set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -DDEBUG") set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2 -DNDEBUG") +if(WITH_TESTS) + #check if we can find the google stuff + pkg_check_modules (GTEST "gtest >= 1.6.0") + pkg_check_modules (GMOCK "gmock >= 1.6.0") + if (NOT(${GTEST_FOUND} AND ${GMOCK_FOUND})) + message (STATUS "Building and installing with shipped sources") + add_subdirectory(googleMock) + set(GMOCK_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/googleMock/include") + set(GTEST_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/googleMock/gtest/include") + set(GTEST_LIBRARIES gtest gtest_main) + set(GMOCK_LIBRARIES gmock gmock_main) + configure_file( ${CMAKE_SOURCE_DIR}/cmake/gtest.pc.in ${CMAKE_BINARY_DIR}/gtest.pc @ONLY ) + configure_file( ${CMAKE_SOURCE_DIR}/cmake/gmock.pc.in ${CMAKE_BINARY_DIR}/gmock.pc @ONLY ) + install(FILES ${CMAKE_BINARY_DIR}/gmock.pc ${CMAKE_BINARY_DIR}/gtest.pc DESTINATION lib/pkgconfig COMPONENT devel) + endif (NOT(${GTEST_FOUND} AND ${GMOCK_FOUND})) +endif(WITH_TESTS) + configure_package_config_file ( - ${CMAKE_SOURCE_DIR}/cmake/audiomanagerConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/audiomanagerConfig.cmake + ${CMAKE_SOURCE_DIR}/cmake/AudioManagerConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerConfig.cmake INSTALL_DESTINATION lib/${LIB_INSTALL_SUFFIX}/cmake PATH_VARS AUDIO_INCLUDE_FOLDER ) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/AudioManagerConfigVersion.cmake VERSION ${DAEMONVERSION} COMPATIBILITY SameMajorVersion ) - -add_subdirectory (AudioManagerDaemon) -add_subdirectory (AudioManagerUtilities) -if(EXISTS "${CMAKE_SOURCE_DIR}/Plugins/") - add_subdirectory (${CMAKE_SOURCE_DIR}/Plugins) -endif(EXISTS "${CMAKE_SOURCE_DIR}/Plugins/") - -configure_file( ${CMAKE_SOURCE_DIR}/AudioManagerDaemon/docx/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/DoxyFile ) +configure_file( ${CMAKE_SOURCE_DIR}/docx/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/DoxyFile ) configure_file( ${CMAKE_SOURCE_DIR}/cmake/config.cmake.in ${CMAKE_BINARY_DIR}/include/audiomanagerconfig.h ) configure_file( ${CMAKE_SOURCE_DIR}/cmake/audiomanager.pc.in ${CMAKE_BINARY_DIR}/audiomanager.pc @ONLY ) + +add_subdirectory (AudioManagerUtilities) +add_subdirectory (AudioManagerCore) +add_subdirectory (AudioManagerDaemon) -install(FILES ${CMAKE_BINARY_DIR}/audiomanager.pc DESTINATION lib/pkgconfig COMPONENT devel) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/audiomanagerConfig.cmake - DESTINATION lib/${LIB_INSTALL_SUFFIX}/cmake - COMPONENT dev) + +install( + FILES ${CMAKE_BINARY_DIR}/AudioManagerConfig.cmake + ${CMAKE_BINARY_DIR}/AudioManagerConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/AudioManager-${DAEMONVERSION} +) + +install(FILES ${CMAKE_BINARY_DIR}/audiomanager.pc DESTINATION lib/pkgconfig COMPONENT devel) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/audiomanagerconfig.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${LIB_INSTALL_SUFFIX} COMPONENT dev) @@ -211,29 +189,48 @@ if(WITH_DOCUMENTATION) COMMAND ${DOXYGEN_EXECUTABLE} ${DOC_OUTPUT_PATH}/Doxyfile WORKING_DIRECTORY ${DOC_OUTPUT_PATH} SOURCES ${CMAKE_SOURCE_DIR} ${DOC_OUTPUT_PATH}/Doxyfile ) + find_program(ASCIIDOC asciidoc asciidoc.py) + + if (ASCIIDOC_FOUND) + execute_process(COMMAND ${ASCIIDOC} -o ${DOC_OUTPUT_PATH}/html/README.html ${CMAKE_SOURCE_DIR}/README ) + endif(ASCIIDOC_FOUND) + install (DIRECTORY ${DOC_OUTPUT_PATH}/ DESTINATION "${CMAKE_INSTALL_DOCDIR}" PATTERN "Doxyfile" EXCLUDE PATTERN "def" EXCLUDE) endif(WITH_DOCUMENTATION) -SET(CMAKE_INSTALL_CONFIG_NAME "RelWithDebInfo") - -add_custom_target(bin-install - COMMAND - "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bin - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" -) - -add_custom_target(dev-install - COMMAND - "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=dev - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" -) - -add_custom_target(test-install - COMMAND - "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=tests - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" -) +message(STATUS) +message(STATUS "${PROJECT_NAME} Configuration:") +message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") +message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") +message(STATUS "BUILD_DOCUMENTATION = ${WITH_DOCUMENTATION}") +message(STATUS "WITH_TESTS = ${WITH_TESTS}") +message(STATUS "WITH_DLT = ${WITH_DLT}") +message(STATUS "WITH_TESTS = ${WITH_TESTS}") +message(STATUS "WITH_TELNET = ${WITH_TELNET}") +message(STATUS "WITH_SYSTEMD_WATCHDOG = ${WITH_SYSTEMD_WATCHDOG}") +message(STATUS "WITH_CAPI_WRAPPER = ${WITH_CAPI_WRAPPER}") +message(STATUS "WITH_DBUS_WRAPPER = ${WITH_DBUS_WRAPPER}") +message(STATUS "WITH_SHARED_UTILITIES = ${WITH_SHARED_UTILITIES}") +message(STATUS "WITH_SHARED_CORE = ${WITH_SHARED_CORE}") +message(STATUS "DYNAMIC_ID_BOUNDARY = ${DYNAMIC_ID_BOUNDARY}") +message(STATUS "LIB_INSTALL_SUFFIX = ${LIB_INSTALL_SUFFIX}") +message(STATUS "TEST_EXECUTABLE_INSTALL_PATH = ${TEST_EXECUTABLE_INSTALL_PATH}") +message(STATUS "DEFAULT_PLUGIN_COMMAND_DIR = ${DEFAULT_PLUGIN_COMMAND_DIR}") +message(STATUS "DEFAULT_PLUGIN_ROUTING_DIR = ${DEFAULT_PLUGIN_ROUTING_DIR}") +message(STATUS "CONTROLLER_PLUGIN_DIR = ${CONTROLLER_PLUGIN_DIR}") +message(STATUS "AM_SHARE_FOLDER = ${AM_SHARE_FOLDER}") +message(STATUS "AM_MAP_CAPACITY = ${AM_MAP_CAPACITY}") +message(STATUS "AM_MAX_CONNECTIONS = ${AM_MAX_CONNECTIONS}") +message(STATUS "AM_MAX_MAIN_CONNECTIONS = ${AM_MAX_MAIN_CONNECTIONS}") +message(STATUS "BUILD_TESTING = ${BUILD_TESTING}") +message(STATUS "CMAKE_INSTALL_DOCDIR = ${CMAKE_INSTALL_DOCDIR}") +message(STATUS "CommandInterface version: ${LIB_COMMAND_INTERFACE_VERSION}") +message(STATUS "ControlInterface version: ${LIB_CONTROL_INTERFACE_VERSION}") +message(STATUS "RoutingInterface version: ${LIB_ROUTING_INTERFACE_VERSION}") +message(STATUS) +message(STATUS) +message(STATUS) diff --git a/README b/README index 2611ac4..6a53965 100755 --- a/README +++ b/README @@ -23,9 +23,11 @@ Author Christian Linke = Christian Linke christian.linke@bmw.de BMW 2011-2015 For further information see http://projects.genivi.org/audio-manager/. == Repositories -The main repository is http://git.projects.genivi.org-AudioManager.git +The main repository is +http://git.projects.genivi.org-AudioManager.git -The repository for example plugins can be found here: http://git.projects.genivi.org/AudioManagerPlugins.git +The repository for example plugins can be found here: +http://git.projects.genivi.org/AudioManagerPlugins.git == License The licenses of this project are split into two parts: @@ -67,44 +69,35 @@ The README is compiled into README.html with asciidoc === Compile Options These are the compile options with default values: - - AM_MAP_CAPACITY 10 - AM_MAX_CONNECTIONS 0x1000 - AM_SHARE_FOLDER /usr/local/share/audiomanager - BUILD_SHARED_LIBS OFF - CMAKE_BUILD_TYPE - CMAKE_INSTALL_PREFIX /usr/local - COMMON_API_DBUS_LIBRARY /usr/local/lib/libCommonAPI-DBus.so - COMMON_API_LIBRARY /usr/local/lib/libCommonAPI.so - DBUS_SERVICE_OBJECT_PATH /org/genivi/audiomanager - DBUS_SERVICE_PREFIX org.genivi.audiomanager - DEFAULT_TELNETPORT 6080 - DOC_OUTPUT_PATH XXX/build/doc - DYNAMIC_ID_BOUNDARY 100 - EXECUTABLE_OUTPUT_PATH XXX/build/bin - GLIB_DBUS_TYPES_TOLERANT ON - LIB_INSTALL_SUFFIX audiomanager - MAX_TELNETCONNECTIONS 3 - NSM_BUS_INTERFACE org.genivi.NodeStateManager - NSM_INTERFACE org.genivi.NodeStateManager.Consumer - NSM_PATH /org/genivi/NodeStateManager - PLUGINS_OUTPUT_PATH XXX/build/plugins - TEST_EXECUTABLE_INSTALL_PATH ~/tests - TEST_EXECUTABLE_OUTPUT_PATH XXX/build/bin/tests - USE_BUILD_LIBS ON - WITH_DATABASE_STORAGE OFF - WITH_DLT ON - WITH_DOCUMENTATION OFF - WITH_SHARED_UTILITIES OFF - WITH_SYSTEMD_WATCHDOG OFF - WITH_TELNET ON - WITH_TESTS ON - gmock_build_tests OFF - gtest_build_samples OFF - gtest_build_tests OFF - gtest_disable_pthreads OFF - gtest_force_shared_crt OFF - +---- +AudioManager Configuration: +-- CMAKE_BUILD_TYPE = +-- CMAKE_INSTALL_PREFIX = /usr/local +-- BUILD_DOCUMENTATION = OFF +-- WITH_TESTS = ON +-- WITH_DLT = ON +-- WITH_TESTS = ON +-- WITH_TELNET = ON +-- WITH_SYSTEMD_WATCHDOG = OFF +-- WITH_CAPI_WRAPPER = ON +-- WITH_DBUS_WRAPPER = OFF +-- WITH_SHARED_UTILITIES = OFF +-- WITH_SHARED_CORE = OFF +-- DYNAMIC_ID_BOUNDARY = 100 +-- LIB_INSTALL_SUFFIX = audiomanager +-- TEST_EXECUTABLE_INSTALL_PATH = ~/tests +-- DEFAULT_PLUGIN_COMMAND_DIR = /usr/local/lib/audiomanager/command +-- DEFAULT_PLUGIN_ROUTING_DIR = /usr/local/lib/audiomanager/routing +-- CONTROLLER_PLUGIN_DIR = /usr/local/lib/audiomanager/control +-- AM_SHARE_FOLDER = /usr/local/share/audiomanager +-- AM_MAP_CAPACITY = 10 +-- AM_MAX_CONNECTIONS = 0x1000 +-- AM_MAX_MAIN_CONNECTIONS = 0x1000 +-- BUILD_TESTING = ON +-- CommandInterface version: 4.0 +-- ControlInterface version: 5.0 +-- RoutingInterface version: 5.0 +---- === Passing options to cmake: Standard CMake can be used to configure these options. Tools like ccmake can be used to visually change the values. @@ -116,36 +109,32 @@ for example... You will need optionally fulfill some dependencies in order to compile the GENIVI AudioManager Daemon, these are: -* dbus (only when DBUS_WRAPPER==ON) [tested on version 1.2.16] -* sqlite3 [tested on version 3.6.22] (only when WITH_DATABASE_STORAGE==ON) +* dbus (only when WITH_DBUS_WRAPPER==ON) [tested on version 1.2.16] * automotive-dlt [greater 2.5.0] (only when WITH_DLT==ON) * doxygen [tested on version 1.6.3] (only when WITH_DOCUMENTATION==ON) -* commonAPI [version > 2.1] (only with WITH_ENABLED_IPC CAPI), more information here http://projects.genivi.org/commonapi/ - -To install them in a build environment like Ubuntu you can use: ----- -sudo apt-get install libdbus-1-dev libsqlite3-dev doxygen git cmake build-essential ----- +* commonAPI [version > 3.1.5] (only with WITH_CAPI_WRAPPER), more information here http://projects.genivi.org/commonapi/ +* systemd [ version > 44 ] (only WITH_SYSTEMD_WATCHDOG) === AudioManagerUtilities In the AudioManagerUtilites you can find helper functions that can be reused by other projects as well. The library can be shipped as a static or a dynamic link library (WITH_SHARED_UTILITIES). -=== The NodeStateManager +=== AudioManagerCore -The nodestatemanager headers are needed to compile the audiomanager. If the nodestatemanager includes are not found, -the headers shipped with the audiomanager are used. -The nodestatemanager can be retrieved from projects.genivi.org . +The AudioMangerCore is build as a static (or with WITH_SHARED_CORE) library. Sometimes it is useful for unit testing of a plugin to compile against the core. -Please note that the NSM interface must be compatible with Dbus properties. This requires for CommonAPI to use the commonAPI fdepl. -It used to work, but currently with CommmonAPI 2.6.1 the generation does not work anymore. +=== CommonAPI Wrapper -=== CommonAPI File generation +The commonapi wrapper provides the mainloop intergration for commonapi into the Mainloop of the audiomanager (CAmSockethandler). +In order to use it, just use: -The audiomanager will search in /usr/share or /usr/local/share for a generator. He will generate all necessary files with this generator into the build tree. +---- +CAPI->registerService(....) +CAPI->buildProxy(...) +---- -The addresses used for commonAPI are fixed. If you need to change them, you can use a central or local configure file. More information on CommonAPI documentation: http://projects.genivi.org/commonapi/ +instead of the standard calls. The CAPIWrapper will serialize the commands and integrate it smoothly with the mainloop. === Tests @@ -184,39 +173,26 @@ sudo make install this installs everything. -== Build targets +== Compiling plugins -Several install targets exists: +Once the Audiomanager is installed, it will also install *.pc files for autotools and *Config.cmake files for cmake projects. +In order to compile and link against the AudioMananger, you can use: -just install the audiomanager ---- -sudo make bin-install +find_package(AudioManager REQUIRED ) +find_package(AudioManagerUtilities) ---- - -just install the dev package with all headers and cmake file, needed to compile plugins out of source ----- -sudo make dev-install +to find the configuration files. To use the right include paths, use: ---- - -just install the tests +${AudioManager_INCLUDE_DIRS} +${AudioManagerUtilities_INCLUDE_DIRS} ---- -sudo make test-install ----- - -just install the plugins (only available if plugins are compiled) +to link agains the right libs use: ---- -sudo make plugins-install +${AudioManagerUtilities_LIBRARIES} ---- -just install the test for the plugins (only available if plugins are compiled) ----- -sudo make plugin-test-install ----- - -If you want to compile the Audiomanager together with the plugins, simply clone the plugins into a folder -Plugins on the main level. The Plugins will be then compiled together with the AudioManager. - -If the plugins are compiled separately, the AudioManager needs to be installed on the system. The plugins will find and read the important CMake variables and use them. +for example, see the AudiomanagerPlugins === Adding own plugins To keep the own sources away from the GENIVI code the project specific elements can be reconfigured with own type definitions. diff --git a/README.html b/README.html index 57eea58..3204c5d 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ - + GENIVI_AudioManager