diff options
Diffstat (limited to 'AudioManagerDaemon')
71 files changed, 3725 insertions, 258 deletions
diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt index 2fa7343..4704864 100644 --- a/AudioManagerDaemon/CMakeLists.txt +++ b/AudioManagerDaemon/CMakeLists.txt @@ -69,6 +69,7 @@ IF(WITH_DBUS_WRAPPER) SET (AUDIOMAN_SRCS_CXX ${AUDIOMAN_SRCS_CXX} src/CAmDbusWrapper.cpp + src/CAmNodeStateCommunicator.cpp ) ENDIF(WITH_DBUS_WRAPPER) @@ -129,10 +130,6 @@ IF (SYSTEMD_FOUND) ) ENDIF (SYSTEMD_FOUND) -IF(WITH_TESTS) - add_subdirectory (test) -ENDIF(WITH_TESTS) - #IF(WITH_DOCUMENTATION) # file(MAKE_DIRECTORY ${DOC_OUTPUT_PATH}) # configure_file(${DOXY_FILE} ${DOC_OUTPUT_PATH}/Doxyfile @ONLY IMMEDIATE) @@ -154,6 +151,27 @@ INSTALL(DIRECTORY "${AUDIO_INCLUDE_FOLDER}/" COMPONENT dev ) +IF(WITH_DBUS_WRAPPER) + IF(USE_BUILD_LIBS) + SET(NSM_INTROSPECTION_FILE ${EXECUTABLE_OUTPUT_PATH}/LifeCycleConsumer.xml) + execute_process( + COMMAND mkdir -p "${CMAKE_SOURCE_DIR}/bin" + COMMAND cp "${CMAKE_SOURCE_DIR}/cmake/LifecycleConsumer.xml" ${NSM_INTROSPECTION_FILE}) + ELSE(USE_BUILD_LIBS) + SET(NSM_INTROSPECTION_FILE ${CMAKE_INSTALL_PREFIX}/share/audiomanager/LifeCycleConsumer.xml) + INSTALL( + FILES ${CMAKE_SOURCE_DIR}/cmake/LifecycleConsumer.xml + DESTINATION "${NSM_INTROSPECTION_FILE}" + COMPONENT bin) + ENDIF(USE_BUILD_LIBS) +ENDIF(WITH_DBUS_WRAPPER) + +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/config.cmake ${CMAKE_SOURCE_DIR}/include/config.h ) + +IF(WITH_TESTS) + add_subdirectory (test) +ENDIF(WITH_TESTS) + # General packet dependency SET(ADD_DEPEND_BIN_PROP "sqlite3(>=3.6.22)") diff --git a/AudioManagerDaemon/docx/01_mainpage.dox b/AudioManagerDaemon/docx/01_mainpage.dox index a890180..ad0848b 100644 --- a/AudioManagerDaemon/docx/01_mainpage.dox +++ b/AudioManagerDaemon/docx/01_mainpage.dox @@ -26,4 +26,5 @@ 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 index 1a31d63..45f68f3 100644 --- a/AudioManagerDaemon/docx/02_license.dox +++ b/AudioManagerDaemon/docx/02_license.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/02_x_dependecies.dox b/AudioManagerDaemon/docx/02_x_dependecies.dox index f334e37..ff5c346 100644 --- a/AudioManagerDaemon/docx/02_x_dependecies.dox +++ b/AudioManagerDaemon/docx/02_x_dependecies.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/02_y_versioning.dox b/AudioManagerDaemon/docx/02_y_versioning.dox index f6c0990..b166beb 100644 --- a/AudioManagerDaemon/docx/02_y_versioning.dox +++ b/AudioManagerDaemon/docx/02_y_versioning.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/03_architecture_overview.dox b/AudioManagerDaemon/docx/03_architecture_overview.dox index ec399f2..230a99a 100644 --- a/AudioManagerDaemon/docx/03_architecture_overview.dox +++ b/AudioManagerDaemon/docx/03_architecture_overview.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/03_x_uml_model.dox b/AudioManagerDaemon/docx/03_x_uml_model.dox index 93077ca..802d181 100644 --- a/AudioManagerDaemon/docx/03_x_uml_model.dox +++ b/AudioManagerDaemon/docx/03_x_uml_model.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/04_components.dox b/AudioManagerDaemon/docx/04_components.dox index 09acd1a..c4084b8 100644 --- a/AudioManagerDaemon/docx/04_components.dox +++ b/AudioManagerDaemon/docx/04_components.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/04_x_elements.dox b/AudioManagerDaemon/docx/04_x_elements.dox index 4afdd35..7990d37 100644 --- a/AudioManagerDaemon/docx/04_x_elements.dox +++ b/AudioManagerDaemon/docx/04_x_elements.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox b/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox index a333141..113cf6b 100644 --- a/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox +++ b/AudioManagerDaemon/docx/04_y_audiomanager_and_sources.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/05_unique.dox b/AudioManagerDaemon/docx/05_unique.dox index a575ef8..5bf021a 100644 --- a/AudioManagerDaemon/docx/05_unique.dox +++ b/AudioManagerDaemon/docx/05_unique.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/06_classification.dox b/AudioManagerDaemon/docx/06_classification.dox index 0b77bde..ccedffc 100644 --- a/AudioManagerDaemon/docx/06_classification.dox +++ b/AudioManagerDaemon/docx/06_classification.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/07_interrupts.dox b/AudioManagerDaemon/docx/07_interrupts.dox index 51de73b..0e26b88 100644 --- a/AudioManagerDaemon/docx/07_interrupts.dox +++ b/AudioManagerDaemon/docx/07_interrupts.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/08_connections.dox b/AudioManagerDaemon/docx/08_connections.dox index f57f9a3..fd8a194 100644 --- a/AudioManagerDaemon/docx/08_connections.dox +++ b/AudioManagerDaemon/docx/08_connections.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/09_lipsync.dox b/AudioManagerDaemon/docx/09_lipsync.dox index 6d75343..6229198 100644 --- a/AudioManagerDaemon/docx/09_lipsync.dox +++ b/AudioManagerDaemon/docx/09_lipsync.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/10_early_audio.dox b/AudioManagerDaemon/docx/10_early_audio.dox index 1811049..bdd72f5 100644 --- a/AudioManagerDaemon/docx/10_early_audio.dox +++ b/AudioManagerDaemon/docx/10_early_audio.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/11_views.dox b/AudioManagerDaemon/docx/11_views.dox index b9efc92..2dda7c9 100644 --- a/AudioManagerDaemon/docx/11_views.dox +++ b/AudioManagerDaemon/docx/11_views.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/12_volumes.dox b/AudioManagerDaemon/docx/12_volumes.dox index c58b7f8..60603bc 100644 --- a/AudioManagerDaemon/docx/12_volumes.dox +++ b/AudioManagerDaemon/docx/12_volumes.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/13_properties.dox b/AudioManagerDaemon/docx/13_properties.dox index 577c743..2597fdf 100644 --- a/AudioManagerDaemon/docx/13_properties.dox +++ b/AudioManagerDaemon/docx/13_properties.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/14_misc.dox b/AudioManagerDaemon/docx/14_misc.dox index 1623f95..eae0caf 100644 --- a/AudioManagerDaemon/docx/14_misc.dox +++ b/AudioManagerDaemon/docx/14_misc.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/14_x_mainloop.dox b/AudioManagerDaemon/docx/14_x_mainloop.dox index cf327bc..8f112bc 100644 --- a/AudioManagerDaemon/docx/14_x_mainloop.dox +++ b/AudioManagerDaemon/docx/14_x_mainloop.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/14_y_watchdog.dox b/AudioManagerDaemon/docx/14_y_watchdog.dox index 8e7fb49..a1facc5 100644 --- a/AudioManagerDaemon/docx/14_y_watchdog.dox +++ b/AudioManagerDaemon/docx/14_y_watchdog.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/14_z_nodeStateManagement.dox b/AudioManagerDaemon/docx/14_z_nodeStateManagement.dox new file mode 100644 index 0000000..2e9150e --- /dev/null +++ b/AudioManagerDaemon/docx/14_z_nodeStateManagement.dox @@ -0,0 +1,32 @@ + /* + * 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 nsm The Node state management +\section The Node state managemer +The nodestatemanager is part of the GENIVI compliance. It basically handles startup and rundown of components in the IVI context.\n +For more information, please go to http://projects.genivi.org + +\section nsmiact The Interaction between the NodeStateManager and the AudioManager +It is the job of am::CAmNodeStateCommunicator to interact with the nodestatemanager via DBUS.\n +The ControllerPlugin can register by the NSM to be informed when a shutdown will occour. For this, the Audiomanager presents an DBus interface, defined in LifeCycleConsumer.xml that will be called from the NSM during a shutdown, +but only after the Controller registered by the NSM via am::CAmNodeStateCommunicator::nsmRegisterShutdownClient.\n +The controller has to answer this request during the timeout with am::CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete . +For more information, check am::CAmNodeStateCommunicator and http://projects.genivi.org + + + */ diff --git a/AudioManagerDaemon/docx/15_dlt_support.dox b/AudioManagerDaemon/docx/15_dlt_support.dox index 93be712..ca34896 100644 --- a/AudioManagerDaemon/docx/15_dlt_support.dox +++ b/AudioManagerDaemon/docx/15_dlt_support.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/15_x_eclipse.dox b/AudioManagerDaemon/docx/15_x_eclipse.dox index 1a06c64..95c8e9f 100644 --- a/AudioManagerDaemon/docx/15_x_eclipse.dox +++ b/AudioManagerDaemon/docx/15_x_eclipse.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ diff --git a/AudioManagerDaemon/docx/16_readme.dox b/AudioManagerDaemon/docx/16_readme.dox index 18a9002..9483a68 100644 --- a/AudioManagerDaemon/docx/16_readme.dox +++ b/AudioManagerDaemon/docx/16_readme.dox @@ -11,7 +11,7 @@ * 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 Mueller (christian.ei.mueller@bmw.de) + * \\author Christian Linke (christian.linke@bmw.de) * */ /*! diff --git a/AudioManagerDaemon/docx/Doxyfile.in b/AudioManagerDaemon/docx/Doxyfile.in index 4c6f48a..a71d39d 100644 --- a/AudioManagerDaemon/docx/Doxyfile.in +++ b/AudioManagerDaemon/docx/Doxyfile.in @@ -78,9 +78,9 @@ LAYOUT_FILE = # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = YES -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES +WARNINGS = NO +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = NO WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text " WARN_LOGFILE = @@ -93,7 +93,7 @@ FILE_PATTERNS = *.h *.cpp *.dox RECURSIVE = YES EXCLUDE = EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = */test/* */Plugin*/* */build*/* +EXCLUDE_PATTERNS = */test/* */Plugin*/* */build*/* */cmake/* */exampleCode/* */googleMock/* */ProjectSpecific/* EXCLUDE_SYMBOLS = EXAMPLE_PATH = @CMAKE_SOURCE_DIR@ EXAMPLE_PATTERNS = diff --git a/AudioManagerDaemon/include/CAmCommandReceiver.h b/AudioManagerDaemon/include/CAmCommandReceiver.h index 0459614..8d5b4a6 100644 --- a/AudioManagerDaemon/include/CAmCommandReceiver.h +++ b/AudioManagerDaemon/include/CAmCommandReceiver.h @@ -60,9 +60,13 @@ public: 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; - void confirmCommandReady(const uint16_t handle); - void confirmCommandRundown(const uint16_t handle); + am_Error_e getListSinkMainNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const; + am_Error_e getListSourceMainNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const; + am_Error_e setSinkMainNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); + am_Error_e setSourceMainNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); uint16_t getStartupHandle(); //!< returns a startup handle uint16_t getRundownHandle(); //!< returns a rundown handle @@ -81,6 +85,8 @@ private: std::vector<uint16_t> 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; }; } diff --git a/AudioManagerDaemon/include/CAmCommandSender.h b/AudioManagerDaemon/include/CAmCommandSender.h index 4605da4..cf41b77 100644 --- a/AudioManagerDaemon/include/CAmCommandSender.h +++ b/AudioManagerDaemon/include/CAmCommandSender.h @@ -65,6 +65,13 @@ public: void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); void getInterfaceVersion(std::string& version) const; am_Error_e getListPlugins(std::vector<std::string>& interfaces) const; + void cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties); + void cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& 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 diff --git a/AudioManagerDaemon/include/CAmControlReceiver.h b/AudioManagerDaemon/include/CAmControlReceiver.h index a911706..a7b2554 100644 --- a/AudioManagerDaemon/include/CAmControlReceiver.h +++ b/AudioManagerDaemon/include/CAmControlReceiver.h @@ -32,6 +32,7 @@ class CAmDatabaseHandler; class CAmRoutingSender; class CAmCommandSender; class CAmRouter; +class CAmNodeStateCommunicator; /** * This class is used to receive all commands from the control interface @@ -39,6 +40,7 @@ class CAmRouter; class CAmControlReceiver: public IAmControlReceive { public: + CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter, CAmNodeStateCommunicator* iNodeStateCommunicator); CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter); ~CAmControlReceiver(); am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s>& returnList); @@ -109,10 +111,30 @@ public: void setCommandRundown(); void setRoutingReady(); void setRoutingRundown(); - void confirmControllerReady(); - void confirmControllerRundown(); + 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<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties); + am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties); + am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFormats, const std::vector<bool> convertionMatrix); + am_Error_e setVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s> 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 norificationConfiguration); + void sendSinkMainNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s notificationPayload); + void sendSourceMainNotificationPayload(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 nsmGetRestartReasonProperty(NsmRestartReason_e& restartReason) ; + am_Error_e nsmGetShutdownReasonProperty(NsmShutdownReason_e& ShutdownReason) ; + am_Error_e nsmGetRunningReasonProperty(NsmRunningReason_e& nsmRunningReason) ; + NsmErrorStatus_e nsmGetNodeState(NsmNodeState_e& nsmNodeState) ; + NsmErrorStatus_e nsmGetSessionState(const std::string& sessionName, const NsmSeat_e& seatID, NsmSessionState_e& sessionState) ; + NsmErrorStatus_e nsmGetApplicationMode(NsmApplicationMode_e& applicationMode) ; + NsmErrorStatus_e nsmRegisterShutdownClient(const uint32_t shutdownMode, const uint32_t timeoutMs) ; + NsmErrorStatus_e nsmUnRegisterShutdownClient(const uint32_t shutdownMode) ; + am_Error_e nsmGetInterfaceVersion(uint32_t& version) ; + NsmErrorStatus_e nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) ; private: CAmDatabaseHandler* mDatabaseHandler; //!< pointer tto the databasehandler @@ -120,6 +142,7 @@ private: CAmCommandSender* mCommandSender; //!< pointer to the command send interface CAmSocketHandler* mSocketHandler; //!< pointer to the socketHandler CAmRouter* mRouter; //!< pointer to the Router + CAmNodeStateCommunicator* mNodeStateCommunicator; }; } diff --git a/AudioManagerDaemon/include/CAmControlSender.h b/AudioManagerDaemon/include/CAmControlSender.h index 65db2c8..c62c7e8 100644 --- a/AudioManagerDaemon/include/CAmControlSender.h +++ b/AudioManagerDaemon/include/CAmControlSender.h @@ -27,6 +27,7 @@ #endif #include "control/IAmControlSend.h" +#include "shared/CAmSocketHandler.h" namespace am { @@ -37,11 +38,12 @@ namespace am class CAmControlSender { public: - CAmControlSender(std::string controlPluginFile); + CAmControlSender(std::string controlPluginFile,CAmSocketHandler* sockethandler); + CAmControlSender(); ~CAmControlSender(); am_Error_e startupController(IAmControlReceive* controlreceiveinterface) ; void setControllerReady() ; - void setControllerRundown() ; + 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) ; @@ -81,24 +83,68 @@ public: 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<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e>& 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 ; - void confirmCommandReady() ; - void confirmRoutingReady() ; - void confirmCommandRundown() ; - void confirmRoutingRundown() ; - static void CallsetControllerRundown() + am_Error_e hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties) ; + am_Error_e hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties) ; + am_Error_e hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFromats, const std::vector<bool> convertionMatrix) ; + void cbAckSetVolume(const am_Handle_s handle, const std::vector<am_Volumes_s> 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 hookSystemNodeStateChanged(const NsmNodeState_e NodeStateId) ; + void hookSystemNodeApplicationModeChanged(const NsmApplicationMode_e ApplicationModeId) ; + void hookSystemSessionStateChanged(const std::string sessionName, const int32_t seatID, const NsmSessionState_e sessionStateID) ; + NsmErrorStatus_e hookSystemLifecycleRequest(const uint32_t Request, const uint32_t RequestId) ; + + 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); + write(mPipe[1], &p, sizeof(p)); + } + + TAmShPollFired<CAmControlSender> receiverCallbackT; + TAmShPollCheck<CAmControlSender> checkerCallbackT; + TAmShPollDispatch<CAmControlSender> dispatcherCallbackT; + + //todo: add getSessionstate, interface nachbilden von org.genivi.NodeStateManager.LifeCycleConsumer, antwort nach NSM + //chek interface version RegisterShutdownClient, UnRegisterShutdownClient, GetSessionState, GetApplicationMode, GetNodeState + + //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->setControllerRundown(); + { + 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; }; } diff --git a/AudioManagerDaemon/include/CAmDatabaseHandler.h b/AudioManagerDaemon/include/CAmDatabaseHandler.h index e8e44c2..50a5bc7 100644 --- a/AudioManagerDaemon/include/CAmDatabaseHandler.h +++ b/AudioManagerDaemon/include/CAmDatabaseHandler.h @@ -136,6 +136,15 @@ public: 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 changeSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties); + am_Error_e changeSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties); + am_Error_e getListSinkMainNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations); + am_Error_e getListSourceMainNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& 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<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFormats, const std::vector<bool> 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; diff --git a/AudioManagerDaemon/include/CAmDatabaseObserver.h b/AudioManagerDaemon/include/CAmDatabaseObserver.h index 9d89ef8..e3a016d 100644 --- a/AudioManagerDaemon/include/CAmDatabaseObserver.h +++ b/AudioManagerDaemon/include/CAmDatabaseObserver.h @@ -66,6 +66,10 @@ public: 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<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible); + void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& 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 diff --git a/AudioManagerDaemon/include/CAmNodeStateCommunicator.h b/AudioManagerDaemon/include/CAmNodeStateCommunicator.h new file mode 100644 index 0000000..dfc6689 --- /dev/null +++ b/AudioManagerDaemon/include/CAmNodeStateCommunicator.h @@ -0,0 +1,72 @@ +/** + * 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 2012 + * + * \file CAmNodeStateCommunicator.h + * For further information see http://www.genivi.org/. + * + */ +#ifndef CAMNODESTATECOMMUNICATOR_H_ +#define CAMNODESTATECOMMUNICATOR_H_ + +#include "shared/CAmDbusWrapper.h" +#include "NodeStateManager.h" + +namespace am +{ + +class CAmControlSender; + +/** communicates with the NSM + * The CAmNodeStateCommunicator communicates with the NodeStateManager via Dbus. Only works, if CAmDBusWrapper is enabled. + * The CAmNodeStateCommunicator is triggered via CAmControlReceiver, so you can communicate from the ControllerPlugin with it. + * Most if the interfaces are passive, so you get the information you need via retrieving it. If you need to register the AudioManager + * as LifeCycleConsumer, you need to call CAmNodeStateCommunicator::nsmRegisterShutdownClient which can be undone with CAmNodeStateCommunicator::nsmUnRegisterShutdownClient. + * After you have registered, you will get hookSystemLifecycleRequest on the ControlSendInterface of the controller. + * You should answer this within your set timeout with CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete. + */ +class CAmNodeStateCommunicator +{ +public: + CAmNodeStateCommunicator(CAmDbusWrapper* iDbusWrapper); + virtual ~CAmNodeStateCommunicator(); + am_Error_e nsmGetRestartReasonProperty(NsmRestartReason_e& restartReason) ; + am_Error_e nsmGetShutdownReasonProperty(NsmShutdownReason_e& ShutdownReason) ; + am_Error_e nsmGetRunningReasonProperty(NsmRunningReason_e& nsmRunningReason) ; + NsmErrorStatus_e nsmGetNodeState(NsmNodeState_e& nsmNodeState) ; + NsmErrorStatus_e nsmGetSessionState(const std::string& sessionName, const NsmSeat_e& seatID, NsmSessionState_e& sessionState) ; + NsmErrorStatus_e nsmGetApplicationMode(NsmApplicationMode_e& applicationMode) ; + NsmErrorStatus_e nsmRegisterShutdownClient(const uint32_t shutdownMode, const uint32_t timeoutMs) ; + NsmErrorStatus_e nsmUnRegisterShutdownClient(const uint32_t shutdownMode) ; + am_Error_e nsmGetInterfaceVersion(uint32_t& version) ; + NsmErrorStatus_e nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) ; + + void registerControlSender(CAmControlSender* iControlSender); + static DBusHandlerResult receiveCallback(DBusConnection *conn, DBusMessage *msg, void *user_data); + static DBusHandlerResult signalCallback(DBusConnection *conn, DBusMessage *msg, void *user_data); + + +private: + void sendIntrospection(DBusConnection* conn, DBusMessage* msg); + void sendMessage(DBusMessage* message, DBusMessage* origMessage); + DBusHandlerResult receiveCallbackDelegate(DBusConnection *conn, DBusMessage *msg); + am_Error_e readIntegerProperty(const std::string property, int32_t &value); + CAmDbusWrapper* mpDbusWrapper; + CAmControlSender* mpControlSender; + DBusConnection* mpDBusConnection; +}; + +} /* namespace am */ +#endif /* CAMNODESTATECOMMUNICATOR_H_ */ diff --git a/AudioManagerDaemon/include/CAmRoutingReceiver.h b/AudioManagerDaemon/include/CAmRoutingReceiver.h index ca2a4b4..3cb1225 100644 --- a/AudioManagerDaemon/include/CAmRoutingReceiver.h +++ b/AudioManagerDaemon/include/CAmRoutingReceiver.h @@ -79,8 +79,16 @@ public: am_Error_e getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const; am_Error_e getSocketHandler(CAmSocketHandler*& socketHandler) const; void getInterfaceVersion(std::string& version) const; - void confirmRoutingReady(const uint16_t handle); - void confirmRoutingRundown(const uint16_t handle); + 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, std::vector<am_ConnectionFormat_e> listSourceFormats, const std::vector<am_ConnectionFormat_e> listSinkFormats, std::vector<bool> convertionMatrix); + am_Error_e updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties); + am_Error_e updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, std::vector<am_SoundProperty_s> listSoundProperties, std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties); + void ackSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s> 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) ; uint16_t getStartupHandle(); //!< returns a startup handle uint16_t getRundownHandle(); //!< returns a rundown handle @@ -101,6 +109,9 @@ private: 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; + }; } diff --git a/AudioManagerDaemon/include/CAmRoutingSender.h b/AudioManagerDaemon/include/CAmRoutingSender.h index 5f58689..ac3f9a2 100644 --- a/AudioManagerDaemon/include/CAmRoutingSender.h +++ b/AudioManagerDaemon/include/CAmRoutingSender.h @@ -72,6 +72,9 @@ public: am_Error_e getListHandles(std::vector<am_Handle_s> & listHandles) const; am_Error_e getListPlugins(std::vector<std::string>& interfaces) const; void getInterfaceVersion(std::string& version) const; + am_Error_e asyncSetVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s>& 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); struct InterfaceNamePairs //!< is used to pair interfaces with busnames { @@ -88,6 +91,7 @@ public: am_sourceID_t sourceID; am_crossfaderID_t crossfaderID; am_connectionID_t connectionID; + am_DataType_u volumeID; }; union @@ -97,6 +101,8 @@ public: am_volume_t volume; am_HotSink_e hotSink; std::vector<am_SoundProperty_s>* soundProperties; + std::vector<am_Volumes_s>* listVolumes; + am_NotificationConfiguration_s* notificationConfiguration; }; }; diff --git a/AudioManagerDaemon/src/CAmCommandReceiver.cpp b/AudioManagerDaemon/src/CAmCommandReceiver.cpp index c507d5f..f3fa3ef 100644 --- a/AudioManagerDaemon/src/CAmCommandReceiver.cpp +++ b/AudioManagerDaemon/src/CAmCommandReceiver.cpp @@ -39,7 +39,9 @@ CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm mListStartupHandles(), // mListRundownHandles(), // mWaitStartup(false), // - mWaitRundown(false) + mWaitRundown(false), + mLastErrorStartup(E_OK), // + mLastErrorRundown(E_OK) // { assert(mDatabaseHandler!=NULL); @@ -184,18 +186,22 @@ void CAmCommandReceiver::getInterfaceVersion(std::string & version) const version = CommandReceiveVersion; } -void CAmCommandReceiver::confirmCommandReady(const uint16_t handle) +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(); + mControlSender->confirmCommandReady(mLastErrorStartup); } -void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle) +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(); + mControlSender->confirmCommandRundown(mLastErrorRundown); } uint16_t CAmCommandReceiver::getStartupHandle() @@ -215,11 +221,35 @@ uint16_t CAmCommandReceiver::getRundownHandle() void CAmCommandReceiver::waitOnStartup(bool startup) { mWaitStartup = startup; + mLastErrorStartup=E_OK; +} + +am_Error_e CAmCommandReceiver::getListSinkMainNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const +{ + return (mDatabaseHandler->getListSinkMainNotificationConfigurations(sinkID,listMainNotificationConfigurations)); +} + +am_Error_e CAmCommandReceiver::getListSourceMainNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const +{ + return (mDatabaseHandler->getListSourceMainNotificationConfigurations(sourceID,listMainNotificationConfigurations)); +} + +am_Error_e CAmCommandReceiver::setSinkMainNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + logInfo("CommandReceiver::setSinkMainNotificationConfiguration got called, sinkID=", sinkID, " notificationType=",mainNotificationConfiguration.notificationType, " parameter=", mainNotificationConfiguration.notificationParameter, "status=",mainNotificationConfiguration.notificationStatus); + return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration)); +} + +am_Error_e CAmCommandReceiver::setSourceMainNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + logInfo("CommandReceiver::setSourceMainNotificationConfiguration got called, sourceID=", sourceID, " notificationType=",mainNotificationConfiguration.notificationType, " parameter=", mainNotificationConfiguration.notificationParameter, "status=",mainNotificationConfiguration.notificationStatus); + 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 index 1494bc1..7ec2740 100644 --- a/AudioManagerDaemon/src/CAmCommandSender.cpp +++ b/AudioManagerDaemon/src/CAmCommandSender.cpp @@ -297,6 +297,36 @@ am_Error_e am::CAmCommandSender::getListPlugins(std::vector<std::string> & inter return (E_OK); } +void CAmCommandSender::cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) +{ + CALL_ALL_INTERFACES(cbSinkUpdated(sinkID,sinkClassID,listMainSoundProperties)); +} + +void CAmCommandSender::cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& 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(cbSinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration)); +} + +void CAmCommandSender::cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + CALL_ALL_INTERFACES(cbSourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration)); +} + void CAmCommandSender::unloadLibraries(void) { std::vector<void*>::iterator iterator = mListLibraryHandles.begin(); diff --git a/AudioManagerDaemon/src/CAmControlReceiver.cpp b/AudioManagerDaemon/src/CAmControlReceiver.cpp index f78a0f3..cfa9467 100644 --- a/AudioManagerDaemon/src/CAmControlReceiver.cpp +++ b/AudioManagerDaemon/src/CAmControlReceiver.cpp @@ -22,22 +22,42 @@ #include "CAmControlReceiver.h" #include <cassert> #include <stdlib.h> +#include <stdexcept> #include "config.h" #include "CAmDatabaseHandler.h" #include "CAmRoutingSender.h" #include "CAmCommandSender.h" #include "CAmRouter.h" +#include "CAmNodeStateCommunicator.h" #include "shared/CAmDltWrapper.h" #include "shared/CAmSocketHandler.h" + namespace am { +CAmControlReceiver::CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter, CAmNodeStateCommunicator* iNodeStateCommunicator) : + mDatabaseHandler(iDatabaseHandler), // + mRoutingSender(iRoutingSender), // + mCommandSender(iCommandSender), // + mSocketHandler(iSocketHandler), // + mRouter(iRouter), // + mNodeStateCommunicator(iNodeStateCommunicator) +{ + assert(mDatabaseHandler!=NULL); + assert(mRoutingSender!=NULL); + assert(mCommandSender!=NULL); + assert(mSocketHandler!=NULL); + assert(mRouter!=NULL); + assert(iNodeStateCommunicator!=NULL); +} + CAmControlReceiver::CAmControlReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmRoutingSender *iRoutingSender, CAmCommandSender *iCommandSender, CAmSocketHandler *iSocketHandler, CAmRouter* iRouter) : mDatabaseHandler(iDatabaseHandler), // mRoutingSender(iRoutingSender), // mCommandSender(iCommandSender), // mSocketHandler(iSocketHandler), // - mRouter(iRouter) + mRouter(iRouter), // + mNodeStateCommunicator(NULL) { assert(mDatabaseHandler!=NULL); assert(mRoutingSender!=NULL); @@ -476,14 +496,26 @@ void CAmControlReceiver::setRoutingReady() mRoutingSender->setRoutingReady(); } -void CAmControlReceiver::confirmControllerReady() +void CAmControlReceiver::confirmControllerReady(const am_Error_e error) { //todo: one time implement here system interaction with NSM + if (error!=E_OK) + logError("CAmControlReceiver::confirmControllerReady controller reported error", error); } -void CAmControlReceiver::confirmControllerRundown() +void CAmControlReceiver::confirmControllerRundown(const am_Error_e error) { - logInfo ("CAmControlReceiver::confirmControllerRundown(), will exit now"); + 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) @@ -508,5 +540,136 @@ void CAmControlReceiver::getInterfaceVersion(std::string & version) const { version = ControlReceiveVersion; } + +am_Error_e CAmControlReceiver::changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + logInfo("CAmControlReceiver::changeSource was called, sourceID", sourceID); + return (mDatabaseHandler->changeSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlReceiver::changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + logInfo("CAmControlReceiver::changeSink was called with sinkID", sinkID); + return (mDatabaseHandler->changeSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmControlReceiver::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFormats, const std::vector<bool> convertionMatrix) +{ + logInfo("CAmControlReceiver::changeGatewayDB was called with gatewayID", gatewayID); + return (mDatabaseHandler->changeGatewayDB(gatewayID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix)); +} + +am_Error_e CAmControlReceiver::setVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s> 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.notificationType=",notificationConfiguration.notificationType,"notificationConfiguration.notificationStatus",notificationConfiguration.notificationStatus,"notificationConfiguration.notificationParameter",notificationConfiguration.notificationParameter); + 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.notificationType=",notificationConfiguration.notificationType,"notificationConfiguration.notificationStatus",notificationConfiguration.notificationStatus,"notificationConfiguration.notificationParameter",notificationConfiguration.notificationParameter); + return (mRoutingSender->asyncSetSourceNotificationConfiguration(handle,sourceID,notificationConfiguration)); +} + +void CAmControlReceiver::sendSinkMainNotificationPayload(const am_sinkID_t sinkID, const am_NotificationPayload_s notificationPayload) +{ + logInfo("CAmControlReceiver::sendSinkMainNotificationPayload called, sinkID=",sinkID,"type=",notificationPayload.notificationType,"value=",notificationPayload.notificationValue); + mCommandSender->cbSinkNotification(sinkID,notificationPayload); +} + +void CAmControlReceiver::sendSourceMainNotificationPayload(const am_sourceID_t sourceID, const am_NotificationPayload_s notificationPayload) +{ + logInfo("CAmControlReceiver::sendSourceMainNotificationPayload called, sourceID=",sourceID,"type=",notificationPayload.notificationType,"value=",notificationPayload.notificationValue); + 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::nsmGetRestartReasonProperty(NsmRestartReason_e& restartReason) +{ + if (!mNodeStateCommunicator) + return (E_NON_EXISTENT); + return (mNodeStateCommunicator->nsmGetRestartReasonProperty(restartReason)); +} + +am_Error_e CAmControlReceiver::nsmGetShutdownReasonProperty(NsmShutdownReason_e& ShutdownReason) +{ + if (!mNodeStateCommunicator) + return (E_NON_EXISTENT); + return (mNodeStateCommunicator->nsmGetShutdownReasonProperty(ShutdownReason)); +} + +am_Error_e CAmControlReceiver::nsmGetRunningReasonProperty(NsmRunningReason_e& nsmRunningReason) +{ + if (!mNodeStateCommunicator) + return (E_NON_EXISTENT); + return (mNodeStateCommunicator->nsmGetRunningReasonProperty(nsmRunningReason)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmGetNodeState(NsmNodeState_e& nsmNodeState) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmGetNodeState(nsmNodeState)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmGetSessionState(const std::string& sessionName, const NsmSeat_e& seatID, NsmSessionState_e& sessionState) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmGetSessionState(sessionName,seatID,sessionState)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmGetApplicationMode(NsmApplicationMode_e& applicationMode) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmGetApplicationMode(applicationMode)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmRegisterShutdownClient(const uint32_t shutdownMode, const uint32_t timeoutMs) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmRegisterShutdownClient(shutdownMode,timeoutMs)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmUnRegisterShutdownClient(const uint32_t shutdownMode) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmUnRegisterShutdownClient(shutdownMode)); +} + +am_Error_e CAmControlReceiver::nsmGetInterfaceVersion(uint32_t& version) +{ + if (!mNodeStateCommunicator) + return (E_NON_EXISTENT); + return (mNodeStateCommunicator->nsmGetInterfaceVersion(version)); +} + +NsmErrorStatus_e CAmControlReceiver::nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) +{ + if (!mNodeStateCommunicator) + return (NsmErrorStatus_Error); + return (mNodeStateCommunicator->nsmSendLifecycleRequestComplete(RequestId,status)); +} + } diff --git a/AudioManagerDaemon/src/CAmControlSender.cpp b/AudioManagerDaemon/src/CAmControlSender.cpp index 569e4c4..da2321e 100644 --- a/AudioManagerDaemon/src/CAmControlSender.cpp +++ b/AudioManagerDaemon/src/CAmControlSender.cpp @@ -36,14 +36,21 @@ namespace am CAmControlSender* CAmControlSender::mInstance=NULL; -CAmControlSender::CAmControlSender(std::string controlPluginFile) : +CAmControlSender::CAmControlSender(std::string controlPluginFile,CAmSocketHandler* sockethandler) : + receiverCallbackT(this, &CAmControlSender::receiverCallback),// + checkerCallbackT(this, &CAmControlSender::checkerCallback),// + dispatcherCallbackT(this, &CAmControlSender::dispatcherCallback), // + mPipe(), // mlibHandle(NULL), // - mController(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()) { @@ -70,6 +77,18 @@ CAmControlSender::CAmControlSender(std::string controlPluginFile) : { 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() @@ -323,10 +342,11 @@ void CAmControlSender::setControllerReady() mController->setControllerReady(); } -void CAmControlSender::setControllerRundown() +void CAmControlSender::setControllerRundown(const int16_t signal) { assert(mController); - mController->setControllerRundown(); + 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<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e> & listPrioConnectionFormats) @@ -340,27 +360,150 @@ void CAmControlSender::getInterfaceVersion(std::string & version) const version = ControlSendVersion; } -void CAmControlSender::confirmCommandReady() +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); +} + +void CAmControlSender::hookSystemNodeStateChanged(const NsmNodeState_e NodeStateId) +{ + assert(mController); + mController->hookSystemNodeStateChanged(NodeStateId); +} + +void CAmControlSender::hookSystemNodeApplicationModeChanged(const NsmApplicationMode_e ApplicationModeId) { assert(mController); - mController->confirmCommandReady(); + mController->hookSystemNodeApplicationModeChanged(ApplicationModeId); } -void CAmControlSender::confirmRoutingReady() +am_Error_e CAmControlSender::hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties) { assert(mController); - mController->confirmRoutingReady(); + return (mController->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); } -void CAmControlSender::confirmCommandRundown() +am_Error_e CAmControlSender::hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties) { assert(mController); - mController->confirmCommandRundown(); + return (mController->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); } -void CAmControlSender::confirmRoutingRundown() +am_Error_e CAmControlSender::hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFromats, const std::vector<bool> convertionMatrix) { assert(mController); - mController->confirmRoutingRundown(); + return (mController->hookSystemUpdateGateway(gatewayID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix)); } + +void CAmControlSender::cbAckSetVolume(const am_Handle_s handle, const std::vector<am_Volumes_s> listVolumes, const am_Error_e error) +{ + assert(mController); + mController->cbAckSetVolume(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 + read(pollfd.fd, &mSignal, sizeof(mSignal)); +} + +bool CAmControlSender::checkerCallback(const sh_pollHandle_t handle, void* userData) +{ + (void) handle; + (void) userData; + return (true); +} + +void CAmControlSender::hookSystemSessionStateChanged(const std::string sessionName, const int32_t seatID, const NsmSessionState_e sessionStateID) +{ + assert(mController); + mController->hookSystemSessionStateChanged(sessionName,seatID,sessionStateID); +} + +NsmErrorStatus_e CAmControlSender::hookSystemLifecycleRequest(const uint32_t Request, const uint32_t RequestId) +{ + assert(mController); + return (mController->hookSystemLifecycleRequest(Request,RequestId)); +} + +/**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/CAmDatabaseHandler.cpp b/AudioManagerDaemon/src/CAmDatabaseHandler.cpp index 2e2fa7e..4e9e51e 100644 --- a/AudioManagerDaemon/src/CAmDatabaseHandler.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseHandler.cpp @@ -429,6 +429,9 @@ am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID 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("(notificationType INTEGER, notificationStatus INTEGER, notificationParameter INTEGER)"); + if (!this->sqQuery(command)) + return (E_DATABASE_ERROR); //fill ConnectionFormats command = "INSERT INTO SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat) VALUES (?)"); @@ -463,6 +466,24 @@ am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID MY_SQLITE_RESET(query) } + //Fill NotificationConfigurations + command = "INSERT INTO SinkNotificationConfiguration" + i2s(sinkID) + std::string("(notificationType,notificationStatus,notificationParameter) VALUES (?,?,?)"); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + std::vector<am_NotificationConfiguration_s>::const_iterator NotificationConfigurationIterator(sinkData.listNotificationConfigurations.begin()); + for (; NotificationConfigurationIterator < sinkData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator) + { + MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->notificationType) + MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->notificationStatus) + MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->notificationParameter) + 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)"); @@ -486,6 +507,29 @@ am_Error_e CAmDatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID MY_SQLITE_RESET(query) } MY_SQLITE_FINALIZE(query) + + //now we got MainNotificationConfigurations as well + command = "CREATE TABLE SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(notificationType INTEGER, notificationStatus INTEGER, notificationParameter INTEGER)"); + if (!this->sqQuery(command)) + return (E_DATABASE_ERROR); + + command = "INSERT INTO SinkMainNotificationConfiguration" + i2s(sinkID) + std::string("(notificationType,notificationStatus,notificationParameter) VALUES (?,?,?)"); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + std::vector<am_NotificationConfiguration_s>::const_iterator mainNotificationConfigurationIterator(sinkData.listMainNotificationConfigurations.begin()); + for (; mainNotificationConfigurationIterator < sinkData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator) + { + MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->notificationType) + MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->notificationStatus) + MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->notificationParameter) + 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); @@ -800,6 +844,9 @@ am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_ 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("(notificationType INTEGER, notificationStatus INTEGER, notificationParameter INTEGER)"); + if (!this->sqQuery(command)) + return (E_DATABASE_ERROR); //fill ConnectionFormats command = "INSERT INTO SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat) VALUES (?)"); @@ -835,7 +882,23 @@ am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_ MY_SQLITE_RESET(query) } - MY_SQLITE_FINALIZE(query) + //Fill NotificationConfigurations + command = "INSERT INTO SourceNotificationConfiguration" + i2s(sourceID) + std::string("(notificationType,notificationStatus,notificationParameter) VALUES (?,?,?)"); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + std::vector<am_NotificationConfiguration_s>::const_iterator NotificationConfigurationIterator(sourceData.listNotificationConfigurations.begin()); + for (; NotificationConfigurationIterator < sourceData.listNotificationConfigurations.end(); ++NotificationConfigurationIterator) + { + MY_SQLITE_BIND_INT(query, 1, NotificationConfigurationIterator->notificationType) + MY_SQLITE_BIND_INT(query, 2, NotificationConfigurationIterator->notificationStatus) + MY_SQLITE_BIND_INT(query, 3, NotificationConfigurationIterator->notificationParameter) + 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) { @@ -860,6 +923,29 @@ am_Error_e CAmDatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_ MY_SQLITE_RESET(query) } MY_SQLITE_FINALIZE(query) + + //now we got MainNotificationConfigurations as well + command = "CREATE TABLE SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(notificationType INTEGER, notificationStatus INTEGER, notificationParameter INTEGER)"); + if (!this->sqQuery(command)) + return (E_DATABASE_ERROR); + + command = "INSERT INTO SourceMainNotificationConfiguration" + i2s(sourceID) + std::string("(notificationType,notificationStatus,notificationParameter) VALUES (?,?,?)"); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + std::vector<am_NotificationConfiguration_s>::const_iterator mainNotificationConfigurationIterator(sourceData.listMainNotificationConfigurations.begin()); + for (; mainNotificationConfigurationIterator < sourceData.listMainNotificationConfigurations.end(); ++mainNotificationConfigurationIterator) + { + MY_SQLITE_BIND_INT(query, 1, mainNotificationConfigurationIterator->notificationType) + MY_SQLITE_BIND_INT(query, 2, mainNotificationConfigurationIterator->notificationStatus) + MY_SQLITE_BIND_INT(query, 3, mainNotificationConfigurationIterator->notificationParameter) + 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); @@ -1250,16 +1336,22 @@ am_Error_e CAmDatabaseHandler::removeSinkDB(const am_sinkID_t 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); @@ -2148,12 +2240,14 @@ am_Error_e CAmDatabaseHandler::getListConnections(std::vector<am_Connection_s> & am_Error_e CAmDatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) const { listSinks.clear(); - sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL; + sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qNotificationConfiguration= NULL, *qMAinSoundProperty = NULL, *qMainNotificationConfiguration= NULL; int eCode = 0; am_Sink_s temp; am_ConnectionFormat_e 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) @@ -2193,6 +2287,19 @@ am_Error_e CAmDatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) MY_SQLITE_FINALIZE(qSoundProperty) + //read out notifications + std::string commandNotificationConfiguration = "SELECT notificationType, notificationStatus, notificationParameter FROM SinkNotificationConfiguration" + i2s(temp.sinkID); + MY_SQLITE_PREPARE_V2(mpDatabase, commandNotificationConfiguration.c_str(), -1, &qNotificationConfiguration, NULL) + while ((eCode = sqlite3_step(qNotificationConfiguration)) == SQLITE_ROW) + { + tempNotificationConfiguration.notificationType = static_cast<am_NotificationType_e> (sqlite3_column_int(qNotificationConfiguration, 0)); + tempNotificationConfiguration.notificationStatus = static_cast<am_NotificationStatus_e> (sqlite3_column_int(qNotificationConfiguration, 1)); + tempNotificationConfiguration.notificationParameter = static_cast<int16_t> (sqlite3_column_int(qNotificationConfiguration, 2)); + temp.listNotificationConfigurations.push_back(tempNotificationConfiguration); + } + + MY_SQLITE_FINALIZE(qNotificationConfiguration) + //read out MainSoundProperties if sink is visible if(temp.visible) { @@ -2206,6 +2313,19 @@ am_Error_e CAmDatabaseHandler::getListSinks(std::vector<am_Sink_s> & listSinks) } MY_SQLITE_FINALIZE(qMAinSoundProperty) + + //and mainNotificationConfigurations + std::string commandMainNotificationConfiguration = "SELECT notificationType, notificationStatus, notificationParameter FROM SinkMainNotificationConfiguration" + i2s(temp.sinkID); + MY_SQLITE_PREPARE_V2(mpDatabase, commandMainNotificationConfiguration.c_str(), -1, &qMainNotificationConfiguration, NULL) + while ((eCode = sqlite3_step(qMainNotificationConfiguration)) == SQLITE_ROW) + { + tempMainNotificationConfiguration.notificationType = static_cast <am_NotificationType_e> (sqlite3_column_int(qMainNotificationConfiguration, 0)); + tempMainNotificationConfiguration.notificationStatus = static_cast <am_NotificationStatus_e> (sqlite3_column_int(qMainNotificationConfiguration, 1)); + tempMainNotificationConfiguration.notificationParameter = static_cast <uint16_t>(sqlite3_column_int(qMainNotificationConfiguration, 2)); + temp.listMainNotificationConfigurations.push_back(tempMainNotificationConfiguration); + } + + MY_SQLITE_FINALIZE(qMainNotificationConfiguration) } listSinks.push_back(temp); @@ -4254,6 +4374,543 @@ am_Error_e am::CAmDatabaseHandler::peekSourceClassID(const std::string & name, a return (returnVal); } + +am_Error_e CAmDatabaseHandler::changeSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + assert(sourceID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + am_sourceClass_t sourceClassOut(sourceClassID); + std::vector<am_MainSoundProperty_s> listMainSoundPropertiesOut(listMainSoundProperties); + + if (!existSource(sourceID)) + { + return (E_NON_EXISTENT); + } + + //check if sinkClass needs to be changed + if (sourceID!=0) + { + command = "UPDATE"+ std::string(SINK_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::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 sourceClassID FROM " + std::string(SINK_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<am_SoundProperty_s>::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 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<am_ConnectionFormat_e>::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<am_MainSoundProperty_s>::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 CAmDatabaseHandler::changeSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + assert(sinkID!=0); + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command; + am_sinkClass_t sinkClassOut(sinkClassID); + std::vector<am_MainSoundProperty_s> 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<am_SoundProperty_s>::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<am_ConnectionFormat_e>::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<am_MainSoundProperty_s>::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 CAmDatabaseHandler::getListSinkMainNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& 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 notificationType, notificationStatus, notificationParameter FROM SinkMainNotificationConfiguration" + i2s(sinkID); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.notificationType = static_cast<am_NotificationType_e>(sqlite3_column_int(query, 0)); + temp.notificationStatus = static_cast<am_NotificationStatus_e>(sqlite3_column_int(query, 1)); + temp.notificationParameter= static_cast<int16_t>(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 CAmDatabaseHandler::getListSourceMainNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& 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 notificationType, notificationStatus, notificationParameter FROM SourceMainNotificationConfiguration" + i2s(sourceID); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.notificationType = static_cast<am_NotificationType_e>(sqlite3_column_int(query, 0)); + temp.notificationStatus = static_cast<am_NotificationStatus_e>(sqlite3_column_int(query, 1)); + temp.notificationParameter= static_cast<int16_t>(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 CAmDatabaseHandler::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 notificationStatus=?, notificationParameter=? WHERE notificationType=" + i2s(mainNotificationConfiguration.notificationType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.notificationStatus) + MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.notificationParameter) + 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.notificationType, "to status=", mainNotificationConfiguration.notificationStatus, "and parameter=",mainNotificationConfiguration.notificationParameter); + + if (mpDatabaseObserver) + mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration); + return (E_OK); +} + +am_Error_e CAmDatabaseHandler::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 notificationStatus=?, notificationParameter=? WHERE notificationType=" + i2s(mainNotificationConfiguration.notificationType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + MY_SQLITE_BIND_INT(query, 1, mainNotificationConfiguration.notificationStatus) + MY_SQLITE_BIND_INT(query, 2, mainNotificationConfiguration.notificationParameter) + 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.notificationType, "to status=", mainNotificationConfiguration.notificationStatus, "and parameter=",mainNotificationConfiguration.notificationParameter); + + if (mpDatabaseObserver) + mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration); + return (E_OK); +} + +am_Error_e CAmDatabaseHandler::changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFormats, const std::vector<bool> 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<am_ConnectionFormat_e>::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<am_ConnectionFormat_e>::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 CAmDatabaseHandler::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 notificationStatus=?, notificationParameter=? WHERE notificationType=" + i2s(notificationConfiguration.notificationType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.notificationStatus) + MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.notificationParameter) + 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.notificationType, "to status=", notificationConfiguration.notificationStatus, "and parameter=",notificationConfiguration.notificationParameter); + + //todo:: inform obsever here... + return (E_OK); +} + +am_Error_e CAmDatabaseHandler::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 notificationStatus=?, notificationParameter=? WHERE notificationType=" + i2s(notificationConfiguration.notificationType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + MY_SQLITE_BIND_INT(query, 1, notificationConfiguration.notificationStatus) + MY_SQLITE_BIND_INT(query, 2, notificationConfiguration.notificationParameter) + 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.notificationType, "to status=", notificationConfiguration.notificationStatus, "and parameter=",notificationConfiguration.notificationParameter); + + //todo:: implement observer function + return (E_OK); +} + void CAmDatabaseHandler::createTables() { for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++) diff --git a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp index 426f5d2..506ec01 100644 --- a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp @@ -202,4 +202,27 @@ void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t m { mSerializer.asyncCall<CAmCommandSender, const am_mainConnectionID_t, const am_timeSync_t>(mCommandSender, &CAmCommandSender::cbTimingInformationChanged, mainConnection, time); } + +void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) +{ + if (visible) + mSerializer.asyncCall<CAmCommandSender, const am_sinkID_t, const am_sinkClass_t, const std::vector<am_MainSoundProperty_s> >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sinkID, sinkClassID, listMainSoundProperties); +} + +void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) +{ + if (visible) + mSerializer.asyncCall<CAmCommandSender, const am_sourceID_t, const am_sourceClass_t, const std::vector<am_MainSoundProperty_s> >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sourceID, sourceClassID, listMainSoundProperties); +} + +void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + mSerializer.asyncCall<CAmCommandSender, const am_sinkID_t, const am_NotificationConfiguration_s> (mCommandSender, &CAmCommandSender::cbSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration); +} + +void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ + mSerializer.asyncCall<CAmCommandSender, const am_sourceID_t, const am_NotificationConfiguration_s>(mCommandSender, &CAmCommandSender::cbSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration); +} + } diff --git a/AudioManagerDaemon/src/CAmDbusWrapper.cpp b/AudioManagerDaemon/src/CAmDbusWrapper.cpp index 23fc27e..89c6122 100644 --- a/AudioManagerDaemon/src/CAmDbusWrapper.cpp +++ b/AudioManagerDaemon/src/CAmDbusWrapper.cpp @@ -302,7 +302,6 @@ void CAmDbusWrapper::toogleWatchDelegate(DBusWatch *watch, void *userData) iterator = mMapHandleWatch.find(watch); if (iterator != mMapHandleWatch.end()) mpSocketHandler->updateEventFlags(iterator->second, event); - logInfo("DBusWrapper::toogleWatchDelegate watch was toggeled"); } dbus_bool_t CAmDbusWrapper::addTimeout(DBusTimeout *timeout, void* userData) @@ -337,7 +336,6 @@ dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userD //save timeout in Socket context userData = timeout; - logInfo("DBusWrapper::addTimeoutDelegate a timeout was added, timeout",localTimeout," handle ", *handle); return (true); } @@ -366,8 +364,7 @@ void CAmDbusWrapper::removeTimeoutDelegate(DBusTimeout *timeout, void* userData) } } delete handle; - logInfo("DBusWrapper::removeTimeoutDelegate a timeout was removed"); -} + } void CAmDbusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData) { @@ -446,12 +443,10 @@ void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) { mpSocketHandler->stopTimer(*handle); } - logInfo("DBusWrapper::toggleTimeoutDelegate was called"); } void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) { - logInfo("DBusWrapper::dbusTimerCallback was called"); assert(userData!=NULL); if (dbus_timeout_get_enabled((DBusTimeout*) userData)) { diff --git a/AudioManagerDaemon/src/CAmNodeStateCommunicator.cpp b/AudioManagerDaemon/src/CAmNodeStateCommunicator.cpp new file mode 100644 index 0000000..ce6fd62 --- /dev/null +++ b/AudioManagerDaemon/src/CAmNodeStateCommunicator.cpp @@ -0,0 +1,763 @@ +/** + * 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 2012 + * + * \file CAmNodeStateCommunicator.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmNodeStateCommunicator.h" +#include <assert.h> +#include <string> +#include <fstream> +#include <stdexcept> +#include "CAmControlSender.h" +#include "shared/CAmDbusWrapper.h" +#include "shared/CAmDltWrapper.h" +#include "config.h" + +namespace am +{ + +static DBusObjectPathVTable gObjectPathVTable; + +CAmNodeStateCommunicator::CAmNodeStateCommunicator(CAmDbusWrapper* iDbusWrapper) : + mpDbusWrapper(iDbusWrapper), // + mpControlSender(NULL), // + mpDBusConnection(NULL) +{ + assert(mpDbusWrapper); + logInfo("CAmNodeStateCommunicator::CAmNodeStateCommunicator started"); + + //save the DBusConnection + mpDbusWrapper->getDBusConnection(mpDBusConnection); + assert(mpDBusConnection!=NULL); + + //register the path and the callback for receiving messages + std::string path("LifeCycleConsumer"); + gObjectPathVTable.message_function=CAmNodeStateCommunicator::receiveCallback; + mpDbusWrapper->registerCallback(&gObjectPathVTable, path, this); + + //now we need to make sure we catch the signals from the NSM: + dbus_bus_add_match(mpDBusConnection, "type=\'signal\',path=\'/org/genivi/NodeStateManager\'", NULL); + if (!dbus_connection_add_filter(mpDBusConnection, CAmNodeStateCommunicator::signalCallback, this, NULL)) + { + logError("CAmNodeStateCommunicator::CAmNodeStateCommunicator not enought memory!"); + throw std::runtime_error("CAmNodeStateCommunicator::CAmNodeStateCommunicator not enought memory!"); + } + dbus_connection_flush(mpDBusConnection); +} + +CAmNodeStateCommunicator::~CAmNodeStateCommunicator() +{} + +/** retrieves the actual restartReason + * + * @param restartReason + * @return E_OK on success + */ +am_Error_e CAmNodeStateCommunicator::nsmGetRestartReasonProperty(NsmRestartReason_e& restartReason) +{ + int32_t answer(0); + am_Error_e error=readIntegerProperty("RestartReason",answer); + restartReason=static_cast<NsmRestartReason_e>(answer); + return(error); +} + +/** retrieves the actual shutdownreason + * + * @param ShutdownReason + * @return E_OK on success + */ +am_Error_e CAmNodeStateCommunicator::nsmGetShutdownReasonProperty(NsmShutdownReason_e& ShutdownReason) +{ + int32_t answer(0); + am_Error_e error=readIntegerProperty("ShutdownReason",answer); + ShutdownReason=static_cast<NsmShutdownReason_e>(answer); + return(error); +} + +/** retrieves the actual runnuing reason + * + * @param nsmRunningReason + * @return E_OK on success + */ +am_Error_e CAmNodeStateCommunicator::nsmGetRunningReasonProperty(NsmRunningReason_e& nsmRunningReason) +{ + int32_t answer(0); + am_Error_e error=readIntegerProperty("WakeUpReason",answer); + nsmRunningReason=static_cast<NsmRunningReason_e>(answer); + return(error); +} + +/** gets the node state + * + * @param nsmNodeState + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmGetNodeState(NsmNodeState_e& nsmNodeState) +{ + DBusError error; + dbus_error_init(&error); + + uint32_t nodeStateID; + uint32_t returnedError; + + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "GetNodeState"); + + if (!message) + { + logError("CAmNodeStateCommunicator::nsmGetNodeState dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + if (!reply) + { + logError("CAmNodeStateCommunicator::nsmGetNodeState failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &nodeStateID, DBUS_TYPE_INT32, &returnedError, DBUS_TYPE_INVALID)) + return (NsmErrorStatus_Dbus); + + dbus_message_unref(reply); + + nsmNodeState=static_cast<NsmNodeState_e>(nodeStateID); + return (static_cast<NsmErrorStatus_e>(returnedError)); +} + +/** gets the session state for a session and seatID + * + * @param sessionName the name of the session + * @param seatID the seatID + * @param sessionState + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmGetSessionState(const std::string& sessionName, const NsmSeat_e& seatID, NsmSessionState_e& sessionState) +{ + DBusError error; + dbus_error_init(&error); + DBusMessageIter iter; + + uint32_t returnedError; + int32_t BsessionState(0); + + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "GetSessionState"); + + if (!message) + { + logError("CAmNodeStateCommunicator::nsmGetSessionState dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + + dbus_message_iter_init_append(message, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &sessionName)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &seatID)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + if (!reply) + { + logError("CAmNodeStateCommunicator::nsmGetSessionState failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error, + DBUS_TYPE_INT32, &BsessionState, + DBUS_TYPE_INT32, &returnedError,DBUS_TYPE_INVALID)) + return (NsmErrorStatus_Dbus); + + dbus_message_unref(reply); + + sessionState=static_cast<NsmSessionState_e>(BsessionState); + return (static_cast<NsmErrorStatus_e>(returnedError)); +} + +/** gets the application mode + * + * @param applicationMode + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmGetApplicationMode(NsmApplicationMode_e& applicationMode) +{ + DBusError error; + dbus_error_init(&error); + + uint32_t BapplicationMode(0),returnedError(0); + + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "GetApplicationMode"); + + if (!message) + { + logError("CAmNodeStateCommunicator::nsmGetApplicationMode dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + if (!reply) + { + logError("CAmNodeStateCommunicator::nsmGetApplicationMode failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &BapplicationMode, DBUS_TYPE_INT32, &returnedError, DBUS_TYPE_INVALID)) + return (NsmErrorStatus_Dbus); + + dbus_message_unref(reply); + + applicationMode=static_cast<NsmApplicationMode_e>(BapplicationMode); + return (static_cast<NsmErrorStatus_e>(returnedError)); +} + +/** this function registers the AudioManager as shutdown client at the NSM + * for more information check the Nodestatemanager + * @param shutdownMode the shutdownmode you wish to set + * @param timeoutMs the timeout you need to have + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmRegisterShutdownClient(const uint32_t shutdownMode, const uint32_t timeoutMs) +{ + DBusError error; + DBusMessageIter iter; + dbus_error_init(&error); + int16_t returnError(0); + std::string path = std::string(DBUS_SERVICE_OBJECT_PATH) + "/LifeCycleConsumer"; + const char* charPath = path.c_str(); + const char* service =DBUS_SERVICE_PREFIX; + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "RegisterShutdownClient"); + + if (!message) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_iter_init_append(message, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &service)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &charPath)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &shutdownMode)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &timeoutMs)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + dbus_message_unref(message); + + if (!reply) + { + logError( "CAmRoutingDbusSend::send failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &returnError,DBUS_TYPE_INVALID)) + { + logError( "CAmRoutingDbusSend::send failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_unref(reply); + + return (static_cast<NsmErrorStatus_e>(returnError)); + +} + +/** this function unregisters the AudioManager as shutdown client at the NSM + * + * @param shutdownMode + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmUnRegisterShutdownClient(const uint32_t shutdownMode) +{ + DBusError error; + DBusMessageIter iter; + dbus_error_init(&error); + int16_t returnError(0); + std::string path = std::string(DBUS_SERVICE_OBJECT_PATH) + "/LifeCycleConsumer"; + const char* charPath = path.c_str(); + const char* service =DBUS_SERVICE_PREFIX; + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "UnRegisterShutdownClient"); + + if (!message) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_iter_init_append(message, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &service)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &charPath)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &shutdownMode)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient no more memory"); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + dbus_message_unref(message); + + if (!reply) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &returnError, DBUS_TYPE_INVALID)) + { + logError( "CAmNodeStateCommunicator::nsmRegisterShutdownClient failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_unref(reply); + + return (static_cast<NsmErrorStatus_e>(returnError)); +} + +/** returns the interface version + * + * @param version + * @return E_OK on success + */ +am_Error_e CAmNodeStateCommunicator::nsmGetInterfaceVersion(uint32_t& version) +{ + DBusError error; + dbus_error_init(&error); + + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "GetInterfaceVersion"); + + if (!message) + { + logError("CAmNodeStateCommunicator::nsmGetInterfaceVersion dbus error:", error.message); + return (E_UNKNOWN); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + + dbus_message_unref(message); + + if (!reply) + { + logError("CAmNodeStateCommunicator::nsmGetInterfaceVersion failed, dbus error", error.message); + return (E_UNKNOWN); + } + + if(!dbus_message_get_args(reply, &error, DBUS_TYPE_UINT32, &version, DBUS_TYPE_INVALID)) + { + logError("CAmNodeStateCommunicator::nsmGetInterfaceVersion failed, dbus error", error.message); + return (E_UNKNOWN); + } + + dbus_message_unref(reply); + + return (E_OK); +} + +/** sends out the Lifecycle request complete message + * + * @param RequestId + * @param status + * @return NsmErrorStatus_Ok on success + */ +NsmErrorStatus_e CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete(const uint32_t RequestId, const NsmErrorStatus_e status) +{ + DBusError error; + DBusMessageIter iter; + dbus_error_init(&error); + int16_t returnError(0); + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, NSM_INTERFACE, "LifecycleRequestComplete"); + + if (!message) + { + logError( "CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete dbus error:", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_iter_init_append(message, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &RequestId)) + { + logError( "CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete no more memory"); + return (NsmErrorStatus_Dbus); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32,&status)) + { + logError( "CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete no more memory"); + return (NsmErrorStatus_Dbus); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + dbus_message_unref(message); + + if (!reply) + { + logError( "CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + + if(!dbus_message_get_args(reply, &error,DBUS_TYPE_INT32, &returnError, DBUS_TYPE_INVALID)) + { + logError( "CAmNodeStateCommunicator::nsmSendLifecycleRequestComplete failed, dbus error", error.message); + return (NsmErrorStatus_Dbus); + } + dbus_message_unref(reply); + + return (static_cast<NsmErrorStatus_e>(returnError)); +} + +void CAmNodeStateCommunicator::registerControlSender(CAmControlSender* iControlSender) +{ + assert(iControlSender); + mpControlSender=iControlSender; +} + +DBusHandlerResult CAmNodeStateCommunicator::receiveCallback(DBusConnection* conn, DBusMessage* msg, void* user_data) +{ + CAmNodeStateCommunicator* instance = static_cast<CAmNodeStateCommunicator*>(user_data); + assert(instance); + return (instance->receiveCallbackDelegate(conn,msg)); +} + +DBusHandlerResult CAmNodeStateCommunicator::receiveCallbackDelegate(DBusConnection* conn, DBusMessage* msg) +{ + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) + { + sendIntrospection(conn, msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + else + { + DBusMessage * returnMessage; + dbus_uint16_t Request(0),RequestId(0); + //no introspection - ok. So we are only interested in out LifecycleRequest message... + std::string method(dbus_message_get_member(msg)); + if (method=="LifecycleRequest") + { + DBusMessageIter iter,replyIter; + if (!dbus_message_iter_init(msg, &iter)) + { + logError("CAmNodeStateCommunicator::receiveCallbackDelegate DBus Message has no arguments!"); + returnMessage = dbus_message_new_error(msg,DBUS_ERROR_INVALID_ARGS, "DBUS Message has no arguments!"); + sendMessage(returnMessage,msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_UINT32) + { + logError("CAmNodeStateCommunicator::receiveCallbackDelegate DBus Message has invalid arguments!"); + returnMessage = dbus_message_new_error(msg,DBUS_ERROR_INVALID_ARGS,"DBus argument is no uint16_t!"); + sendMessage(returnMessage,msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &Request); + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_UINT32) + { + logError("CAmNodeStateCommunicator::receiveCallbackDelegate DBus Message has invalid arguments!"); + returnMessage = dbus_message_new_error(msg,DBUS_ERROR_INVALID_ARGS,"DBus argument is no uint16_t!"); + sendMessage(returnMessage,msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &RequestId); + + assert(mpControlSender); + NsmErrorStatus_e returnError = mpControlSender->hookSystemLifecycleRequest(static_cast<uint32_t>(Request),static_cast<uint32_t>(RequestId)); + + returnMessage = dbus_message_new_method_return(msg); + + if (returnMessage == NULL) + { + logError("CAmNodeStateCommunicator::receiveCallbackDelegate Cannot allocate DBus message!"); + returnMessage = dbus_message_new_error(msg,DBUS_ERROR_NO_MEMORY,"Cannot create reply!"); + sendMessage(returnMessage,msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_init_append(returnMessage, &replyIter); + + if (!dbus_message_iter_append_basic(&replyIter, DBUS_TYPE_INT32, &returnError)) + { + logError("CAmNodeStateCommunicator::receiveCallbackDelegate Cannot allocate DBus message!"); + returnMessage = dbus_message_new_error(msg,DBUS_ERROR_NO_MEMORY,"Cannot create reply!"); + } + sendMessage(returnMessage,msg); + return (DBUS_HANDLER_RESULT_HANDLED); + } + } + return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + +void CAmNodeStateCommunicator::sendIntrospection(DBusConnection* conn, DBusMessage* msg) +{ + assert(conn != NULL); + assert(msg != NULL); + DBusMessage* reply; + DBusMessageIter args; + dbus_uint32_t serial = 0; + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + std::string fullpath(NSM_INTROSPECTION_FILE); + std::ifstream in(fullpath.c_str(), std::ifstream::in); + if (!in) + { + logError("IAmCommandReceiverShadow::sendIntrospection could not load xml file ",fullpath); + throw std::runtime_error("IAmCommandReceiverShadow::sendIntrospection Could not load introspecton XML"); + } + std::string introspect((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()); + const char* string = introspect.c_str(); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string)) + { + logError( "CAmNodeStateCommunicator::sendIntrospection DBUS handler Out Of Memory!"); + } + + // send the reply && flush the connection + if (!dbus_connection_send(conn, reply, &serial)) + { + logError( "CAmNodeStateCommunicator::sendIntrospection DBUS handler Out Of Memory!"); + } + dbus_connection_flush(conn); + + // free the reply + dbus_message_unref(reply); +} + +void CAmNodeStateCommunicator::sendMessage(DBusMessage* message, DBusMessage* origMessage) +{ + dbus_uint32_t serial = dbus_message_get_serial(origMessage); + + dbus_connection_send(mpDBusConnection, message, &serial); + dbus_connection_flush(mpDBusConnection); + dbus_message_unref(message); +} + +DBusHandlerResult CAmNodeStateCommunicator::signalCallback(DBusConnection* conn, DBusMessage* msg, void* user_data) +{ + (void) conn; + CAmNodeStateCommunicator* instance(static_cast<CAmNodeStateCommunicator*>(user_data)); + std::string interface = dbus_message_get_interface(msg); + std::string member = dbus_message_get_member(msg); + + if (interface=="org.genivi.NodeStateManager.Consumer") + { + if (member=="NodeState") + { + int32_t nodeState; + DBusMessageIter iter; + if (!dbus_message_iter_init(msg, &iter)) + { + logError("CAmNodeStateCommunicator::signalCallback NodeState DBus Message has no arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_INT32) + { + logError("CAmNodeStateCommunicator::signalCallback NodeState DBus Message has invalid arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &nodeState); + + logInfo("CAmNodeStateCommunicator::signalCallback got signal NodeState, with nodeState",nodeState); + + assert(instance->mpControlSender); + instance->mpControlSender->hookSystemNodeStateChanged(static_cast<NsmNodeState_e>(nodeState)); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + else if (member=="NodeApplicationMode") + { + int32_t nodeApplicationMode; + DBusMessageIter iter; + if (!dbus_message_iter_init(msg, &iter)) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has no arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_INT32) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has invalid arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &nodeApplicationMode); + + logInfo("CAmNodeStateCommunicator::signalCallback got signal nodeApplicationMode, with applicationMode",nodeApplicationMode); + + assert(instance->mpControlSender); + instance->mpControlSender->hookSystemNodeApplicationModeChanged(static_cast<NsmApplicationMode_e>(nodeApplicationMode)); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + else if (member=="SessionStateChanged") + { + std::string sessionName; + NsmSeat_e seatID; + NsmSessionState_e sessionState; + DBusMessageIter iter; + if (!dbus_message_iter_init(msg, &iter)) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has no arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_STRING) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has invalid arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + char * sessionNameChar; + dbus_message_iter_get_basic(&iter, &sessionNameChar); + sessionName=std::string(sessionNameChar); + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_INT32) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has invalid arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &seatID); + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter)!=DBUS_TYPE_INT32) + { + logError("CAmNodeStateCommunicator::signalCallback nodeApplicationMode DBus Message has invalid arguments!"); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + dbus_message_iter_get_basic(&iter, &sessionState); + + + logInfo("CAmNodeStateCommunicator::signalCallback got signal sessionStateChanged, with session",sessionName,"seatID=",seatID,"sessionState",sessionState); + + assert(instance->mpControlSender); + instance->mpControlSender->hookSystemSessionStateChanged(sessionName,seatID,sessionState); + return (DBUS_HANDLER_RESULT_HANDLED); + } + + else + { + return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + } + } + else + { + return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + } + printf("asdasdas\n"); + return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + +am_Error_e CAmNodeStateCommunicator::readIntegerProperty(const std::string property, int32_t& value) +{ + DBusError error; + dbus_error_init(&error); + DBusMessageIter iter,iterVariant; + + DBusMessage * message = dbus_message_new_method_call(NSM_BUS_INTERFACE, NSM_PATH, "org.freedesktop.DBus.Properties", "Get"); + + if (!message) + { + logError("CAmNodeStateCommunicator::readIntegerProperty dbus error:", error.message); + return (E_UNKNOWN); + } + + + dbus_message_iter_init_append(message, &iter); + const char *interface=std::string(NSM_INTERFACE).c_str(); + const char *propertyChar=property.c_str(); + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface)) + { + logError("CAmNodeStateCommunicator::readIntegerProperty append error"); + return (E_UNKNOWN); + } + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &propertyChar)) + { + logError("CAmNodeStateCommunicator::readIntegerProperty append error"); + return (E_UNKNOWN); + } + + DBusMessage* reply(dbus_connection_send_with_reply_and_block(mpDBusConnection, message, -1, &error)); + if (!reply) + { + logError("CAmNodeStateCommunicator::readIntegerProperty failed, dbus error", error.message); + return (E_UNKNOWN); + } + + dbus_message_iter_init(reply,&iterVariant); + if (dbus_message_iter_get_arg_type (&iterVariant)!= DBUS_TYPE_VARIANT) + { + logError("CAmNodeStateCommunicator::readIntegerProperty failed, dbus return type wrong"); + return (E_UNKNOWN); + } + DBusMessageIter subiter; + dbus_message_iter_recurse (&iterVariant, &subiter); + if (dbus_message_iter_get_arg_type (&subiter)!= DBUS_TYPE_INT32) + { + logError("CAmNodeStateCommunicator::readIntegerProperty failed, dbus return type wrong"); + return (E_UNKNOWN); + } + + dbus_message_iter_get_basic(&subiter,&value); + dbus_message_unref(reply); + + return (E_OK); +} + +} /* namespace am */ diff --git a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp index f0821a9..f1f0e09 100644 --- a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp +++ b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp @@ -41,7 +41,9 @@ CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm mListRundownHandles(), // handleCount(0), // mWaitStartup(false), // - mWaitRundown(false) + mWaitRundown(false), // + mLastStartupError(E_OK), // + mLastRundownError(E_OK) // { assert(mpDatabaseHandler!=NULL); assert(mpRoutingSender!=NULL); @@ -59,7 +61,9 @@ CAmRoutingReceiver::CAmRoutingReceiver(CAmDatabaseHandler *iDatabaseHandler, CAm mListRundownHandles(), // handleCount(0), // mWaitStartup(false), // - mWaitRundown(false) + mWaitRundown(false), + mLastStartupError(E_OK), // + mLastRundownError(E_OK) // { assert(mpDatabaseHandler!=NULL); assert(mpRoutingSender!=NULL); @@ -345,18 +349,22 @@ void CAmRoutingReceiver::getInterfaceVersion(std::string & version) const version = RoutingReceiveVersion; } -void CAmRoutingReceiver::confirmRoutingReady(const uint16_t handle) +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(); + mpControlSender->confirmRoutingReady(mLastStartupError); } -void CAmRoutingReceiver::confirmRoutingRundown(const uint16_t handle) +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(); + mpControlSender->confirmRoutingRundown(mLastRundownError); } uint16_t am::CAmRoutingReceiver::getStartupHandle() @@ -376,11 +384,88 @@ uint16_t am::CAmRoutingReceiver::getRundownHandle() void am::CAmRoutingReceiver::waitOnStartup(bool startup) { mWaitStartup = startup; + mLastStartupError=E_OK; +} + +am_Error_e CAmRoutingReceiver::updateGateway(const am_gatewayID_t gatewayID, std::vector<am_ConnectionFormat_e> listSourceFormats, const std::vector<am_ConnectionFormat_e> listSinkFormats, std::vector<bool> convertionMatrix) +{ + return (mpControlSender->hookSystemUpdateGateway(gatewayID,listSourceFormats,listSinkFormats,convertionMatrix)); +} + +am_Error_e CAmRoutingReceiver::updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + return (mpControlSender->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +am_Error_e CAmRoutingReceiver::updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, std::vector<am_SoundProperty_s> listSoundProperties, std::vector<am_ConnectionFormat_e> listConnectionFormats, const std::vector<am_MainSoundProperty_s> listMainSoundProperties) +{ + return (mpControlSender->hookSystemUpdateSource(sourceID,sourceClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties)); +} + +void CAmRoutingReceiver::ackSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s> listvolumes, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mpRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.volumeID.sink != 0) + { + std::vector<am_Volumes_s>::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); + } + } + + } + mpRoutingSender->removeHandle(handle); + mpControlSender->cbAckSetVolume(handle,listvolumes,error); +} + +void CAmRoutingReceiver::ackSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mpRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sinkID != 0) + { + mpDatabaseHandler->changeSinkNotificationConfigurationDB(handleData.sinkID,*handleData.notificationConfiguration); + delete handleData.notificationConfiguration; + } + mpRoutingSender->removeHandle(handle); + mpControlSender->cbAckSetSinkNotificationConfiguration(handle,error); +} + +void CAmRoutingReceiver::ackSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) +{ + CAmRoutingSender::am_handleData_c handleData = mpRoutingSender->returnHandleData(handle); + if (error == E_OK && handleData.sourceID != 0) + { + mpDatabaseHandler->changeSourceNotificationConfigurationDB(handleData.sourceID,*handleData.notificationConfiguration); + delete handleData.notificationConfiguration; + } + mpRoutingSender->removeHandle(handle); + mpControlSender->cbAckSetSourceNotificationConfiguration(handle,error); +} + +void CAmRoutingReceiver::hookSinkNotificationDataChange(const am_sinkID_t sinkID, const am_NotificationPayload_s payload) +{ + logInfo("CAmRoutingReceiver::hookSinkNotificationDataChange received, sinkID=",sinkID,"notificationType=",payload.notificationType,"notificationValue=",payload.notificationValue); + mpControlSender->hookSinkNotificationDataChanged(sinkID,payload); +} + +void CAmRoutingReceiver::hookSourceNotificationDataChange(const am_sourceID_t sourceID, const am_NotificationPayload_s payload) +{ + logInfo("CAmRoutingReceiver::hookSourceNotificationDataChange received, sinkID=",sourceID,"notificationType=",payload.notificationType,"notificationValue=",payload.notificationValue); + mpControlSender->hookSourceNotificationDataChanged(sourceID,payload); } void am::CAmRoutingReceiver::waitOnRundown(bool rundown) { mWaitRundown = rundown; + mLastRundownError=E_OK; } am_Error_e CAmRoutingSender::removeConnectionLookup(const am_connectionID_t connectionID) diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp index f45f918..57892c7 100644 --- a/AudioManagerDaemon/src/CAmRoutingSender.cpp +++ b/AudioManagerDaemon/src/CAmRoutingSender.cpp @@ -596,6 +596,78 @@ void CAmRoutingSender::setRoutingRundown() } } +am_Error_e CAmRoutingSender::asyncSetVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s>& 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<am_Volumes_s>(listVolumes); + handle = createHandle(handleData, H_SETVOLUMES); + + mMapHandleInterface.insert(std::make_pair(+ handle.handle, pRoutingInterface)); + return (pRoutingInterface->asyncSetVolumes(handle, listVolumes)); +} + +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)); + return (iter->second->asyncSetSinkNotificationConfiguration(handle, sinkID,notificationConfiguration)); + } + 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)); + return (iter->second->asyncSetSourceNotificationConfiguration(handle, sourceID,notificationConfiguration)); + } + return (E_NON_EXISTENT); +} + void CAmRoutingSender::unloadLibraries(void) { std::vector<void*>::iterator iterator = mListLibraryHandles.begin(); diff --git a/AudioManagerDaemon/src/CAmSocketHandler.cpp b/AudioManagerDaemon/src/CAmSocketHandler.cpp index f7c4ace..19d61c0 100644 --- a/AudioManagerDaemon/src/CAmSocketHandler.cpp +++ b/AudioManagerDaemon/src/CAmSocketHandler.cpp @@ -34,9 +34,9 @@ namespace am { -CAmSocketHandler* CAmSocketHandler::mInstance=NULL; - CAmSocketHandler::CAmSocketHandler() : + receiverCallbackT(this, &CAmSocketHandler::receiverCallback),// + checkerCallbackT(this, &CAmSocketHandler::checkerCallback),// mPipe(), mListPoll(), // mListTimer(), // @@ -44,12 +44,9 @@ CAmSocketHandler::CAmSocketHandler() : mLastInsertedHandle(0), // mLastInsertedPollHandle(0), // mRecreatePollfds(true), // - mStartTime(), // - receiverCallbackT(this, &CAmSocketHandler::receiverCallback),// - checkerCallbackT(this, &CAmSocketHandler::checkerCallback)// + mStartTime() // { gDispatchDone = 1; - mInstance=this; if (pipe(mPipe) == -1) { @@ -527,14 +524,6 @@ void CAmSocketHandler::exit_mainloop() write(mPipe[1], &p, sizeof(p)); } -void CAmSocketHandler::static_exit_mainloop() -{ - if (mInstance!=0) - { - mInstance->exit_mainloop(); - } -} - /** * is used to set the pointer for the ppoll command * @param buffertime diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp index d820351..87f9659 100644 --- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp +++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp @@ -1235,7 +1235,6 @@ void CAmTelnetMenuHelper::setSinkVolumeExec(std::queue<std::string>& CmdQueue, i { am_volume_t volume = 0; am_sinkID_t sinkID = 0; - am_Handle_s handle; bool error = false; std::istringstream istream_sinkID(CmdQueue.front()); CmdQueue.pop(); diff --git a/AudioManagerDaemon/src/CAmWatchdog.cpp b/AudioManagerDaemon/src/CAmWatchdog.cpp index 15c7dcc..db34009 100755 --- a/AudioManagerDaemon/src/CAmWatchdog.cpp +++ b/AudioManagerDaemon/src/CAmWatchdog.cpp @@ -91,7 +91,6 @@ void CAmWatchdog::timerCallback(sh_timerHandle_t handle, void* userData) } mpCAmSocketHandler->restartTimer(handle); - logInfo("restarted watchdog "); } void CAmWatchdog::startWatchdog() diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index 6b84ba3..51003cf 100755 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -57,6 +57,7 @@ #include "CAmControlReceiver.h" #include "CAmDatabaseObserver.h" #include "CAmWatchdog.h" +#include "CAmNodeStateCommunicator.h" #include "shared/CAmDltWrapper.h" #include "shared/CAmSocketHandler.h" @@ -265,15 +266,32 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context) (void) siginfo; (void) context; logInfo("signal handler was called, signal",sig); - //todo: maually fire the mainloop - CAmControlSender::CallsetControllerRundown(); - //deinit the DLT - CAmDltWrapper* inst(getWrapper()); - inst->deinit(); + switch (sig) + { + /*ctl +c lets call direct controllerRundown, because we might be blocked at the moment. + But there is the risk of interrupting something important */ + case SIGINT: + CAmControlSender::CallsetControllerRundown(sig); + break; - CAmSocketHandler::static_exit_mainloop(); + /* huch- we are getting killed. Better take the fast but risky way: */ + case SIGQUIT: + CAmControlSender::CallsetControllerRundown(sig); + break; + + /* more friendly here assuming systemd wants to stop us, so we can use the mainloop */ + case SIGTERM: + CAmControlSender::CallsetControllerRundownSafe(sig); + break; + /* looks friendly, too, so lets take the long run */ + case SIGHUP: + CAmControlSender::CallsetControllerRundownSafe(sig); + break; + default: + break; + } } void mainProgram() @@ -283,6 +301,7 @@ void mainProgram() #ifdef WITH_DBUS_WRAPPER CAmDbusWrapper iDBusWrapper(&iSocketHandler,dbusWrapperType); + CAmNodeStateCommunicator iNodeStateCommunicator(&iDBusWrapper); #endif /*WITH_DBUS_WRAPPER */ #ifdef WITH_SYSTEMD_WATCHDOG @@ -292,19 +311,21 @@ void mainProgram() CAmDatabaseHandler iDatabaseHandler(databasePath); CAmRoutingSender iRoutingSender(listRoutingPluginDirs); CAmCommandSender iCommandSender(listCommandPluginDirs); - CAmControlSender iControlSender(controllerPlugin); + CAmControlSender iControlSender(controllerPlugin,&iSocketHandler); CAmRouter iRouter(&iDatabaseHandler, &iControlSender); #ifdef WITH_DBUS_WRAPPER CAmCommandReceiver iCommandReceiver(&iDatabaseHandler, &iControlSender, &iSocketHandler, &iDBusWrapper); CAmRoutingReceiver iRoutingReceiver(&iDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper); - CAmControlReceiver iControlReceiver(&iDatabaseHandler, &iRoutingSender, &iCommandSender, &iSocketHandler, &iRouter); + CAmControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter, &iNodeStateCommunicator); + iNodeStateCommunicator.registerControlSender(&iControlSender); #else /*WITH_DBUS_WRAPPER*/ CAmCommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler); CAmRoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler); CAmControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter); #endif /*WITH_DBUS_WRAPPER*/ + #ifdef WITH_TELNET CAmTelnetServer iTelnetServer(&iSocketHandler, &iCommandSender, &iCommandReceiver, &iRoutingSender, &iRoutingReceiver, &iControlSender, &iControlReceiver, &iDatabaseHandler, &iRouter, telnetport, maxConnections); CAmDatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer); @@ -378,13 +399,18 @@ int main(int argc, char *argv[], char** envp) catch (std::exception& exc) { logError("The AudioManager ended by throwing the exception", exc.what()); - //todo: ergency exit here... call destructors etc... + std::cerr<<"The AudioManager ended by throwing an exception "<<exc.what()<<std::endl; exit(EXIT_FAILURE); } close(fd0); close(fd1); close(fd2); + + //deinit the DLT + CAmDltWrapper* inst(getWrapper()); + inst->deinit(); + exit(0); } diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp index c4f71e1..b126efc 100644 --- a/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp +++ b/AudioManagerDaemon/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp @@ -43,7 +43,7 @@ CAmControlInterfaceTest::CAmControlInterfaceTest() : pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // pControlInterfaceBackdoor(), // - pControlSender(std::string("")), // + pControlSender(), // pRouter(&pDatabaseHandler,&pControlSender), // pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // diff --git a/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt b/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt index 8d4b2e9..6107389 100644 --- a/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmControlInterfaceTest/CMakeLists.txt @@ -54,6 +54,8 @@ file(GLOB CONTROL_INTERFACE_SRCS_CXX "../../src/CAmDltWrapper.cpp" "../../src/CAmSocketHandler.cpp" "../../src/CAmCommandReceiver.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmDbusWrapper.cpp" "../CAmCommonFunctions.cpp" "*.cpp" ) diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp index a1b7e39..a5143ef 100644 --- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp +++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp @@ -45,7 +45,7 @@ CAmDatabaseHandlerTest::CAmDatabaseHandlerTest() : pMockInterface(), // pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // - pControlSender(""), // + pControlSender(), // pRouter(&pDatabaseHandler, &pControlSender), // pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) @@ -1915,6 +1915,285 @@ TEST_F(CAmDatabaseHandlerTest,enterSinksCorrect) ASSERT_EQ(true, equal); } +TEST_F(CAmDatabaseHandlerTest,enterNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=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.begin()->notificationParameter,notify.notificationParameter); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations.begin()->notificationStatus,notify.notificationStatus); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations.begin()->notificationType,notify.notificationType); +} + +TEST_F(CAmDatabaseHandlerTest,enterMainNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=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.begin()->notificationParameter,notify.notificationParameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations.begin()->notificationStatus,notify.notificationStatus); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations.begin()->notificationType,notify.notificationType); +} + +TEST_F(CAmDatabaseHandlerTest,removeNotifications) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=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.begin()->notificationParameter,notify.notificationParameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations.begin()->notificationStatus,notify.notificationStatus); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations.begin()->notificationType,notify.notificationType); + + //now we remove the sink + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)); +} + +TEST_F(CAmDatabaseHandlerTest,getMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.notificationType=NT_MAX; + notify1.notificationStatus=NS_PERIODIC; + notify1.notificationParameter=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.getListSinkMainNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(returnList[0].notificationParameter,notify.notificationParameter); + ASSERT_EQ(returnList[0].notificationStatus,notify.notificationStatus); + ASSERT_EQ(returnList[0].notificationType,notify.notificationType); + + ASSERT_EQ(returnList[1].notificationParameter,notify1.notificationParameter); + ASSERT_EQ(returnList[1].notificationStatus,notify1.notificationStatus); + ASSERT_EQ(returnList[1].notificationType,notify1.notificationType); + +} + +TEST_F(CAmDatabaseHandlerTest,getMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.notificationType=NT_MAX; + notify1.notificationStatus=NS_PERIODIC; + notify1.notificationParameter=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.getListSourceMainNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(returnList[0].notificationParameter,notify.notificationParameter); + ASSERT_EQ(returnList[0].notificationStatus,notify.notificationStatus); + ASSERT_EQ(returnList[0].notificationType,notify.notificationType); + + ASSERT_EQ(returnList[1].notificationParameter,notify1.notificationParameter); + ASSERT_EQ(returnList[1].notificationStatus,notify1.notificationStatus); + ASSERT_EQ(returnList[1].notificationType,notify1.notificationType); + +} + +TEST_F(CAmDatabaseHandlerTest,changeMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + std::vector<am_NotificationConfiguration_s>returnList,returnList1; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.notificationType=NT_MAX; + notify1.notificationStatus=NS_PERIODIC; + notify1.notificationParameter=5; + + am_NotificationConfiguration_s notify2; + notify2.notificationType=NT_MAX; + notify2.notificationStatus=NS_CHANGE; + notify2.notificationParameter=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.getListSourceMainNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(returnList[0].notificationParameter,notify.notificationParameter); + ASSERT_EQ(returnList[0].notificationStatus,notify.notificationStatus); + ASSERT_EQ(returnList[0].notificationType,notify.notificationType); + + ASSERT_EQ(returnList[1].notificationParameter,notify1.notificationParameter); + ASSERT_EQ(returnList[1].notificationStatus,notify1.notificationStatus); + ASSERT_EQ(returnList[1].notificationType,notify1.notificationType); + + //change a setting + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2)); + + ASSERT_EQ(E_OK,pDatabaseHandler.getListSourceMainNotificationConfigurations(sourceID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].notificationParameter,notify2.notificationParameter); + ASSERT_EQ(returnList1[1].notificationStatus,notify2.notificationStatus); + ASSERT_EQ(returnList1[1].notificationType,notify2.notificationType); + +} + +TEST_F(CAmDatabaseHandlerTest,changeMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + std::vector<am_NotificationConfiguration_s>returnList,returnList1; + + am_NotificationConfiguration_s notify; + notify.notificationType=NT_UNKNOWN; + notify.notificationStatus=NS_CHANGE; + notify.notificationParameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.notificationType=NT_MAX; + notify1.notificationStatus=NS_PERIODIC; + notify1.notificationParameter=5; + + am_NotificationConfiguration_s notify2; + notify2.notificationType=NT_MAX; + notify2.notificationStatus=NS_CHANGE; + notify2.notificationParameter=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.getListSinkMainNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(returnList[0].notificationParameter,notify.notificationParameter); + ASSERT_EQ(returnList[0].notificationStatus,notify.notificationStatus); + ASSERT_EQ(returnList[0].notificationType,notify.notificationType); + + ASSERT_EQ(returnList[1].notificationParameter,notify1.notificationParameter); + ASSERT_EQ(returnList[1].notificationStatus,notify1.notificationStatus); + ASSERT_EQ(returnList[1].notificationType,notify1.notificationType); + + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)) + << "ERROR: database error"; + + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinkMainNotificationConfigurations(sinkID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].notificationParameter,notify2.notificationParameter); + ASSERT_EQ(returnList1[1].notificationStatus,notify2.notificationStatus); + ASSERT_EQ(returnList1[1].notificationType,notify2.notificationType); +} + //Commented out - gives always a warning.. //TEST_F(databaseTest,registerDomainFailonID0) //{ diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt index 184a50d..24f79be 100644 --- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CMakeLists.txt @@ -55,6 +55,8 @@ file(GLOB DATABASE_SRCS_CXX "../../src/CAmSocketHandler.cpp" "../../src/CAmCommandReceiver.cpp" "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmDbusWrapper.cpp" "../CAmCommonFunctions.cpp" "*.cpp" ) diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.cpp b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.cpp new file mode 100644 index 0000000..0624ff4 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.cpp @@ -0,0 +1,240 @@ +/** + * 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 2012 + * + * \file CAmNodeStateCommunicatorTest.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmNodeStateCommunicatorTest.h" +#include <Python.h> +#include "shared/CAmDltWrapper.h" +#include "shared/CAmSocketHandler.h" +#include "shared/CAmDbusWrapper.h" + +using namespace testing; +using namespace am; + +static CAmEnvironment* env; + +CAmNodeStateCommunicatorTest::CAmNodeStateCommunicatorTest() +{ +} + +CAmNodeStateCommunicatorTest::~CAmNodeStateCommunicatorTest() +{ + // TODO Auto-generated destructor stub +} + +/**This is the thread for the nsm python fake + * + * @param + */ +void* nsmThread (void*) +{ + system("python nsm.py"); + return (NULL); +} + +/**this is the thread the mainloop runs in + * + * @param importHandler + */ +void* mainLoop(void* importHandler) +{ + CAmSocketHandler* handler=static_cast<CAmSocketHandler*>(importHandler); + handler->start_listenting(); + return (NULL); +} + + + +TEST_F(CAmNodeStateCommunicatorTest, nsmChangeNodeState) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmNodeState_e newstate(NsmNodeState_BaseRunning) ; + EXPECT_CALL(pMockControlInterface,hookSystemNodeStateChanged(newstate)); + std::ostringstream send; + send<<"python send2nsm.py nodeState "<<static_cast<std::int32_t>(newstate); + system(send.str().c_str()); +} + +TEST_F(CAmNodeStateCommunicatorTest, nsmChangeApplicationMode) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmApplicationMode_e appmode(NsmApplicationMode_Swl) ; + EXPECT_CALL(pMockControlInterface,hookSystemNodeApplicationModeChanged(appmode)); + std::ostringstream send; + send<<"python send2nsm.py appMode "<<static_cast<std::int32_t>(appmode); + system(send.str().c_str()); +} + +TEST_F(CAmNodeStateCommunicatorTest, nsmChangeSessionState) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + std::string sessionName("mySession"); + NsmSeat_e seatID(NsmSeat_CoDriver); + NsmSessionState_e sessionState(NsmSessionState_Inactive) ; + EXPECT_CALL(pMockControlInterface,hookSystemSessionStateChanged(sessionName,seatID,sessionState)); + std::ostringstream send; + send<<"python send2nsm.py sessionState "<<sessionName<<" "<<static_cast<std::int32_t>(seatID)<<" "<<static_cast<int32_t>(sessionState); + system(send.str().c_str()); +} + +TEST_F(CAmNodeStateCommunicatorTest, getRestartReason) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmRestartReason_e restartReason; + ASSERT_EQ(E_OK,env->nsmController.nsmGetRestartReasonProperty(restartReason)); + ASSERT_EQ(restartReason,1); +} + +TEST_F(CAmNodeStateCommunicatorTest, getShutdownReason) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmShutdownReason_e ShutdownReason; + ASSERT_EQ(E_OK,env->nsmController.nsmGetShutdownReasonProperty(ShutdownReason)); + ASSERT_EQ(ShutdownReason,2); +} + +TEST_F(CAmNodeStateCommunicatorTest, getWakeUpReason) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmRunningReason_e WakeUpReason; + ASSERT_EQ(E_OK,env->nsmController.nsmGetRunningReasonProperty(WakeUpReason)); + ASSERT_EQ(WakeUpReason,3); +} + +TEST_F(CAmNodeStateCommunicatorTest, getNodeState) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmNodeState_e nodeState; + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmGetNodeState(nodeState)); + ASSERT_EQ(nodeState,1); +} + +TEST_F(CAmNodeStateCommunicatorTest, getApplicationMode) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + NsmApplicationMode_e applicationMode; + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Error,env->nsmController.nsmGetApplicationMode(applicationMode)); + ASSERT_EQ(applicationMode,5); +} + +TEST_F(CAmNodeStateCommunicatorTest, getSessionState) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + std::string sessionName("mySession"); + NsmSeat_e seatID(NsmSeat_Driver); + NsmSessionState_e sessionState; + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmGetSessionState(sessionName,seatID,sessionState)); + ASSERT_EQ(sessionState,5); +} + +TEST_F(CAmNodeStateCommunicatorTest, RegisterShutdownClient) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + uint32_t shutdownmode(1), timeoutMs(100); + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmRegisterShutdownClient(shutdownmode,timeoutMs)); +} + +TEST_F(CAmNodeStateCommunicatorTest, receiveLifecycleRequest) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + uint32_t shutdownmode(1),timeoutMs(100),Request(1),RequestID(4); + EXPECT_CALL(pMockControlInterface,hookSystemLifecycleRequest(Request,RequestID)).WillOnce(Return(NsmErrorStatus_e::NsmErrorStatus_Ok)); + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmRegisterShutdownClient(shutdownmode,timeoutMs)); + std::ostringstream send; + send << "python send2nsm.py LifecycleRequest "<<static_cast<std::int32_t>(Request)<<" "<<static_cast<int32_t>(RequestID); + system(send.str().c_str()); +} + +TEST_F(CAmNodeStateCommunicatorTest, UnRegisterShutdownClient) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + uint32_t shutdownmode(1),timeoutMs(100); + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmRegisterShutdownClient(shutdownmode,timeoutMs)); + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmUnRegisterShutdownClient(shutdownmode)); + +} + +TEST_F(CAmNodeStateCommunicatorTest, sendLifecycleRequestComplete) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + uint32_t RequestID(22); + NsmErrorStatus_e errorStatus(NsmErrorStatus_Internal); + ASSERT_EQ(NsmErrorStatus_e::NsmErrorStatus_Ok,env->nsmController.nsmSendLifecycleRequestComplete(RequestID,errorStatus)); +} + +TEST_F(CAmNodeStateCommunicatorTest, getInterfaceVersion) +{ + env->pControlInterfaceBackdoor.replaceController(&env->pControlSender,&pMockControlInterface); + uint32_t version(0); + ASSERT_EQ(E_OK,env->nsmController.nsmGetInterfaceVersion(version)); + ASSERT_EQ(version,static_cast<uint32_t>(23)); +} + +void CAmNodeStateCommunicatorTest::SetUp() +{ +} + +void CAmNodeStateCommunicatorTest::TearDown() +{ +} + +int main(int argc, char **argv) +{ + CAmDltWrapper::instance()->registerApp("nsm", "nsmtest"); + logInfo("nsmtest Test started "); + ::testing::InitGoogleTest(&argc, argv); + ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new CAmEnvironment); + (void) env; + return RUN_ALL_TESTS(); +} + +CAmEnvironment::CAmEnvironment() : + pControlInterfaceBackdoor(), + pControlSender(), + iSocketHandler(), + wrapper(&iSocketHandler,DBusBusType::DBUS_BUS_SESSION), + nsmController(&wrapper) +{ + env=this; +} + +CAmEnvironment::~CAmEnvironment() +{ +} + +void CAmEnvironment::SetUp() +{ + //create the nsm thread + pthread_create(&pNsmThread, NULL, nsmThread, NULL); + nsmController.registerControlSender(&pControlSender); + //create the mainloop thread + pthread_create(&pMainLoopThread, NULL, mainLoop, (void*)&iSocketHandler); + sleep(1); +} + +void CAmEnvironment::TearDown() +{ + //end the nsm per dbus + system("python send2nsm.py finish"); + pthread_join(pNsmThread, NULL); + //end the mainloop + iSocketHandler.exit_mainloop(); + pthread_join(pMainLoopThread, NULL); +} diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.h b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.h new file mode 100644 index 0000000..bd83e97 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CAmNodeStateCommunicatorTest.h @@ -0,0 +1,61 @@ +/** + * 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 2012 + * + * \file CAmNodeStateCommunicatorTest.h + * For further information see http://www.genivi.org/. + * + */ +#ifndef CAMNODESTATECOMMUNICATORTEST_H_ +#define CAMNODESTATECOMMUNICATORTEST_H_ + +#include "CAmNodeStateCommunicator.h" +#include "CAmControlSender.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../IAmControlBackdoor.h" +#include "../MockIAmControlSend.h" + +using namespace testing; +using namespace am; + +class CAmEnvironment : public ::testing::Environment +{ +public: + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlSender pControlSender; + CAmSocketHandler iSocketHandler; + CAmDbusWrapper wrapper; + CAmNodeStateCommunicator nsmController; + pthread_t pNsmThread, pMainLoopThread; + CAmEnvironment(); + ~CAmEnvironment(); + void SetUp(); + // Override this to define how to tear down the environment. + void TearDown(); +}; + +class CAmNodeStateCommunicatorTest:public ::testing::Test +{ +public: + MockIAmControlSend pMockControlInterface; + CAmNodeStateCommunicatorTest(); + virtual ~CAmNodeStateCommunicatorTest(); + void SetUp(); + void TearDown(); +}; + + +#endif /* CAMNODESTATECOMMUNICATORTEST_H_ */ diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CMakeLists.txt b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CMakeLists.txt new file mode 100644 index 0000000..4300e49 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/CMakeLists.txt @@ -0,0 +1,112 @@ +# Copyright (c) 2012 GENIVI Alliance +# Copyright (c) 2012 BMW +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# copyright +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +# THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 2.6) + +PROJECT(AmNodeStateCommunicatorTest) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1") + +set(STD_INCLUDE_DIRS "/usr/include") +set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) + +FIND_PACKAGE(Threads) +FIND_PACKAGE(DBUS REQUIRED) +FIND_PACKAGE(PkgConfig) +FIND_PACKAGE(PythonLibs REQUIRED) +pkg_check_modules(SQLITE REQUIRED sqlite3) + + +IF(WITH_DLT) + pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0) +ENDIF(WITH_DLT) + +INCLUDE_DIRECTORIES( + ${STD_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${AUDIO_INCLUDE_FOLDER} + ${DBUS_ARCH_INCLUDE_DIR} + ${DBUS_INCLUDE_FOLDER} + ${CMAKE_SOURCE_DIR} + ${DLT_INCLUDE_DIRS} + ${DBUS_INCLUDE_DIR} + ${INCLUDE_FOLDER} + ${PYTHON_INCLUDE_DIRS} + ${GOOGLE_TEST_INCLUDE_DIR} + ${GMOCK_INCLUDE_DIR} + "../../include" +) + +file(GLOB NODESTATECOMMUNICATOR + "../../src/CAmDatabaseHandler.cpp" + "../../src/CAmDatabaseObserver.cpp" + "../../src/CAmRoutingSender.cpp" + "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmDbusWrapper.cpp" + "../../src/CAmDltWrapper.cpp" + "../../src/CAmSocketHandler.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmControlSender.cpp" + "../../src/CAmCommandSender.cpp" + "../../src/CAmCommandReceiver.cpp" + "../CAmCommonFunctions.cpp" + "../../src/CAmRouter.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE(AmNodeStateCommunicatorTest ${NODESTATECOMMUNICATOR}) + +TARGET_LINK_LIBRARIES(AmNodeStateCommunicatorTest + ${SQLITE_LIBRARIES} + ${DLT_LIBRARIES} + ${DBUS_LIBRARY} + ${CMAKE_DL_LIBS} + ${CMAKE_THREAD_LIBS_INIT} + ${PYTHON_LIBRARY} + gtest + gmock +) + +ADD_DEPENDENCIES(AmNodeStateCommunicatorTest gtest gmock) + +INSTALL(TARGETS AmNodeStateCommunicatorTest + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/org.genivi.NodeStateManager.Consumer.xml + ${CMAKE_CURRENT_SOURCE_DIR}/nsm.py + ${CMAKE_CURRENT_SOURCE_DIR}/send2nsm.py + DESTINATION "~/AudioManagerTest/" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + +IF(USE_BUILD_LIBS) + execute_process( + COMMAND mkdir -p "${EXECUTABLE_OUTPUT_PATH}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/org.genivi.NodeStateManager.Consumer.xml" ${EXECUTABLE_OUTPUT_PATH}/org.genivi.NodeStateManager.Consumer.xml + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/nsm.py" ${EXECUTABLE_OUTPUT_PATH}/nsm.py + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/send2nsm.py" ${EXECUTABLE_OUTPUT_PATH}/send2nsm.py) +ENDIF(USE_BUILD_LIBS) + +SET(ADD_DEPEND "audiomanager-bin" "sqlite3(>=3.6.22)" "dlt" "libdbus-1-3(>=1.2.16)" "gtest" "libpthread-stubs0") +set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}") + diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/nsm.py b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/nsm.py new file mode 100644 index 0000000..7a02d05 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/nsm.py @@ -0,0 +1,179 @@ +# -*- coding: utf-8 -*- +# +# 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 2012 +# +# For further information see http://www.genivi.org/. +# + +import sys +import traceback +import gobject +import math +import dbus +import dbus.service +import dbus.mainloop.glib + +loop = gobject.MainLoop() +dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +class NodeStateManager(dbus.service.Object): + def __init__(self, loop): + busName = dbus.service.BusName('org.genivi.NodeStateManager', bus = dbus.SessionBus()) + dbus.service.Object.__init__(self, busName, '/org/genivi/NodeStateManager') + self.properties = {'RestartReason': 1, 'ShutdownReason': 2, 'WakeUpReason' :3, 'BootMode' :4} + self.ABus="" + self.APath="" + self.loop=loop + + @dbus.service.method(dbus_interface='org.freedesktop.DBus.Introspectable', out_signature = 's') + def Introspect(self): + f = open('org.genivi.NodeStateManager.Consumer.xml', "r") + text = f.read() + return text + + @dbus.service.method(dbus_interface='org.genivi.NodeStateManager.Consumer', out_signature = 'ii') + def GetNodeState(self): + NodeStateId=1 + ErrorCode=1 + print('[----------] send out nodeState' + str(NodeStateId) + ' ErrorCode '+ str(1)) + return NodeStateId, ErrorCode + + @dbus.service.method('org.genivi.NodeStateManager.Consumer', out_signature = 'ii') + def GetApplicationMode(self): + ApplicationModeId=5 + ErrorCode=2 + print('[----------] send out ApplicationMode' + str(ApplicationModeId) + ' ErrorCode '+ str(2)) + return ApplicationModeId, ErrorCode + + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='si', out_signature = 'ii') + def GetSessionState(self,SessionName,seatID): + SessionState=0 + ErrorCode=2 + + if SessionName=="mySession" and seatID==1: + SessionState=5 + ErrorCode=1 + + print('[----------] GetSessionState for session ' + SessionName + ' seatID '+ str(seatID) + ' returnState ' + str (SessionState)) + return SessionState, ErrorCode + + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ssuu', out_signature = 'i') + def RegisterShutdownClient(self,BName,ObjName,ShutdownMode,TimeoutMs): + print('[----------] Busname: ' + BName) + print('[----------] ObjName: ' + ObjName) + print('[----------] ShutdownMode: ' + str(ShutdownMode)) + print('[----------] TimeoutMs: ' + str(TimeoutMs)) + ErrorCode=1 + if TimeoutMs!=100: + ErrorCode=3 + if BName!="org.genivi.audiomanager": + ErrorCode=4 + if ShutdownMode!=1: + ErrorCode=5 + if ObjName!="/org/genivi/audiomanager/LifeCycleConsumer": + ErrorCode=6 + self.ABus=BName + self.APath=ObjName + return ErrorCode + + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ssu', out_signature = 'i') + def UnRegisterShutdownClient(self,BusName,ObjName,ShutdownMode): + print('[----------] Busname: ' + str(BusName)) + print('[----------] ObjName: ' + str(ObjName)) + print('[----------] ShutdownMode: ' + str(ShutdownMode)) + ErrorCode=1 + if BusName!=self.ABus: + ErrorCode=2 + if ObjName!=self.APath: + ErrorCode=2 + if ShutdownMode!=1: + ErrorCode=2 + return ErrorCode + + @dbus.service.method(dbus_interface='org.genivi.NodeStateManager.Consumer', out_signature = 'u') + def GetInterfaceVersion(self): + version=23 + return version + + @dbus.service.method('org.genivi.NodeStateManager.Consumer', in_signature='ui', out_signature='i') + def LifecycleRequestComplete(self,RequestID,Status): + print('[----------] RequestId: ' + str(RequestID)) + print('[----------] Status: ' + str(Status)) + ErrorCode=1 + if RequestID!=22: + ErrorCode=2 + if Status!=4: + ErrorCode=2 + return ErrorCode + + @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v') + def Get(self, interface, prop): + if prop in self.properties: + print('[----------] send out ' + str(self.properties[prop]) + ' for property '+ prop) + return self.properties[prop] + return 0 + + @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ssv') + def Set(self, interface, prop, value): + return 3 + + @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') + def GetAll(self, interface): + return self.properties + + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='i') + def NodeApplicationMode(self, ApplicationModeId): + print "[----------] Send out application mode ID %d" % (ApplicationModeId) + + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='i') + def NodeState(self, NodeState): + print "[----------] Send out NodeState %d" % (NodeState) + + @dbus.service.signal(dbus_interface='org.genivi.NodeStateManager.Consumer', signature='sii') + def SessionStateChanged(self, SessionStateName,SeatID,SessionState): + print "[----------] Send out SessionStateChanged " + SessionStateName + + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='i') + def sendNodeApplicationMode(self, input): + self.NodeApplicationMode(input) + return input + + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='i') + def sendNodeState(self, input): + self.NodeState(input) + return input + + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='sii') + def sendSessionState(self, SessionStateName,SeatID,SessionState): + self.SessionStateChanged (SessionStateName,SeatID,SessionState) + return SeatID + + @dbus.service.method('org.genivi.NodeStateManager.Control', in_signature='uu', out_signature='i') + def sendLifeCycleRequest(self, request, requestID): + bus = dbus.SessionBus() + remote_object = bus.get_object(self.ABus,self.APath) + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.LifeCycleConsumer') + iface.LifecycleRequest(request,requestID) + return 42 + + @dbus.service.method('org.genivi.NodeStateManager.Control') + def finish(self): + print '[----------] Going to exit now!' + self.loop.quit() + return 0 + +nsm = NodeStateManager(loop) +loop.run() diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/org.genivi.NodeStateManager.Consumer.xml b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/org.genivi.NodeStateManager.Consumer.xml new file mode 100644 index 0000000..bb40a96 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/org.genivi.NodeStateManager.Consumer.xml @@ -0,0 +1,259 @@ +<!-- Auto-Generated interface from Rhapsody: 'Repository::ssw_LifecycleSupport::NodeStateManagement::Concept::Interface::INSM_Consumer' -->
+<!-- Created at 2012-06-01 09:36:05 by uid65904 -->
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+<interface name="org.freedesktop.DBus.Introspectable">
+ <method name="Introspect">
+ <arg name="data" direction="out" type="s"/>
+ </method>
+</interface>
+<interface name="org.freedesktop.DBus.Properties">
+ <method name="Get">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="propname" direction="in" type="s"/>
+ <arg name="value" direction="out" type="v"/>
+ </method>
+
+ <method name="Set">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="propname" direction="in" type="s"/>
+ <arg name="value" direction="in" type="v"/>
+ </method>
+
+ <method name="GetAll">
+ <arg name="interface" direction="in" type="s"/>
+ <arg name="props" direction="out" type="a{sv}"/>
+ </method>
+</interface>
+ <!--
+ org.genivi.NodeStateManager.Consumer:
+ @short_description: "Consumer" interface of the NodeStateManager.
+
+ This interface contains functions which are not safety critical and can be accessed by "every" client without further restrictions.
+ -->
+ <interface name="org.genivi.NodeStateManager.Consumer">
+ <!--
+ RestartReason: This property informs clients about the reason for the last restart. The values are based upon the enummeration NsmRestartReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="RestartReason" type="i" access="read"/>
+
+ <!--
+ ShutdownReason: This property informs clients about the reason for the last shutdown. The values are based upon the enummeration NsmShutdownReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="ShutdownReason" type="i" access="read"/>
+
+ <!--
+ WakeUpReason: This property informs clients about the recent reason for waking up the target. The values are based upon the enummeration NsmWakeUpReason_e. Note: The value is only set once at start-up.
+ -->
+ <property name="WakeUpReason" type="i" access="read"/>
+
+ <!--
+ BootMode: This property informs clients about the recent BootMode of the target. The values will be defined by a third party header, which has not been delivered yet. The description needs to be updated as soon as the header is available.
+ -->
+ <property name="BootMode" type="i" access="read"/>
+
+ <!--
+ NodeState:
+ @NodeState: Numeric value for the current NodeState, defined in NsmNodeState_e.
+
+ Clients can register for notifications when the NodeState is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeState as a parameter.
+ -->
+ <signal name="NodeState">
+ <arg name="NodeState" type="i"/>
+ </signal>
+
+ <!--
+ NodeApplicationMode:
+ @ApplicationModeId: Numeric value for the current ApplicationMode, defined in NsmAplicationMode_e.
+
+ Clients can register for notifications when the NodeApplicationMode is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeApplicationMode as a parameter.
+ -->
+ <signal name="NodeApplicationMode">
+ <arg name="ApplicationModeId" type="i"/>
+ </signal>
+
+ <!--
+ SessionStateChanged:
+ @SessionStateName: The SessionName will be based upon either the pre-defined platform SessionNames or using a newly added product defined session name.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
+
+ This signal is sent to registered clients when a particular session is state is changed. The client can register for notification about a specific session through the use of the SessionName, as a "match rule".
+ -->
+ <signal name="SessionStateChanged">
+ <arg name="SessionStateName" type="s"/>
+ <arg name="SeatID" type="i"/>
+ <arg name="SessionState" type="i"/>
+ </signal>
+
+ <!--
+ GetNodeState:
+ @NodeStateId: Will be based on the NsmNodeState_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to get the NodeState without the need of registration to the signal.
+ -->
+ <method name="GetNodeState">
+ <arg name="NodeStateId" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ SetSessionState:
+ @SessionName: The SessionName will be based upon either the pre-defined platform SessionNames (see NSM content page) or using a newly added product defined session name.
+ @SessionOwner: This parameter defines the name of the application that is setting the state of the session. This must be the applications systemd unit filename.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by applications to set the state of a session.
+ -->
+ <method name="SetSessionState">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetSessionState:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by applications to get the state of a session.
+ -->
+ <method name="GetSessionState">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetApplicationMode:
+ @ApplicationModeId: This parameter will be based upon the NsmNodeApplicationMode_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to get the application mode.
+ -->
+ <method name="GetApplicationMode">
+ <arg name="ApplicationModeId" direction="out" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ RegisterShutdownClient:
+ @BusName: Bus name of remote application.
+ @ObjName: Object name of remote object that provides the shutdown interface.
+ @ShutdownMode: Shutdown mode for which client wants to be informed (i.e normal, fast etc).
+ @TimeoutMs: Max. Timeout to wait for response from shutdown client in ms.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to register themselves as shutdown client. Any client that registers must provide a method in their D-Bus object called "LifecycleRequest". This method will take one parameter which is the RequestType (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST). For an example of the required client interface please see the BootManager component who will be a client of the NSM.
+ -->
+ <method name="RegisterShutdownClient">
+ <arg name="BusName" direction="in" type="s"/>
+ <arg name="ObjName" direction="in" type="s"/>
+ <arg name="ShutdownMode" direction="in" type="u"/>
+ <arg name="TimeoutMs" direction="in" type="u"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ UnRegisterShutdownClient:
+ @BusName: Bus name of remote application.
+ @ObjName: Object name of remote object that provides the shutdown interface.
+ @ShutdownMode: Shutdown mode for which client wants to unregister (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST).
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to unregister themselves as shutdown client.
+ -->
+ <method name="UnRegisterShutdownClient">
+ <arg name="BusName" direction="in" type="s"/>
+ <arg name="ObjName" direction="in" type="s"/>
+ <arg name="ShutdownMode" direction="in" type="u"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ RegisterSession:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SessionOwner: This is the name of the application that is registering the new session (this must be the applications systemd unit filename).
+ @SeatID: This parameter will be based upon the enum NsmSeatId_e
+ @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to register a new session whose state should be observed and distributed by the NSM.
+ -->
+ <method name="RegisterSession">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="SessionState" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ UnRegisterSession:
+ @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
+ @SessionOwner: This is the name of the application that originally registered the session. It will be validated that this value matches the stored value from the registration.
+ @SeatID: This parameter will be based upon the enum NsmSeat_e.
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The method is used by other applications to remove a new session from the session list hosted by NSM.
+ -->
+ <method name="UnRegisterSession">
+ <arg name="SessionName" direction="in" type="s"/>
+ <arg name="SessionOwner" direction="in" type="s"/>
+ <arg name="SeatID" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+
+ <!--
+ GetAppHealthCount:
+ @Count: Return value passed to the caller. Number of applications that crashed or terminated accidentally.
+
+ The method returns the number of applications that crashed or terminated accidentally, within the current life cycle. It can be used to observe the system state.
+ -->
+ <method name="GetAppHealthCount">
+ <arg name="Count" direction="out" type="u"/>
+ </method>
+
+ <!--
+ GetInterfaceVersion:
+ @Version: Unsigned integer that represents the version number of the Node State Manager.
+
+ The method returns the version number of the Node State Manager. The number is organized in four bytes:
+
+ Version: VVV.RRR.PPP.BBB
+
+ <literallayout>
+ VVV => Version [1..255]
+ RRR => Release [0..255]
+ PPP => Patch [0..255]
+ BBB => Build [0..255]
+ </literallayout>
+ -->
+ <method name="GetInterfaceVersion">
+ <arg name="Version" direction="out" type="u"/>
+ </method>
+
+ <!--
+ LifecycleRequestComplete:
+ @RequestId: The request Id of the called life cycle client. The value has been passed when "LifecycleRequest" was called.
+ @Status: The result of the call to "LifecycleRequest". NsmErrorStatus_Ok: Request successfully processed. NsmErrorStatus_Error: An error occured while processing the "LifecycleRequest".
+ @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
+
+ The function has to be called by a "asynchrounous" lifecycle client, when he processed the "LifecycleRequest".
+ -->
+ <method name="LifecycleRequestComplete">
+ <arg name="RequestId" direction="in" type="u"/>
+ <arg name="Status" direction="in" type="i"/>
+ <arg name="ErrorCode" direction="out" type="i"/>
+ </method>
+ </interface>
+</node>
diff --git a/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/send2nsm.py b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/send2nsm.py new file mode 100644 index 0000000..3b6cad3 --- /dev/null +++ b/AudioManagerDaemon/test/AmNodeStateCommunicatorTest/send2nsm.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# +# 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 2012 +# +# For further information see http://www.genivi.org/. +# + +import sys +import traceback +import gobject +import math +import dbus +import dbus.service + +def nodeState (nodeState): + bus = dbus.SessionBus() + remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') + iface.sendNodeState(int(nodeState)) + +def appMode (appMode): + bus = dbus.SessionBus() + remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') + iface.sendNodeApplicationMode(int(appMode)) + +def sessionState (SessionStateName,SeatID,SessionState): + bus = dbus.SessionBus() + remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') + iface.sendSessionState(SessionStateName,int(SeatID),int(SessionState)) + +def finish(): + bus = dbus.SessionBus() + remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') + iface.finish() + +def LifecycleRequest(Request,RequestID): + bus = dbus.SessionBus() + remote_object = bus.get_object('org.genivi.NodeStateManager','/org/genivi/NodeStateManager') + iface = dbus.Interface(remote_object, 'org.genivi.NodeStateManager.Control') + iface.sendLifeCycleRequest(Request,RequestID) + +command=sys.argv[1] +if command=="nodeState": + nodeState(sys.argv[2]) +if command=="finish": + finish() +if command=="appMode": + appMode(sys.argv[2]) +if command=="sessionState": + sessionState(sys.argv[2],sys.argv[3],sys.argv[4]) +if command=="LifecycleRequest": + LifecycleRequest(sys.argv[2],sys.argv[3]) diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp index 0758a01..9f172be 100644 --- a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp +++ b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp @@ -30,7 +30,7 @@ CAmRouterTest::CAmRouterTest() : plistCommandPluginDirs(), // pSocketHandler(), // pDatabaseHandler(std::string(":memory:")), // - pControlSender(std::string("")), // + pControlSender(), // pRouter(&pDatabaseHandler, &pControlSender), // pRoutingSender(plistRoutingPluginDirs), // pCommandSender(plistCommandPluginDirs), // @@ -121,7 +121,7 @@ TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); } @@ -182,7 +182,7 @@ TEST_F(CAmRouterTest,simpleRoute2withDomain) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -290,7 +290,7 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFree) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -412,10 +412,10 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFreeNotFree) ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -575,7 +575,7 @@ TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_2) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -729,7 +729,7 @@ TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_1) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -878,7 +878,7 @@ TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1112,7 +1112,7 @@ TEST_F(CAmRouterTest,simpleRoute4Domains2Routes) compareRoute1.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(2, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(2), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])); } @@ -1259,7 +1259,7 @@ TEST_F(CAmRouterTest,simpleRoute3DomainsNoConnection) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); } //test that checks just 2 domains, one sink one source with only one connection format each TEST_F(CAmRouterTest,simpleRoute2Domains) @@ -1364,7 +1364,7 @@ TEST_F(CAmRouterTest,simpleRoute2Domains) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1472,7 +1472,7 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsNoMatchConnectionFormats) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(0, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); } //test that checks 3 domains, one sink one source. @@ -1616,7 +1616,7 @@ TEST_F(CAmRouterTest,simpleRoute3Domains) compareRoute.sourceID = sourceID; ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); - ASSERT_EQ(1, listRoutes.size()); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } diff --git a/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt index aae97e5..2a0468f 100644 --- a/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmRouterTest/CMakeLists.txt @@ -55,6 +55,8 @@ file(GLOB ROUTING_SRCS_CXX "../../src/CAmSocketHandler.cpp" "../../src/CAmCommandReceiver.cpp" "../../src/CAmRoutingReceiver.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmDbusWrapper.cpp" "../CAmCommonFunctions.cpp" "*.cpp" ) diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp index 47181b3..d7bb96d 100644 --- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp +++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -31,7 +31,7 @@ CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : pDatabaseHandler(std::string(":memory:")), // pRoutingSender(plistRoutingPluginDirs), // pCommandSender(plistCommandPluginDirs), // - pControlSender(""), // + pControlSender(), // pRouter(&pDatabaseHandler, &pControlSender), // pMockInterface(), // pRoutingInterfaceBackdoor(), // diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt index 5b903b5..abda5c1 100644 --- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt @@ -57,6 +57,8 @@ file(GLOB ROUTING_INTERFACE_SRCS_CXX "../../src/CAmSocketHandler.cpp" "../../src/CAmRoutingReceiver.cpp" "../../src/CAmCommandReceiver.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmDbusWrapper.cpp" "*.cpp" ) diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp index ebc3705..686ac92 100644 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp @@ -44,9 +44,8 @@ static CAmSocketHandler* mpSocketHandler = NULL; void* startSocketHandler(void* data) { CAmEnvironment* Env = static_cast<CAmEnvironment*>(data); - CAmSocketHandler mySocketHandler; - Env->setSocketHandler(&mySocketHandler); - mySocketHandler.start_listenting(); + Env->setSocketHandler(&Env->mSocketHandler); + Env->mSocketHandler.start_listenting(); Env->setSocketHandler(NULL); return (NULL); } @@ -54,11 +53,11 @@ void* startSocketHandler(void* data) CAmEnvironment::CAmEnvironment() : mlistRoutingPluginDirs() , mlistCommandPluginDirs() -//, mpSocketHandler(NULL) +, mSocketHandler() , mDatabasehandler(std::string(":memory:")) , mRoutingSender(mlistRoutingPluginDirs) , mCommandSender(mlistRoutingPluginDirs) -, mControlSender(controllerPlugin) +, mControlSender(controllerPlugin,&mSocketHandler) , mRouter(&mDatabasehandler,&mControlSender) , mpCommandReceiver(NULL) , mpRoutingReceiver(NULL) @@ -172,7 +171,7 @@ TEST_F(CAmTelnetServerTest,sendCmdTelnetServer) std::string string("help"); ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); - ASSERT_EQ(sizesent,string.size()); + ASSERT_EQ(static_cast<uint>(sizesent),string.size()); char buffer[1000]; memset(buffer,0,sizeof(buffer)); @@ -187,7 +186,7 @@ TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) mpSocketHandler->stop_listening(); ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0); - ASSERT_EQ(sizesent,string.size()); + ASSERT_EQ(static_cast<uint>(sizesent),string.size()); char buffer[1000]; memset(buffer,0,sizeof(buffer)); diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h index 06d10fe..a584b97 100644 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h @@ -63,7 +63,7 @@ class CAmEnvironment : public ::testing::Environment std::vector<std::string> mlistRoutingPluginDirs; std::vector<std::string> mlistCommandPluginDirs; - //SocketHandler* mpSocketHandler; + CAmSocketHandler mSocketHandler; CAmDatabaseHandler mDatabasehandler; CAmRoutingSender mRoutingSender; CAmCommandSender mCommandSender; diff --git a/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt index b2c44a9..181940c 100644 --- a/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt +++ b/AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt @@ -63,6 +63,8 @@ file(GLOB TELNET_SRCS_CXX "../../src/CAmRouter.cpp" "../../src/CAmDltWrapper.cpp" "../../src/CAmTelnetMenuHelper.cpp" + "../../src/CAmNodeStateCommunicator.cpp" + "../../src/CAmDbusWrapper.cpp" "*.cpp" ) diff --git a/AudioManagerDaemon/test/CMakeLists.txt b/AudioManagerDaemon/test/CMakeLists.txt index fb93efa..2588e8f 100644 --- a/AudioManagerDaemon/test/CMakeLists.txt +++ b/AudioManagerDaemon/test/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory (AmDatabaseHandlerTest) add_subdirectory (AmRouterTest) add_subdirectory (AmRoutingInterfaceTest) add_subdirectory (AmSocketHandlerTest) +add_subdirectory (AmNodeStateCommunicatorTest) IF(WITH_TELNET) add_subdirectory (AmTelnetServerTest) ENDIF(WITH_TELNET) diff --git a/AudioManagerDaemon/test/MockIAmCommandSend.h b/AudioManagerDaemon/test/MockIAmCommandSend.h index 11c1992..70cdc4f 100644 --- a/AudioManagerDaemon/test/MockIAmCommandSend.h +++ b/AudioManagerDaemon/test/MockIAmCommandSend.h @@ -71,6 +71,20 @@ class MockIAmCommandSend : public IAmCommandSend { void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); MOCK_CONST_METHOD1(getInterfaceVersion, void(std::string& version)); + MOCK_METHOD3(cbSinkUpdated, + void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)); + MOCK_METHOD3(cbSourceUpdated, + void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& 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(cbSinkMainNotificationConfigurationChanged, + void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + MOCK_METHOD2(cbSourceMainNotificationConfigurationChanged, + void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + + }; } // namespace am diff --git a/AudioManagerDaemon/test/MockIAmControlSend.h b/AudioManagerDaemon/test/MockIAmControlSend.h index 7f51ab0..7f83823 100644 --- a/AudioManagerDaemon/test/MockIAmControlSend.h +++ b/AudioManagerDaemon/test/MockIAmControlSend.h @@ -29,100 +29,129 @@ namespace am { class MockIAmControlSend : public IAmControlSend { public: - MOCK_METHOD1(startupController, - am_Error_e(IAmControlReceive* controlreceiveinterface)); - MOCK_METHOD0(setControllerReady, - void()); - MOCK_METHOD0(setControllerRundown, - void()); - MOCK_METHOD3(hookUserConnectionRequest, - am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); - MOCK_METHOD1(hookUserDisconnectionRequest, - am_Error_e(const am_mainConnectionID_t connectionID)); - MOCK_METHOD2(hookUserSetMainSinkSoundProperty, - am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD2(hookUserSetMainSourceSoundProperty, - am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); - MOCK_METHOD1(hookUserSetSystemProperty, - am_Error_e(const am_SystemProperty_s& property)); - MOCK_METHOD2(hookUserVolumeChange, - am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); - MOCK_METHOD2(hookUserVolumeStep, - am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); - MOCK_METHOD2(hookUserSetSinkMuteState, - am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); - MOCK_METHOD2(hookSystemRegisterDomain, - am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); - MOCK_METHOD1(hookSystemDeregisterDomain, - am_Error_e(const am_domainID_t domainID)); - MOCK_METHOD1(hookSystemDomainRegistrationComplete, - void(const am_domainID_t domainID)); - MOCK_METHOD2(hookSystemRegisterSink, - am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); - MOCK_METHOD1(hookSystemDeregisterSink, - am_Error_e(const am_sinkID_t sinkID)); - MOCK_METHOD2(hookSystemRegisterSource, - am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); - MOCK_METHOD1(hookSystemDeregisterSource, - am_Error_e(const am_sourceID_t sourceID)); - MOCK_METHOD2(hookSystemRegisterGateway, - am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); - MOCK_METHOD1(hookSystemDeregisterGateway, - am_Error_e(const am_gatewayID_t gatewayID)); - MOCK_METHOD2(hookSystemRegisterCrossfader, - am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); - MOCK_METHOD1(hookSystemDeregisterCrossfader, - am_Error_e(const am_crossfaderID_t crossfaderID)); - MOCK_METHOD3(hookSystemSinkVolumeTick, - void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); - MOCK_METHOD3(hookSystemSourceVolumeTick, - void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); - MOCK_METHOD2(hookSystemInterruptStateChange, - void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); - MOCK_METHOD2(hookSystemSinkAvailablityStateChange, - void(const am_sinkID_t sinkID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemSourceAvailablityStateChange, - void(const am_sourceID_t sourceID, const am_Availability_s& availability)); - MOCK_METHOD2(hookSystemDomainStateChange, - void(const am_domainID_t domainID, const am_DomainState_e state)); - MOCK_METHOD1(hookSystemReceiveEarlyData, - void(const std::vector<am_EarlyData_s>& 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<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e>& listPrioConnectionFormats)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); - MOCK_METHOD0(confirmCommandReady, - void()); - MOCK_METHOD0(confirmRoutingReady, - void()); - MOCK_METHOD0(confirmCommandRundown, - void()); - MOCK_METHOD0(confirmRoutingRundown, - void()); + 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(hookSystemRegisterGateway, + am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); + MOCK_METHOD1(hookSystemDeregisterGateway, + am_Error_e(const am_gatewayID_t gatewayID)); + MOCK_METHOD2(hookSystemRegisterCrossfader, + am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); + MOCK_METHOD1(hookSystemDeregisterCrossfader, + am_Error_e(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD3(hookSystemSinkVolumeTick, + void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); + MOCK_METHOD3(hookSystemSourceVolumeTick, + void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); + MOCK_METHOD2(hookSystemInterruptStateChange, + void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); + MOCK_METHOD2(hookSystemSinkAvailablityStateChange, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemSourceAvailablityStateChange, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemDomainStateChange, + void(const am_domainID_t domainID, const am_DomainState_e state)); + MOCK_METHOD1(hookSystemReceiveEarlyData, + void(const std::vector<am_EarlyData_s>& 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<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e>& 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<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties)); + MOCK_METHOD5(hookSystemUpdateSource, + am_Error_e(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s> listSoundProperties, const std::vector<am_ConnectionFormat_e> listConnectionFormats, std::vector<am_MainSoundProperty_s> listMainSoundProperties)); + MOCK_METHOD4(hookSystemUpdateGateway, + am_Error_e(const am_gatewayID_t gatewayID, const std::vector<am_ConnectionFormat_e> listSourceConnectionFormats, const std::vector<am_ConnectionFormat_e> listSinkConnectionFormats, const std::vector<bool> convertionMatrix)); + MOCK_METHOD3(cbAckSetVolume, + void(const am_Handle_s handle, const std::vector<am_Volumes_s> 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_METHOD1(hookSystemNodeStateChanged, + void(const NsmNodeState_e NodeStateId)); + MOCK_METHOD1(hookSystemNodeApplicationModeChanged, + void(const NsmApplicationMode_e ApplicationModeId)); + MOCK_METHOD3(hookSystemSessionStateChanged, + void(const std::string sessionName, const int32_t seatID, const NsmSessionState_e sessionStateID)); + MOCK_METHOD2(hookSystemLifecycleRequest, + NsmErrorStatus_e(const uint32_t Request, const uint32_t RequestId)); + }; } // namespace am diff --git a/AudioManagerDaemon/test/MockIAmRoutingSend.h b/AudioManagerDaemon/test/MockIAmRoutingSend.h index 0534e41..029790e 100644 --- a/AudioManagerDaemon/test/MockIAmRoutingSend.h +++ b/AudioManagerDaemon/test/MockIAmRoutingSend.h @@ -29,40 +29,47 @@ namespace am { class MockIAmRoutingSend : public IAmRoutingSend { public: - MOCK_METHOD1(startupInterface, - am_Error_e(IAmRoutingReceive* routingreceiveinterface)); - MOCK_METHOD1(setRoutingReady, - void(const uint16_t handle)); - MOCK_METHOD1(setRoutingRundown, - void(const uint16_t handle)); - MOCK_METHOD1(asyncAbort, - am_Error_e(const am_Handle_s handle)); - MOCK_METHOD5(asyncConnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)); - MOCK_METHOD2(asyncDisconnect, - am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); - MOCK_METHOD5(asyncSetSinkVolume, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD5(asyncSetSourceVolume, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); - MOCK_METHOD3(asyncSetSourceState, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); - MOCK_METHOD3(asyncSetSinkSoundProperties, - am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& 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<am_SoundProperty_s>& listSoundProperties)); - MOCK_METHOD3(asyncSetSourceSoundProperty, - am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); - MOCK_METHOD5(asyncCrossFade, - am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)); - MOCK_METHOD2(setDomainState, - am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); - MOCK_CONST_METHOD1(returnBusName, - am_Error_e(std::string& BusName)); - MOCK_CONST_METHOD1(getInterfaceVersion, - void(std::string& version)); + 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_ConnectionFormat_e connectionFormat)); + MOCK_METHOD2(asyncDisconnect, + am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); + MOCK_METHOD5(asyncSetSinkVolume, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); + MOCK_METHOD5(asyncSetSourceVolume, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)); + MOCK_METHOD3(asyncSetSourceState, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); + MOCK_METHOD3(asyncSetSinkSoundProperties, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& 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<am_SoundProperty_s>& listSoundProperties)); + MOCK_METHOD3(asyncSetSourceSoundProperty, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); + MOCK_METHOD5(asyncCrossFade, + am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)); + MOCK_METHOD2(setDomainState, + am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); + MOCK_CONST_METHOD1(returnBusName, + am_Error_e(std::string& BusName)); + MOCK_METHOD2(asyncSetVolumes, + am_Error_e(const am_Handle_s handle, const std::vector<am_Volumes_s>& 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)); + }; } // namespace am |