diff options
Diffstat (limited to 'AudioManagerDaemon')
19 files changed, 636 insertions, 525 deletions
diff --git a/AudioManagerDaemon/include/CommandReceiver.h b/AudioManagerDaemon/include/CommandReceiver.h index c7154f1..a8f7400 100644 --- a/AudioManagerDaemon/include/CommandReceiver.h +++ b/AudioManagerDaemon/include/CommandReceiver.h @@ -64,13 +64,27 @@ public: am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const; am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const; am_Error_e getSocketHandler(SocketHandler*& socketHandler) const; - uint16_t getInterfaceVersion() const; + void getInterfaceVersion(std::string& version) const; + void confirmCommandReady(const uint16_t handle); + void confirmCommandRundown(const uint16_t handle); + + uint16_t getStartupHandle(); //!< returns a startup handle + uint16_t getRundownHandle(); //!< returns a rundown handle + + void waitOnStartup(bool startup); //!< tells the ComandReceiver to start waiting for all handles to be confirmed + void waitOnRundown(bool rundown); //!< tells the ComandReceiver to start waiting for all handles to be confirmed private: DatabaseHandler* mDatabaseHandler; //!< pointer to the databasehandler ControlSender* mControlSender; //!< pointer to the control sender DBusWrapper* mDBusWrapper; //!< pointer to the dbuswrapper SocketHandler* mSocketHandler; //!< pointer to the SocketHandler + + uint16_t handleCount; //!< counts all handles + std::vector<uint16_t> mListStartupHandles; //!< list of handles that wait for a confirm + 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 }; } diff --git a/AudioManagerDaemon/include/CommandSender.h b/AudioManagerDaemon/include/CommandSender.h index 1a17134..57362f0 100644 --- a/AudioManagerDaemon/include/CommandSender.h +++ b/AudioManagerDaemon/include/CommandSender.h @@ -34,6 +34,9 @@ namespace am { +class CommandReceiver; + + /** * This class is used to send data to the CommandInterface. * All loaded plugins will be called when a callback is invoked. @@ -43,20 +46,19 @@ class CommandSender public: CommandSender(const std::vector<std::string>& listOfPluginDirectories); virtual ~CommandSender(); - am_Error_e startupInterface(CommandReceiveInterface* commandreceiveinterface); - am_Error_e stopInterface(); - am_Error_e cbCommunicationReady(); - am_Error_e cbCommunicationRundown(); + am_Error_e startupInterfaces(CommandReceiver* iCommandReceiver); + void setCommandReady(); + void setCommandRundown(); void cbNewMainConnection(const am_MainConnectionType_s mainConnection); - void cbRemovedMainConnection(const am_MainConnectionType_s mainConnection); - void cbNewSink(const am_SinkType_s sink); - void cbRemovedSink(const am_SinkType_s sink); + void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection); + void cbNewSink(am_SinkType_s sink); + void cbRemovedSink(const am_sinkID_t sink); void cbNewSource(const am_SourceType_s source); - void cbRemovedSource(const am_SourceType_s source); + void cbRemovedSource(const am_sourceID_t source); void cbNumberOfSinkClassesChanged(); void cbNumberOfSourceClassesChanged(); void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); - void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s soundProperty); + void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); @@ -64,7 +66,7 @@ public: void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); void cbSystemPropertyChanged(const am_SystemProperty_s& systemProperty); void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); - uint16_t getInterfaceVersion() const; + void getInterfaceVersion(std::string& version) const; am_Error_e getListPlugins(std::vector<std::string>& interfaces) const; #ifdef UNIT_TEST friend class CommandInterfaceBackdoor; //this is to get access to the loaded plugins and be able to exchange the interfaces @@ -73,7 +75,9 @@ private: void unloadLibraries(void); //!< unload the shared libraries std::vector<CommandSendInterface*> mListInterfaces; //!< list of all interfaces std::vector<void*> mListLibraryHandles; //!< list of all library handles. This information is used to unload the plugins correctly. - std::vector<std::string> mListLibraryNames; //!< list of all library anmes. This information is used for getListPlugins. + std::vector<std::string> mListLibraryNames; //!< list of all library names. This information is used for getListPlugins. + + CommandReceiver *mCommandReceiver; }; } diff --git a/AudioManagerDaemon/include/ControlReceiver.h b/AudioManagerDaemon/include/ControlReceiver.h index c67e0d9..03e36d8 100644 --- a/AudioManagerDaemon/include/ControlReceiver.h +++ b/AudioManagerDaemon/include/ControlReceiver.h @@ -49,23 +49,25 @@ public: am_Error_e connect(am_Handle_s& handle, am_connectionID_t& connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID); am_Error_e disconnect(am_Handle_s& handle, const am_connectionID_t connectionID); am_Error_e crossfade(am_Handle_s& handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime); + am_Error_e abortAction(const am_Handle_s handle); am_Error_e setSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state); am_Error_e setSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); am_Error_e setSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time); - am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); am_Error_e setSinkSoundProperties(am_Handle_s& handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& soundProperty); - am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); + am_Error_e setSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty); am_Error_e setSourceSoundProperties(am_Handle_s& handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& soundProperty); + am_Error_e setSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty); am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); - am_Error_e abortAction(const am_Handle_s handle); am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID); - am_Error_e enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass); + am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID); + am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass); + am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass); + am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass); am_Error_e enterSystemPropertiesListDB(const std::vector<am_SystemProperty_s>& listSystemProperties); am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector<am_connectionID_t>& listConnectionID); am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState); @@ -77,8 +79,6 @@ public: am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID); am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID); am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property); - am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& classInfo); - am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& classInfo); am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID); am_Error_e removeSinkDB(const am_sinkID_t sinkID); am_Error_e removeSourceDB(const am_sourceID_t sourceID); @@ -96,25 +96,27 @@ public: am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const; am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t>& listSinkID) const; am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const; - am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listGatewaysID) const; + am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listCrossfadersID) const; am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const; am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const; am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const; am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const; am_Error_e getListSinks(std::vector<am_Sink_s>& listSinks) const; - am_Error_e getListSources(std::vector<am_Source_s>& lisSources) const; + am_Error_e getListSources(std::vector<am_Source_s>& listSources) const; am_Error_e getListSourceClasses(std::vector<am_SourceClass_s>& listSourceClasses) const; am_Error_e getListHandles(std::vector<am_Handle_s>& listHandles) const; am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const; am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const; am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const; am_Error_e getListSystemProperties(std::vector<am_SystemProperty_s>& listSystemProperties) const; - void setRoutingReady(); void setCommandReady(); void setCommandRundown(); + void setRoutingReady(); void setRoutingRundown(); + void confirmControllerReady(); + void confirmControllerRundown(); am_Error_e getSocketHandler(SocketHandler*& socketHandler); - uint16_t getInterfaceVersion() const; + void getInterfaceVersion(std::string& version) const; private: DatabaseHandler* mDatabaseHandler; //!< pointer tto the databasehandler diff --git a/AudioManagerDaemon/include/ControlSender.h b/AudioManagerDaemon/include/ControlSender.h index 66db61c..cb9ff36 100644 --- a/AudioManagerDaemon/include/ControlSender.h +++ b/AudioManagerDaemon/include/ControlSender.h @@ -42,49 +42,53 @@ class ControlSender public: ControlSender(std::string controlPluginFile); virtual ~ControlSender(); - am_Error_e startupController(ControlReceiveInterface* controlreceiveinterface); - am_Error_e stopController(); - am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID); - am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID); - am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty); - am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty); - am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property); - am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume); - am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment); - am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState); - am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID); - am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID); - am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID); - am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID); - am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID); - am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID); - am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID); - am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID); - am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); - am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID); - void hookAllPluginsLoaded(); - void hookSystemDomainRegistrationComplete(const am_domainID_t domainID); - void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); - void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); - void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); - void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability); - void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability); - void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state); - void hookSystemReceiveEarlyData(const std::vector<am_EarlyData_s>& data); - void hookSystemSpeedChange(const am_speed_t speed); - void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time); - void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID); - void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID); - void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error); - void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); - void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); - void cbAckSetSourceSoundProperties(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); - uint16_t getInterfaceVersion() const; + am_Error_e startupController(ControlReceiveInterface* controlreceiveinterface) ; + void setControllerReady() ; + void setControllerRundown() ; + am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID) ; + am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID) ; + am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty) ; + am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty) ; + am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s& property) ; + am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume) ; + am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment) ; + am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState) ; + am_Error_e hookSystemRegisterDomain(const am_Domain_s& domainData, am_domainID_t& domainID) ; + am_Error_e hookSystemDeregisterDomain(const am_domainID_t domainID) ; + void hookSystemDomainRegistrationComplete(const am_domainID_t domainID) ; + am_Error_e hookSystemRegisterSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID) ; + am_Error_e hookSystemDeregisterSink(const am_sinkID_t sinkID) ; + am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ; + am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) ; + am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ; + am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ; + am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ; + am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) ; + void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) ; + void hookSystemSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) ; + void hookSystemInterruptStateChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) ; + void hookSystemSinkAvailablityStateChange(const am_sinkID_t sinkID, const am_Availability_s& availability) ; + void hookSystemSourceAvailablityStateChange(const am_sourceID_t sourceID, const am_Availability_s& availability) ; + void hookSystemDomainStateChange(const am_domainID_t domainID, const am_DomainState_e state) ; + void hookSystemReceiveEarlyData(const std::vector<am_EarlyData_s>& data) ; + void hookSystemSpeedChange(const am_speed_t speed) ; + void hookSystemTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time) ; + void cbAckConnect(const am_Handle_s handle, const am_Error_e errorID) ; + void cbAckDisconnect(const am_Handle_s handle, const am_Error_e errorID) ; + void cbAckCrossFade(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error) ; + void cbAckSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) ; + void cbAckSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error) ; + void cbAckSetSourceState(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error) ; + void cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) ; + am_Error_e getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e>& listPrioConnectionFormats) ; + void getInterfaceVersion(std::string& version) const ; + void confirmCommandReady() ; + void confirmRoutingReady() ; + void confirmCommandRundown() ; + void confirmRoutingRundown() ; #ifdef UNIT_TEST friend class ControlInterfaceBackdoor; diff --git a/AudioManagerDaemon/include/DatabaseObserver.h b/AudioManagerDaemon/include/DatabaseObserver.h index 75fed77..0657b9d 100644 --- a/AudioManagerDaemon/include/DatabaseObserver.h +++ b/AudioManagerDaemon/include/DatabaseObserver.h @@ -26,8 +26,8 @@ #define DATABASEOBSERVER_H_ #include <audiomanagertypes.h> -#include <SocketHandler.h> #include <queue> +#include "CAmSerializer.h" namespace am { @@ -35,6 +35,7 @@ namespace am class TelnetServer; class CommandSender; class RoutingSender; +class SocketHandler; /** * This class observes the Database and notifies other classes about important events, mainly the CommandSender. @@ -46,21 +47,22 @@ public: DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler); DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler, TelnetServer *iTelnetServer); virtual ~DatabaseObserver(); - void numberOfMainConnectionsChanged(); void numberOfSinkClassesChanged(); void numberOfSourceClassesChanged(); - void newSink(am_Sink_s sink); - void newSource(am_Source_s source); - void newDomain(am_Domain_s domain); - void newGateway(am_Gateway_s gateway); - void newCrossfader(am_Crossfader_s crossfader); - void removedSink(am_sinkID_t sinkID); - void removedSource(am_sourceID_t sourceID); - void removeDomain(am_domainID_t domainID); - void removeGateway(am_gatewayID_t gatewayID); - void removeCrossfader(am_crossfaderID_t crossfaderID); + void newSink(const am_Sink_s& sink); + void newSource(const am_Source_s& source); + void newDomain(const am_Domain_s& domain); + void newGateway(const am_Gateway_s& gateway); + void newCrossfader(const am_Crossfader_s& crossfader); + void newMainConnection(const am_MainConnectionType_s& mainConnection); + void removedMainConnection(const am_mainConnectionID_t mainConnection); + void removedSink(const am_sinkID_t sinkID, const bool visible); + void removedSource(const am_sourceID_t sourceID, const bool visible); + void removeDomain(const am_domainID_t domainID); + void removeGateway(const am_gatewayID_t gatewayID); + void removeCrossfader(const am_crossfaderID_t crossfaderID); void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); - void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty); + void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty); void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty); void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); @@ -69,112 +71,11 @@ public: void systemPropertyChanged(const am_SystemProperty_s& SystemProperty); void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time); - void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - bool dispatcherCallback(const sh_pollHandle_t handle, void* userData); - bool checkerCallback(const sh_pollHandle_t handle, void* userData); - - shPollFired_T<DatabaseObserver> receiverCallbackT; - shPollDispatch_T<DatabaseObserver> dispatcherCallbackT; - shPollCheck_T<DatabaseObserver> checkerCallbackT; - private: - - enum do_msgID_e - { - MDO_cbNumberOfSinksChanged, // - MDO_cbNumberOfSourcesChanged, // - MDO_cbNumberOfMainConnectionsChanged, // - MDO_cbNumberOfSinkClassesChanged, // - MDO_cbNumberOfSourceClassesChanged, // - MDO_cbMainConnectionStateChanged, // - MDO_cbMainSinkSoundPropertyChanged, // - MDO_cbMainSourceSoundPropertyChanged, // - MDO_cbSinkAvailabilityChanged, // - MDO_cbSourceAvailabilityChanged, // - MDO_cbVolumeChanged, // - MDO_cbSinkMuteStateChanged, // - MDO_cbSystemPropertyChanged, // - MDO_cbTimingInformationChanged - }; - - struct do_connectionStateChanged_s - { - am_mainConnectionID_t connectionID; - am_ConnectionState_e connectionState; - }; - - struct do_mainSinkSoundPropertyChanged_s - { - am_sinkID_t sinkID; - am_MainSoundProperty_s SoundProperty; - }; - - struct do_mainSourceSoundPropertyChanged_s - { - am_sourceID_t sourceID; - am_MainSoundProperty_s SoundProperty; - }; - - struct do_sinkAvailabilityChanged_s - { - am_sinkID_t sinkID; - am_Availability_s availability; - }; - - struct do_sourceAvailabilityChanged_s - { - am_sourceID_t sourceID; - am_Availability_s availability; - }; - - struct do_volumeChanged_s - { - am_sinkID_t sinkID; - am_mainVolume_t volume; - }; - - struct do_sinkMuteStateChanged_s - { - am_sinkID_t sinkID; - am_MuteState_e muteState; - }; - - struct do_timingInformationChanged_s - { - am_mainConnectionID_t mainConnection; - am_timeSync_t time; - }; - - union do_parameter_u - { - do_connectionStateChanged_s connectionStateChanged; - do_mainSinkSoundPropertyChanged_s mainSinkSoundPropertyChanged; - do_mainSourceSoundPropertyChanged_s mainSourceSoundPropertyChanged; - do_sinkAvailabilityChanged_s sinkAvailabilityChanged; - do_sourceAvailabilityChanged_s sourceAvailabilityChanged; - do_volumeChanged_s volumeChanged; - do_sinkMuteStateChanged_s sinkMuteStateChanged; - do_timingInformationChanged_s timingInformationChanged; - am_SystemProperty_s systemProperty; - }; - - struct do_msg_s - { - do_msgID_e msgID; - do_parameter_u parameters; - }; - - void pipeCommand(const do_msg_s& message); - - void commonConstructor(); //!< this is called from both constructors CommandSender *mCommandSender; //!< pointer to the comandSender RoutingSender* mRoutingSender; //!< pointer to the routingSender TelnetServer* mTelnetServer; //!< pointer to the telnetserver - SocketHandler* mSocketHandler; //!< pointer to the sockethandler - - int mPipe[2]; - sh_pollHandle_t mHandle; - std::queue<do_msg_s> mQueue; + CAmSerializer mSerializer; }; } diff --git a/AudioManagerDaemon/include/RoutingReceiver.h b/AudioManagerDaemon/include/RoutingReceiver.h index 08af182..3803ff4 100644 --- a/AudioManagerDaemon/include/RoutingReceiver.h +++ b/AudioManagerDaemon/include/RoutingReceiver.h @@ -51,10 +51,10 @@ public: void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error); void ackSetSourceState(const am_Handle_s handle, const am_Error_e error); - void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); void ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error); - void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); + void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error); void ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error); + void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error); void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error); void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume); void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume); @@ -71,8 +71,8 @@ public: am_Error_e deregisterSource(const am_sourceID_t sourceID); am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID); - am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); + am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); void hookDomainRegistrationComplete(const am_domainID_t domainID); void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); @@ -82,7 +82,15 @@ public: void sendChangedData(const std::vector<am_EarlyData_s>& earlyData); am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const; am_Error_e getSocketHandler(SocketHandler*& socketHandler) const; - uint16_t getInterfaceVersion() const; + void getInterfaceVersion(std::string& version) const; + void confirmRoutingReady(const uint16_t handle) const; + void confirmRoutingRundown(const uint16_t handle) const; + + uint16_t getStartupHandle(); //!< returns a startup handle + uint16_t getRundownHandle(); //!< returns a rundown handle + + void waitOnStartup(bool startup); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed + void waitOnRundown(bool rundown); //!< tells the RoutingReceiver to start waiting for all handles to be confirmed private: DatabaseHandler *mDatabaseHandler; //!< pointer to the databaseHandler @@ -91,6 +99,12 @@ private: SocketHandler *mSocketHandler; //!< pointer to sockethandler DBusWrapper *mDBusWrapper; //!< pointer to dbuswrapper + uint16_t handleCount; //!< counts all handles + std::vector<uint16_t> mListStartupHandles; //!< list of handles that wait for a confirm + 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 + }; } diff --git a/AudioManagerDaemon/include/RoutingSender.h b/AudioManagerDaemon/include/RoutingSender.h index 0888b6a..308d5e5 100644 --- a/AudioManagerDaemon/include/RoutingSender.h +++ b/AudioManagerDaemon/include/RoutingSender.h @@ -35,6 +35,8 @@ namespace am { +class RoutingReceiver; + /** * Implements the RoutingSendInterface. Loads all plugins and dispatches calls to the plugins */ @@ -95,9 +97,9 @@ public: * this removes the Crossfader to the lookup table of the Router. This must be done everytime a crossfader is deregistered. */ am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID); - void startupRoutingInterface(RoutingReceiveInterface* routingreceiveinterface); - void routingInterfacesReady(); - void routingInterfacesRundown(); + am_Error_e startupInterfaces(RoutingReceiver* iRoutingReceiver); + void setRoutingReady(); + void setRoutingRundown(); am_Error_e asyncAbort(const am_Handle_s& handle); am_Error_e asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); am_Error_e asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID); @@ -112,7 +114,7 @@ public: am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState); am_Error_e getListHandles(std::vector<am_Handle_s> & listHandles) const; am_Error_e getListPlugins(std::vector<std::string>& interfaces) const; - uint16_t getInterfaceVersion() const; + void getInterfaceVersion(std::string& version) const; //!< is used to pair interfaces with busnames struct InterfaceNamePairs @@ -192,6 +194,7 @@ private: SinkInterfaceMap mMapSinkInterface; //!< map of sinks to interfaces SourceInterfaceMap mMapSourceInterface; //!< map of sources to interfaces HandleInterfaceMap mMapHandleInterface; //!< map of handles to interfaces + RoutingReceiver *mRoutingReceiver; }; } diff --git a/AudioManagerDaemon/include/mainpage.h b/AudioManagerDaemon/include/mainpage.h new file mode 100644 index 0000000..8d8fdab --- /dev/null +++ b/AudioManagerDaemon/include/mainpage.h @@ -0,0 +1,115 @@ +/** + * \mainpage + * + * + * \image html genivilogo.png + * + * \author Christian Mueller (christian.ei.mueller@bmw.de) + * + * \par Copyright + * Copyright Copyright (C) 2011,2012 GENIVI Alliance\n + * Copyright Copyright (C) 2011,2012 BMW AG + * + * \par License + * Contributions are licensed to the GENIVI Alliance under one or more Contribution License Agreements. + * This file is licensed under the terms of the Mozilla Public License 2.0.\n + * A copy of the license text has been included in the “LICENSE” file in the root directory of the source distribution. + * You can also obtain a copy of the license text at\n + * http://mozilla.org/MPL/2.0/. + * + * \par More information + * can be found at https://collab.genivi.org/wiki/display/genivi/GENIVI+Home \n + * + * \par About AudioManager + * The AudioManager is a Deamon that manages all Audio Connections in a GENIVI headunit. + * It is a managing instance that uses so called RoutingAdaptors to control AudioDomains that then do the "real" connections. + * \n\n\n + * + * + * \section architecture Architecture Overview + * + * The architecture concept bases on the partition of management (logic) and routing (action). Sinks and sources are clustered into independent parts which are capable of exchanging audio with each other (AudioDomains). Between these AudioDomains, Audio can be interchanged via Gateways. \n + * Since the routing and the management shall be independent from the actual used system, it is realized as an OwnedComponent, the AudioManager. Each AudioDomain has a Routing Adapter which implements some necessary logic and is the interface between the AudioManager and the AudioDomains. + * + * \section domains Audio Domains + * + * An Audio Domain consists of sinks and sources that can exchange audio with each other. To make the most out of the concept, AudioDomains shall be chosen in such a way that they are implemented by already existing audio routing engines. + * + * The AudioManager assumes that there are no restrictions in interconnection of sinks and sources. One or more sources can be connected to one sink and one or more sinks can be connected to one source. Since real hardware or software might end up in having restrictions, the knowledge of this must exist in the AudioManager and handled by him accordingly. This shall be accomplished via a plug-in mechanism. An AudioDomain is not tied to a hardware or software implementation. It can be software or hardware or even a combination of both. \n + * + * Examples for possible audio domains:\n + * PulseAudio, Alsa, Jack, DSP, FPGA, MOST, In-chip switching matrix\n + * + * The clustering and usage of the AudioDomains will vary from each product. Care must be taken while choosing the right AudioDomains in regards to system load (due to resampling), latency and of course flexibility.\n + * In special implementations of the AudioDomain, it is capable of operation a certain time without interaction to the AudioManager. This is needed to fulfill the requirements for Early & Late Audio, more information can be found below. + * + * \section routing_adaptor Routing Adapter + * + * Via this adapter, the interconnection from the AudioManager to the AudioDomains is accomplished. An AudioDomain shall have exactly one RoutingAdapter. In the terms of GENIVI, a RoutingAdapter is an AbstractComponent, this means that we define an API and a certain behavior in UML models but do not maintain components itself. Existing implementations from Proof of Concepts are shipped as example Adapters "as is" but cannot be seen as maintained components.\n + * The implementation of a routing adapter can and will vary from each project to another since the combination of sinks and sources, the used hardware etc has influence on the adapters. Besides interchanging and abstracting information between the AudioManager and the sinks and sources, the Adapters also need to implement some business logic in order to interact with the AudioManager. This includes for example the registering of components, managing the current state, error handling etc.\n + * In the special case of an EarlyDomain, the routing adapter also has to manage start-up and rundown including persistence for his domain while the AudioManager is not started or already stopped. During this periods of time, these special adapters have to be able to fulfill basic tasks like changing volumes, for example (this implies that the Adapter is implemented on a different piece of hardware, e.g. vehicle processor). + * + * \section Gateway + * + * Gateways are used to let audio flow between two domains. They always have a direction and can only transport one stream at a time. Several gateways connecting the same domains together can exist in parallel so that more than one source can be connected to more than one sink from the same domains at the same time.\n + * The representation of a Gateway in the domain which originates the audio is a sink. In the receiving domain, the gateway appears as a source. The AudioManager knows about the Gateways, in terms of connection, it handles it as simple sources and sinks. + * + * \section AudioManagerDaemon + * + * The AudioManager is the central managing instance of the Audio architecture. It is designed as an OwnedComponent, this means that the software is maintained within GENIVI as open source component. The AudioManager consists of 4 central components.\n + * + * GOwnedComponent: AudioManager Daemon\n + * + * This component is owned and maintained by Genivi. It is the central audio framework component. There can be only one daemon in a system (singleton). + * + * \subsection controlinterface Control Interface Plugin + * + * This describes the interface towards the Controlling Instances of the AudioManagerDaemon. This is the HMI and interrupt sources that use this interface to start their interrupt and stop it again. The interface shall be asynchronous. Via this interface all user interactions are handled. + * + * \subsection routinginterface Routing Interface Plugin + * + * This interface is used by the AudioManager to control the RoutingAdapters and communicate with them. The communication is based on two interfaces, one is provided by the AudioManager for communication from the adapters towards the AudioManager and one for the opposite direction. The design of the AudioManager shall be done in such a way that several Interfaces are supported at the same time via a plug-in mechanism. The plug-ins are (either statically - due to performance reasons or dynamically) loaded at start-up. Due to this architecture, the number of buses and routing adapters that are supported are as low as possible for each system and as high as needed without the need of changing the AudioManager itself. The AudioManager expects a bus-like structure behind each plug-in, so that a plug-in can implement a bus interface and proxy the messages to the routing adapters - the AudioManager will be capable of addressing more than one adapter one each plug-in. The interface shall is asynchronous for all timely critical commands. + * + * \section interfaces Interfaces + * the calls to the interfaces of the AudioManagerDaemon are generally not threadsafe ! + * Nevertheless if such calls from a different thread-context are needed, you may use the defered-call pattern that utilizes the mainloop (Sockethandler) to get self called in the next loop of the mainloop. For more infomation please check the audiomanger wiki page. + * + * \section deferred The deferred call pattern + * Create a unix pipe or socket and add the file descriptor to the Sockethandler. Whenever a call needs to be deferred you can store the necessary information protected by a mutex in a queue and write to the socket or pipe. This will lead to a callback in the next loop of the mainloop - when getting called by the callback that was registered at the Sockethandler execute your call with the information stored away. + * + * + * \section sources_sinks Sources & Sinks + * \subsection Visibility + * Sources and sinks can either be visible or not. If they are visible, the HMI is informed about their existence and can use them. \n + * Invisible Sources and Sinks either are system only relevant (e.g. an audio processing that has a source and a sink) or belong to a gateway. + * + * \subsection Availability + * It can be the case, that sources and sinks are present in the system but cannot be used at the moment. This is indicated via the availability. A sample use-case for this feature is CD drive that shall only be available if a CD is inserted. + * + * \section Interrupts + * \subsection llinterrupts Low level interrupts + * \todo write low level Interrupts description + * + * \subsection Interrupts + * \todo write Interrupts description + * + * \section Persistency + * It is the job of the AudioManagerController to handle the persistency. It is planned to expose an interface via the ControlInterface to accomplish this but the GENIVI persistance is not ready yet. \n + * + * + * \section speed Speed dependent volume + * The adjustments for the speed are done product specific in the controller. The speed information itself is retrieved by the AudioManagerDaemon, sampled and quantified and forwarded to the controller.\n + * Turning speed controlled volume on/off and possible settings are achieved via SinkSoundProperty settings. + * + * \section Lipsync + * It is the job of the AudioManager to retrieve all latency timing information from each connection, to aggregate this information and provide a latency information on a per MainConnection Basis. It is not the task of the AudioManager to actually delay or speed up video or audio signals to achieve a lipsync. The actual correction shall be done in the videoplayer with the information provided by the AudioManager. + * The time information is always reported by the routingadaptors for each connection. Delays that are introduced in a sink or a gateway are counting for the connection that connects to this sink or gateway.\n + * After the buildup of a connection the first timing information needs to be sent within 5 seconds, the timing information from the routing adaptors need to be sent via 4 seconds. If the latency for a connection is variable and changes over lifetime of the connection, the routing adaptors shall resend the value and the audiomanger will correct the over all latency.\n + * @author Christian Mueller + * @created 25-Feb-2012 3:54:06 PM + */ + +#ifndef MAINPAGE_H_ +#define MAINPAGE_H_ + +#endif /* MAINPAGE_H_ */ diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp index 2066487..9e052cc 100644 --- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp +++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp @@ -741,7 +741,13 @@ void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & (void) CmdQueue; std::stringstream output; - output << "\tSender versions:" << std::endl << "\tCtrl: " << mpControlSender->getInterfaceVersion() << " | " << "Cmd: " << mpCommandSender->getInterfaceVersion() << " | " << "Routing: " << mpRoutingSender->getInterfaceVersion() << std::endl; + std::string versionCommand; + std::string versionRouting; + std::string versionControl; + mpControlSender->getInterfaceVersion(versionControl); + mpRoutingSender->getInterfaceVersion(versionRouting); + mpCommandSender->getInterfaceVersion(versionCommand); + output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; sendTelnetLine(filedescriptor, output); } @@ -760,7 +766,13 @@ void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> (void) CmdQueue; std::stringstream output; - output << "\tReceiver versions:" << std::endl << "\tCtrl: " << mpControlReceiver->getInterfaceVersion() << " | " << "Cmd: " << mpCommandReceiver->getInterfaceVersion() << " | " << "Routing: " << mpRoutingReceiver->getInterfaceVersion() << std::endl; + std::string versionCommand; + std::string versionRouting; + std::string versionControl; + mpControlReceiver->getInterfaceVersion(versionControl); + mpRoutingReceiver->getInterfaceVersion(versionRouting); + mpCommandReceiver->getInterfaceVersion(versionCommand); + output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; sendTelnetLine(filedescriptor, output); diff --git a/AudioManagerDaemon/src/CommandReceiver.cpp b/AudioManagerDaemon/src/CommandReceiver.cpp index ff092dd..74b819b 100644 --- a/AudioManagerDaemon/src/CommandReceiver.cpp +++ b/AudioManagerDaemon/src/CommandReceiver.cpp @@ -29,13 +29,19 @@ #include <SocketHandler.h> #include <config.h> #include <cassert> +#include <algorithm> using namespace am; CommandReceiver::CommandReceiver(DatabaseHandler *iDatabaseHandler, ControlSender *iControlSender, SocketHandler *iSocketHandler) : mDatabaseHandler(iDatabaseHandler), // mControlSender(iControlSender), // - mSocketHandler(iSocketHandler) + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) + { assert(mDatabaseHandler!=NULL); assert(mSocketHandler!=NULL); @@ -46,7 +52,11 @@ CommandReceiver::CommandReceiver(DatabaseHandler *iDatabaseHandler, ControlSende mDatabaseHandler(iDatabaseHandler), // mControlSender(iControlSender), // mDBusWrapper(iDBusWrapper), // - mSocketHandler(iSocketHandler) + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) { assert(mDatabaseHandler!=NULL); assert(mSocketHandler!=NULL); @@ -168,8 +178,46 @@ am_Error_e CommandReceiver::getSocketHandler(SocketHandler *& socketHandler) con return E_OK; } -uint16_t CommandReceiver::getInterfaceVersion() const +void CommandReceiver::getInterfaceVersion(std::string & version) const +{ + version = CommandReceiveVersion; +} + +void CommandReceiver::confirmCommandReady(const uint16_t handle) +{ + mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end()); + if (mWaitStartup && mListStartupHandles.empty()) + mControlSender->confirmCommandReady(); +} + +void CommandReceiver::confirmCommandRundown(const uint16_t handle) +{ + mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end()); + if (mWaitRundown && mListRundownHandles.empty()) + mControlSender->confirmCommandRundown(); +} + +uint16_t CommandReceiver::getStartupHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListStartupHandles.push_back(handle); + return handle; +} + +uint16_t CommandReceiver::getRundownHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListRundownHandles.push_back(handle); + return handle; +} + +void am::CommandReceiver::waitOnStartup(bool startup) +{ + mWaitStartup = startup; +} + +void am::CommandReceiver::waitOnRundown(bool rundown) { - return CommandReceiveVersion; + mWaitRundown = rundown; } diff --git a/AudioManagerDaemon/src/CommandSender.cpp b/AudioManagerDaemon/src/CommandSender.cpp index c70509f..c613a4e 100644 --- a/AudioManagerDaemon/src/CommandSender.cpp +++ b/AudioManagerDaemon/src/CommandSender.cpp @@ -23,14 +23,17 @@ */ #include "CommandSender.h" -#include "command/CommandReceiveInterface.h" #include <dirent.h> +#include <sstream> +#include <string> +#include "CommandReceiver.h" #include "PluginTemplate.h" #include "DLTWrapper.h" using namespace am; -#define REQUIRED_INTERFACE_VERSION 1 +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 //!< macro to call all interfaces #define CALL_ALL_INTERFACES(...) \ @@ -43,8 +46,9 @@ using namespace am; CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirectories) : mListInterfaces(), // - mListLibraryHandles(), - mListLibraryNames() + mListLibraryHandles(), // + mListLibraryNames(), // + mCommandReceiver() { std::vector<std::string> sharedLibraryNameList; std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin(); @@ -54,12 +58,12 @@ CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirecto for (; dirIter < dirIterEnd; ++dirIter) { const char* directoryName = dirIter->c_str(); - logInfo("Searching for CommandPlugins in" , *dirIter); + logInfo("Searching for CommandPlugins in", *dirIter); DIR *directory = opendir(directoryName); if (!directory) { - logError("Error opening directory ",*dirIter); + logError("Error opening directory ", *dirIter); continue; } @@ -108,9 +112,15 @@ CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirecto } //check libversion - if (commander->getInterfaceVersion() < REQUIRED_INTERFACE_VERSION) + std::string version; + commander->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) { - logInfo("RoutingPlugin initialization failed. Version of Interface to old"); + logInfo("CommandInterface initialization failed. Version of Interface to old"); continue; } @@ -125,32 +135,16 @@ CommandSender::~CommandSender() unloadLibraries(); } -am_Error_e CommandSender::stopInterface() -{ - am_Error_e returnError = E_OK; - - std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); - std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end(); - for (; iter < iterEnd; ++iter) - { - am_Error_e error = (*iter)->stopInterface(); - if (error != E_OK) - { - returnError = error; - } - } - return returnError; -} - -am_Error_e CommandSender::startupInterface(CommandReceiveInterface *commandreceiveinterface) +am_Error_e CommandSender::startupInterfaces(CommandReceiver *iCommandReceiver) { + mCommandReceiver = iCommandReceiver; am_Error_e returnError = E_OK; std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end(); for (; iter < iterEnd; ++iter) { - am_Error_e error = (*iter)->startupInterface(commandreceiveinterface); + am_Error_e error = (*iter)->startupInterface(iCommandReceiver); if (error != E_OK) { returnError = error; @@ -159,31 +153,6 @@ am_Error_e CommandSender::startupInterface(CommandReceiveInterface *commandrecei return returnError; } -void CommandSender::cbCommunicationReady() -{ - CALL_ALL_INTERFACES(cbCommunicationReady()) -} - -void CommandSender::cbCommunicationRundown() -{ - CALL_ALL_INTERFACES(cbCommunicationRundown()) -} - -void CommandSender::cbNumberOfMainConnectionsChanged() -{ - CALL_ALL_INTERFACES(cbNumberOfMainConnectionsChanged()) -} - -void CommandSender::cbNumberOfSinksChanged() -{ - CALL_ALL_INTERFACES(cbNumberOfSinksChanged()) -} - -void CommandSender::cbNumberOfSourcesChanged() -{ - CALL_ALL_INTERFACES(cbNumberOfSourcesChanged()) -} - void CommandSender::cbNumberOfSinkClassesChanged() { CALL_ALL_INTERFACES(cbNumberOfSinkClassesChanged()) @@ -199,12 +168,12 @@ void CommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t con CALL_ALL_INTERFACES(cbMainConnectionStateChanged(connectionID,connectionState)) } -void CommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty) +void CommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) { CALL_ALL_INTERFACES(cbMainSinkSoundPropertyChanged(sinkID,SoundProperty)) } -void CommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) +void CommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) { CALL_ALL_INTERFACES(cbMainSourceSoundPropertyChanged(sourceID,SoundProperty)) } @@ -239,34 +208,69 @@ void CommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainC CALL_ALL_INTERFACES(cbTimingInformationChanged(mainConnection,time)) } -am_Error_e am::CommandSender::getListPlugins(std::vector<std::string> & interfaces) const +void CommandSender::cbNewMainConnection(const am_MainConnectionType_s mainConnection) { - interfaces = mListLibraryNames; - return E_OK; + CALL_ALL_INTERFACES(cbNewMainConnection(mainConnection)) } -void am::CommandSender::cbNewMainConnection(const am_MainConnectionType_s mainConnection) +void CommandSender::cbRemovedMainConnection(const am_mainConnectionID_t mainConnection) { + CALL_ALL_INTERFACES(cbRemovedMainConnection(mainConnection)) } -void am::CommandSender::cbRemovedMainConnection(const am_MainConnectionType_s mainConnection) +void CommandSender::cbNewSink(const am_SinkType_s sink) { + CALL_ALL_INTERFACES(cbNewSink(sink)) } -void am::CommandSender::cbNewSink(const am_SinkType_s sink) +void CommandSender::cbRemovedSink(const am_sinkID_t sink) { + CALL_ALL_INTERFACES(cbRemovedSink(sink)) } -void am::CommandSender::cbRemovedSink(const am_SinkType_s sink) +void CommandSender::cbNewSource(const am_SourceType_s source) { + CALL_ALL_INTERFACES(cbNewSource(source)) } -void am::CommandSender::cbNewSource(const am_SourceType_s source) +void CommandSender::cbRemovedSource(const am_sourceID_t source) { + CALL_ALL_INTERFACES(cbRemovedSource(source)) } -void am::CommandSender::cbRemovedSource(const am_SourceType_s source) +void CommandSender::setCommandReady() { + mCommandReceiver->waitOnStartup(false); + std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); + std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandReady(mCommandReceiver->getStartupHandle()); + } + mCommandReceiver->waitOnStartup(true); +} + +void CommandSender::setCommandRundown() +{ + mCommandReceiver->waitOnRundown(false); + std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); + std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter)->setCommandRundown(mCommandReceiver->getRundownHandle()); + } + mCommandReceiver->waitOnRundown(true); +} + +void CommandSender::getInterfaceVersion(std::string & version) const +{ + version = CommandSendVersion; +} + +am_Error_e am::CommandSender::getListPlugins(std::vector<std::string> & interfaces) const +{ + interfaces = mListLibraryNames; + return E_OK; } void CommandSender::unloadLibraries(void) @@ -279,8 +283,3 @@ void CommandSender::unloadLibraries(void) mListLibraryHandles.clear(); } -uint16_t CommandSender::getInterfaceVersion() const -{ - return CommandSendVersion; -} - diff --git a/AudioManagerDaemon/src/ControlReceiver.cpp b/AudioManagerDaemon/src/ControlReceiver.cpp index 2b2e8b0..8ef8d23 100644 --- a/AudioManagerDaemon/src/ControlReceiver.cpp +++ b/AudioManagerDaemon/src/ControlReceiver.cpp @@ -468,13 +468,23 @@ am_Error_e ControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceCla void ControlReceiver::setCommandReady() { logInfo("ControlReceiver::setCommandReady got called"); - mCommandSender->cbCommunicationReady(); + mCommandSender->setCommandReady(); } void ControlReceiver::setRoutingReady() { logInfo("ControlReceiver::setRoutingReady got called"); - mRoutingSender->routingInterfacesReady(); + mRoutingSender->setRoutingReady(); +} + +void ControlReceiver::confirmControllerReady() +{ + //todo: one time implement here system interaction with NSM +} + +void ControlReceiver::confirmControllerRundown() +{ + //todo: one time implement here system interaction with NSM } am_Error_e ControlReceiver::getSocketHandler(SocketHandler *& socketHandler) @@ -483,20 +493,22 @@ am_Error_e ControlReceiver::getSocketHandler(SocketHandler *& socketHandler) return E_OK; } -void am::ControlReceiver::setCommandRundown() +void ControlReceiver::setCommandRundown() { logInfo("ControlReceiver::setCommandRundown got called"); - mCommandSender->cbCommunicationRundown(); + mCommandSender->setCommandRundown(); } -void am::ControlReceiver::setRoutingRundown() +void ControlReceiver::setRoutingRundown() { logInfo("ControlReceiver::setRoutingRundown got called"); - mRoutingSender->routingInterfacesRundown(); + mRoutingSender->setRoutingRundown(); } -uint16_t ControlReceiver::getInterfaceVersion() const +void ControlReceiver::getInterfaceVersion(std::string & version) const { - return ControlReceiveVersion; + version = ControlReceiveVersion; } + + diff --git a/AudioManagerDaemon/src/ControlSender.cpp b/AudioManagerDaemon/src/ControlSender.cpp index a334475..492244e 100644 --- a/AudioManagerDaemon/src/ControlSender.cpp +++ b/AudioManagerDaemon/src/ControlSender.cpp @@ -27,10 +27,14 @@ #include "DLTWrapper.h" #include <cassert> #include <fstream> +#include <iostream> +#include <sstream> +#include <stdexcept> using namespace am; -#define REQUIRED_MIN_INTERFACE_VERSION 1 +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 ControlSender::ControlSender(std::string controlPluginFile) : mlibHandle(NULL), // @@ -49,7 +53,17 @@ ControlSender::ControlSender(std::string controlPluginFile) : mController = createFunc(); //check libversion - assert(REQUIRED_MIN_INTERFACE_VERSION<=mController->getInterfaceVersion()); + std::string version; + mController->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) + { + logError("ControlSender::ControlSender: Interface Version of Controller too old, exiting now"); + throw std::runtime_error("Interface Version of Controller too old"); + } } else { @@ -63,11 +77,6 @@ ControlSender::~ControlSender() dlclose(mlibHandle); } -void ControlSender::hookAllPluginsLoaded() -{ - mController->hookAllPluginsLoaded(); -} - am_Error_e ControlSender::hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID) { return mController->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID); @@ -248,11 +257,6 @@ am_Error_e ControlSender::startupController(ControlReceiveInterface *controlrece return mController->startupController(controlreceiveinterface); } -am_Error_e ControlSender::stopController() -{ - return mController->stopController(); -} - void ControlSender::cbAckSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) { mController->cbAckSetSinkSoundProperty(handle, error); @@ -268,13 +272,43 @@ void ControlSender::cbAckSetSourceSoundProperties(const am_Handle_s handle, cons mController->cbAckSetSourceSoundProperties(handle, error); } +void ControlSender::setControllerReady() +{ + mController->setControllerReady(); +} + +void ControlSender::setControllerRundown() +{ + mController->setControllerRundown(); +} + am_Error_e am::ControlSender::getConnectionFormatChoice(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector<am_ConnectionFormat_e> listPossibleConnectionFormats, std::vector<am_ConnectionFormat_e> & listPrioConnectionFormats) { return mController->getConnectionFormatChoice(sourceID, sinkID, listRoute, listPossibleConnectionFormats, listPrioConnectionFormats); } -uint16_t ControlSender::getInterfaceVersion() const +void ControlSender::getInterfaceVersion(std::string & version) const +{ + version = ControlSendVersion; +} + +void ControlSender::confirmCommandReady() +{ + mController->confirmCommandReady(); +} + +void ControlSender::confirmRoutingReady() +{ + mController->confirmRoutingReady(); +} + +void ControlSender::confirmCommandRundown() +{ + mController->confirmCommandRundown(); +} + +void ControlSender::confirmRoutingRundown() { - return ControlSendVersion; + mController->confirmRoutingRundown(); } diff --git a/AudioManagerDaemon/src/DBusWrapper.cpp b/AudioManagerDaemon/src/DBusWrapper.cpp index bfe6706..71352ef 100644 --- a/AudioManagerDaemon/src/DBusWrapper.cpp +++ b/AudioManagerDaemon/src/DBusWrapper.cpp @@ -103,7 +103,7 @@ DBusWrapper::DBusWrapper(SocketHandler* socketHandler) : } if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { - logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner",ret); + logError("DBusWrapper::DBusWrapper Wrapper is not the Primary Owner ! Another instance already running?",ret); exit(1); } } diff --git a/AudioManagerDaemon/src/DatabaseHandler.cpp b/AudioManagerDaemon/src/DatabaseHandler.cpp index a80e241..54e0129 100644 --- a/AudioManagerDaemon/src/DatabaseHandler.cpp +++ b/AudioManagerDaemon/src/DatabaseHandler.cpp @@ -262,7 +262,13 @@ am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & ma if (mDatabaseObserver) { - mDatabaseObserver->numberOfMainConnectionsChanged(); + am_MainConnectionType_s mainConnection; + mainConnection.mainConnectionID=connectionID; + mainConnection.connectionState=mainConnectionData.connectionState; + mainConnection.delay=delay; + mainConnection.sinkID=mainConnectionData.sinkID; + mainConnection.sourceID=mainConnectionData.sourceID; + mDatabaseObserver->newMainConnection(mainConnection); mDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState); } @@ -1227,7 +1233,7 @@ am_Error_e DatabaseHandler::removeMainConnectionDB(const am_mainConnectionID_t m if (mDatabaseObserver) { mDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); - mDatabaseObserver->numberOfMainConnectionsChanged(); + mDatabaseObserver->removedMainConnection(mainConnectionID); } return E_OK; } @@ -1240,6 +1246,9 @@ am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID) { return E_NON_EXISTENT; } + + bool visible=sinkVisible(sinkID); + std::string command = "DELETE from " + std::string(SINK_TABLE) + " WHERE sinkID=" + i2s(sinkID); std::string command1 = "DROP table SinkConnectionFormat" + i2s(sinkID); std::string command2 = "DROP table SinkMainSoundProperty" + i2s(sinkID); @@ -1255,7 +1264,7 @@ am_Error_e DatabaseHandler::removeSinkDB(const am_sinkID_t sinkID) logInfo("DatabaseHandler::removeSinkDB removed:", sinkID); if (mDatabaseObserver != NULL) - mDatabaseObserver->removedSink(sinkID); + mDatabaseObserver->removedSink(sinkID,visible); return E_OK; } @@ -1268,6 +1277,9 @@ am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID) { return E_NON_EXISTENT; } + + bool visible=sourceVisible(sourceID); + std::string command = "DELETE from " + std::string(SOURCE_TABLE) + " WHERE sourceID=" + i2s(sourceID); std::string command1 = "DROP table SourceConnectionFormat" + i2s(sourceID); std::string command2 = "DROP table SourceMainSoundProperty" + i2s(sourceID); @@ -1282,7 +1294,7 @@ am_Error_e DatabaseHandler::removeSourceDB(const am_sourceID_t sourceID) return E_DATABASE_ERROR; logInfo("DatabaseHandler::removeSourceDB removed:", sourceID); if (mDatabaseObserver) - mDatabaseObserver->removedSource(sourceID); + mDatabaseObserver->removedSource(sourceID,visible); return E_OK; } diff --git a/AudioManagerDaemon/src/DatabaseObserver.cpp b/AudioManagerDaemon/src/DatabaseObserver.cpp index a1bc123..93031ef 100644 --- a/AudioManagerDaemon/src/DatabaseObserver.cpp +++ b/AudioManagerDaemon/src/DatabaseObserver.cpp @@ -16,7 +16,7 @@ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details. * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense. - * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception. + * Linking AudioManager statiasyncCally or dynamiasyncCally with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception. * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned. * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception. * @@ -32,317 +32,175 @@ #include "RoutingSender.h" #include "TelnetServer.h" #include "DLTWrapper.h" +//#include "CAmSerializer.h" using namespace am; DatabaseObserver::DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler) : - receiverCallbackT(this, &DatabaseObserver::receiverCallback), // - dispatcherCallbackT(this, &DatabaseObserver::dispatcherCallback), // - checkerCallbackT(this, &DatabaseObserver::checkerCallback), // mCommandSender(iCommandSender), // mRoutingSender(iRoutingSender), // - mSocketHandler(iSocketHandler), // - mPipe(), // - mHandle(), // - mQueue() + mSerializer(iSocketHandler) // { - commonConstructor(); + assert(mCommandSender!=0); + assert(mRoutingSender!=0); + assert(iSocketHandler!=0); } DatabaseObserver::DatabaseObserver(CommandSender *iCommandSender, RoutingSender *iRoutingSender, SocketHandler *iSocketHandler, TelnetServer *iTelnetServer) : - receiverCallbackT(this, &DatabaseObserver::receiverCallback), // - dispatcherCallbackT(this, &DatabaseObserver::dispatcherCallback), // - checkerCallbackT(this, &DatabaseObserver::checkerCallback), // mCommandSender(iCommandSender), // mRoutingSender(iRoutingSender), // mTelnetServer(iTelnetServer), // - mSocketHandler(iSocketHandler), // - mPipe(), // - mHandle(), // - mQueue() + mSerializer(iSocketHandler) // { assert(mTelnetServer!=0); - commonConstructor(); + assert(mCommandSender!=0); + assert(mRoutingSender!=0); + assert(iSocketHandler!=0); } -void DatabaseObserver::pipeCommand(const do_msg_s & message) +DatabaseObserver::~DatabaseObserver() { - mQueue.push(message); - - if (write(mPipe[1], &message.msgID, sizeof(do_msg_s)) == -1) - { - logError("DatabaseObserver::msgID pipe write failed, error code:", strerror(errno)); - } } -void DatabaseObserver::commonConstructor() +void DatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) { - assert(mCommandSender!=0); - assert(mRoutingSender!=0); - assert(mSocketHandler!=0); - if (pipe(mPipe) == -1) - { - logError("RoutingReceiverAsyncShadow::setRoutingInterface could not create pipe!:"); - throw "could not create pipe"; - } - - short event = 0; - event |= POLLIN; - mSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, mHandle); + mSerializer.asyncCall<CommandSender, const am_MainConnectionType_s>(mCommandSender, &CommandSender::cbNewMainConnection, mainConnection); } -DatabaseObserver::~DatabaseObserver() +void DatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) { + mSerializer.asyncCall<CommandSender, const am_mainConnectionID_t>(mCommandSender, &CommandSender::cbRemovedMainConnection, mainConnection); } -void DatabaseObserver::newSink(am_Sink_s sink) +void DatabaseObserver::newSink(const am_Sink_s& sink) { mRoutingSender->addSinkLookup(sink); - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSinksChanged; - pipeCommand(msg); - + if (sink.visible) + { + am_SinkType_s s; + s.availability = sink.available; + s.muteState = sink.muteState; + s.name = sink.name; + s.sinkClassID = sink.sinkClassID; + s.sinkID = sink.sinkID; + s.volume = sink.mainVolume; + mSerializer.asyncCall<CommandSender, const am_SinkType_s>(mCommandSender, &CommandSender::cbNewSink, s); + } } -void DatabaseObserver::newSource(am_Source_s source) +void DatabaseObserver::newSource(const am_Source_s& source) { mRoutingSender->addSourceLookup(source); - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSourcesChanged; - pipeCommand(msg); + if (source.visible) + { + am_SourceType_s s; + s.availability = source.available; + s.name = source.name; + s.sourceClassID = source.sourceClassID; + s.sourceID = source.sourceID; + mSerializer.asyncCall<CommandSender, const am_SourceType_s>(mCommandSender, &CommandSender::cbNewSource, s); + } } -void DatabaseObserver::newDomain(am_Domain_s domain) +void DatabaseObserver::newDomain(const am_Domain_s& domain) { mRoutingSender->addDomainLookup(domain); } -void DatabaseObserver::newGateway(am_Gateway_s gateway) +void DatabaseObserver::newGateway(const am_Gateway_s& gateway) { (void) gateway; //todo: implement something } -void DatabaseObserver::newCrossfader(am_Crossfader_s crossfader) +void DatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) { mRoutingSender->addCrossfaderLookup(crossfader); } -void DatabaseObserver::removedSink(am_sinkID_t sinkID) +void DatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) { mRoutingSender->removeSinkLookup(sinkID); - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSinksChanged; - pipeCommand(msg); + + if (visible) + mSerializer.asyncCall<CommandSender, const am_sinkID_t>(mCommandSender, &CommandSender::cbRemovedSink, sinkID); } -void DatabaseObserver::removedSource(am_sourceID_t sourceID) +void DatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) { mRoutingSender->removeSourceLookup(sourceID); - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSourcesChanged; - pipeCommand(msg); + + if (visible) + mSerializer.asyncCall<CommandSender, const am_sourceID_t>(mCommandSender, &CommandSender::cbRemovedSource, sourceID); } -void DatabaseObserver::removeDomain(am_domainID_t domainID) +void DatabaseObserver::removeDomain(const am_domainID_t domainID) { mRoutingSender->removeDomainLookup(domainID); } -void DatabaseObserver::removeGateway(am_gatewayID_t gatewayID) +void DatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) { (void) gatewayID; - //todo: implement something + //todo: implement something? } -void DatabaseObserver::removeCrossfader(am_crossfaderID_t crossfaderID) +void DatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) { mRoutingSender->removeCrossfaderLookup(crossfaderID); } -void DatabaseObserver::numberOfMainConnectionsChanged() -{ - do_msg_s msg; - msg.msgID = MDO_cbNumberOfMainConnectionsChanged; - pipeCommand(msg); -} - void DatabaseObserver::numberOfSinkClassesChanged() { - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSinkClassesChanged; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender>(mCommandSender, &CommandSender::cbNumberOfSinkClassesChanged); } void DatabaseObserver::numberOfSourceClassesChanged() { - do_msg_s msg; - msg.msgID = MDO_cbNumberOfSourceClassesChanged; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender>(mCommandSender, &CommandSender::cbNumberOfSourceClassesChanged); } void DatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) { - do_msg_s msg; - msg.msgID = MDO_cbMainConnectionStateChanged; - msg.parameters.connectionStateChanged.connectionID = connectionID; - msg.parameters.connectionStateChanged.connectionState = connectionState; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_connectionID_t, const am_ConnectionState_e>(mCommandSender, &CommandSender::cbMainConnectionStateChanged, connectionID, connectionState); } -void DatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty) +void DatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) { - do_msg_s msg; - msg.msgID = MDO_cbMainSinkSoundPropertyChanged; - msg.parameters.mainSinkSoundPropertyChanged.sinkID = sinkID; - msg.parameters.mainSinkSoundPropertyChanged.SoundProperty = SoundProperty; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sinkID_t, const am_MainSoundProperty_s&>(mCommandSender, &CommandSender::cbMainSinkSoundPropertyChanged, sinkID, SoundProperty); } void DatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) { - do_msg_s msg; - msg.msgID = MDO_cbMainSourceSoundPropertyChanged; - msg.parameters.mainSourceSoundPropertyChanged.sourceID = sourceID; - msg.parameters.mainSourceSoundPropertyChanged.SoundProperty = SoundProperty; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sourceID_t, const am_MainSoundProperty_s&>(mCommandSender, &CommandSender::cbMainSourceSoundPropertyChanged, sourceID, SoundProperty); } void DatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) { - do_msg_s msg; - msg.msgID = MDO_cbSinkAvailabilityChanged; - msg.parameters.sinkAvailabilityChanged.sinkID = sinkID; - msg.parameters.sinkAvailabilityChanged.availability = availability; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sinkID_t, const am_Availability_s&>(mCommandSender, &CommandSender::cbSinkAvailabilityChanged, sinkID, availability); } void DatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) { - do_msg_s msg; - msg.msgID = MDO_cbSourceAvailabilityChanged; - msg.parameters.sourceAvailabilityChanged.sourceID = sourceID; - msg.parameters.sourceAvailabilityChanged.availability = availability; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sourceID_t, const am_Availability_s&>(mCommandSender, &CommandSender::cbSourceAvailabilityChanged, sourceID, availability); } void DatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) { - do_msg_s msg; - msg.msgID = MDO_cbVolumeChanged; - msg.parameters.volumeChanged.sinkID = sinkID; - msg.parameters.volumeChanged.volume = volume; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sinkID_t, const am_mainVolume_t>(mCommandSender, &CommandSender::cbVolumeChanged, sinkID, volume); } void DatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) { - do_msg_s msg; - msg.msgID = MDO_cbSinkMuteStateChanged; - msg.parameters.sinkMuteStateChanged.sinkID = sinkID; - msg.parameters.sinkMuteStateChanged.muteState = muteState; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_sinkID_t, const am_MuteState_e>(mCommandSender, &CommandSender::cbSinkMuteStateChanged, sinkID, muteState); } -void DatabaseObserver::systemPropertyChanged(const am_SystemProperty_s & SystemProperty) +void DatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) { - do_msg_s msg; - msg.msgID = MDO_cbSystemPropertyChanged; - msg.parameters.systemProperty = SystemProperty; - pipeCommand(msg); + mSerializer.asyncCall<CommandSender, const am_SystemProperty_s&>(mCommandSender, &CommandSender::cbSystemPropertyChanged, SystemProperty); } void DatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) { - do_msg_s msg; - msg.msgID = MDO_cbTimingInformationChanged; - msg.parameters.timingInformationChanged.mainConnection = mainConnection; - msg.parameters.timingInformationChanged.time = time; - pipeCommand(msg); - //todo:inform the controller via controlsender + mSerializer.asyncCall<CommandSender, const am_mainConnectionID_t, const am_timeSync_t>(mCommandSender, &CommandSender::cbTimingInformationChanged, mainConnection, time); } - -void DatabaseObserver::receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - //it is no really important what to read here, we will read the queue later... - char buffer[10]; - if (read(pollfd.fd, buffer, 10) == -1) - { - logError("DatabaseObserver::receiverCallback could not read pipe!"); - } -} - -bool DatabaseObserver::dispatcherCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - do_msg_s msg; - - msg = mQueue.front(); - mQueue.pop(); - - switch (msg.msgID) - { - case MDO_cbNumberOfSinksChanged: - mCommandSender->cbNumberOfSinksChanged(); - break; - case MDO_cbNumberOfSourcesChanged: - mCommandSender->cbNumberOfSourcesChanged(); - break; - case MDO_cbNumberOfMainConnectionsChanged: - mCommandSender->cbNumberOfMainConnectionsChanged(); - break; - case MDO_cbNumberOfSinkClassesChanged: - mCommandSender->cbNumberOfSinkClassesChanged(); - break; - case MDO_cbNumberOfSourceClassesChanged: - mCommandSender->cbNumberOfSourceClassesChanged(); - break; - case MDO_cbMainConnectionStateChanged: - mCommandSender->cbMainConnectionStateChanged(msg.parameters.connectionStateChanged.connectionID, msg.parameters.connectionStateChanged.connectionState); - break; - case MDO_cbMainSinkSoundPropertyChanged: - mCommandSender->cbMainSinkSoundPropertyChanged(msg.parameters.mainSinkSoundPropertyChanged.sinkID, msg.parameters.mainSinkSoundPropertyChanged.SoundProperty); - break; - case MDO_cbMainSourceSoundPropertyChanged: - mCommandSender->cbMainSourceSoundPropertyChanged(msg.parameters.mainSourceSoundPropertyChanged.sourceID, msg.parameters.mainSourceSoundPropertyChanged.SoundProperty); - break; - case MDO_cbSinkAvailabilityChanged: - mCommandSender->cbSinkAvailabilityChanged(msg.parameters.sinkAvailabilityChanged.sinkID, msg.parameters.sinkAvailabilityChanged.availability); - break; - case MDO_cbSourceAvailabilityChanged: - mCommandSender->cbSourceAvailabilityChanged(msg.parameters.sourceAvailabilityChanged.sourceID, msg.parameters.sourceAvailabilityChanged.availability); - break; - case MDO_cbVolumeChanged: - mCommandSender->cbVolumeChanged(msg.parameters.volumeChanged.sinkID, msg.parameters.volumeChanged.volume); - break; - case MDO_cbSinkMuteStateChanged: - mCommandSender->cbSinkMuteStateChanged(msg.parameters.sinkMuteStateChanged.sinkID, msg.parameters.sinkMuteStateChanged.muteState); - break; - case MDO_cbSystemPropertyChanged: - mCommandSender->cbSystemPropertyChanged(msg.parameters.systemProperty); - break; - case MDO_cbTimingInformationChanged: - mCommandSender->cbTimingInformationChanged(msg.parameters.timingInformationChanged.mainConnection, msg.parameters.timingInformationChanged.time); - break; - default: - logError("Something went totally wrong in DatabaseObserver::dispatcherCallback"); - break; - } - - if (mQueue.size() > 0) - return (true); - return (false); -} - -bool DatabaseObserver::checkerCallback(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - if (mQueue.size() > 0) - return (true); - return (false); -} - diff --git a/AudioManagerDaemon/src/RoutingReceiver.cpp b/AudioManagerDaemon/src/RoutingReceiver.cpp index 49ee3f9..fb160b0 100644 --- a/AudioManagerDaemon/src/RoutingReceiver.cpp +++ b/AudioManagerDaemon/src/RoutingReceiver.cpp @@ -39,7 +39,11 @@ RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSende mDatabaseHandler(iDatabaseHandler), // mRoutingSender(iRoutingSender), // mControlSender(iControlSender), // - mSocketHandler(iSocketHandler) // + mSocketHandler(iSocketHandler), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) { assert(mDatabaseHandler!=NULL); assert(mRoutingSender!=NULL); @@ -52,7 +56,11 @@ RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSende mRoutingSender(iRoutingSender), // mControlSender(iControlSender), // mSocketHandler(iSocketHandler), // - mDBusWrapper(iDBusWrapper) // + mDBusWrapper(iDBusWrapper), // + mListStartupHandles(), // + mListRundownHandles(), // + mWaitStartup(false), // + mWaitRundown(false) { assert(mDatabaseHandler!=NULL); assert(mRoutingSender!=NULL); @@ -329,8 +337,41 @@ am_Error_e RoutingReceiver::getSocketHandler(SocketHandler *& socketHandler) con return E_OK; } -uint16_t RoutingReceiver::getInterfaceVersion() const +void RoutingReceiver::getInterfaceVersion(std::string & version) const +{ + version = RoutingReceiveVersion; +} + +void RoutingReceiver::confirmRoutingReady(const uint16_t handle) const +{ + +} + +void RoutingReceiver::confirmRoutingRundown(const uint16_t handle) const +{ +} + +uint16_t am::RoutingReceiver::getStartupHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListStartupHandles.push_back(handle); + return handle; +} + +uint16_t am::RoutingReceiver::getRundownHandle() +{ + uint16_t handle = ++handleCount; //todo: handle overflow + mListRundownHandles.push_back(handle); + return handle; +} + +void am::RoutingReceiver::waitOnStartup(bool startup) +{ + mWaitStartup = startup; +} + +void am::RoutingReceiver::waitOnRundown(bool rundown) { - return RoutingReceiveVersion; + mWaitRundown = rundown; } diff --git a/AudioManagerDaemon/src/RoutingSender.cpp b/AudioManagerDaemon/src/RoutingSender.cpp index 16d04b0..76c671d 100644 --- a/AudioManagerDaemon/src/RoutingSender.cpp +++ b/AudioManagerDaemon/src/RoutingSender.cpp @@ -27,12 +27,17 @@ #include <dirent.h> #include <dlfcn.h> #include <cassert> +#include <iostream> +#include <sstream> + +#include "RoutingReceiver.h" #include "PluginTemplate.h" #include "DLTWrapper.h" using namespace am; -#define REQUIRED_INTERFACE_VERSION 1 +#define REQUIRED_INTERFACE_VERSION_MAJOR 1 +#define REQUIRED_INTERFACE_VERSION_MINOR 0 #define CALL_ALL_INTERFACES(...) \ std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); \ @@ -51,7 +56,8 @@ RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirecto mMapDomainInterface(), // mMapSinkInterface(), // mMapSourceInterface(), // - mMapHandleInterface() // + mMapHandleInterface(), // + mRoutingReceiver() { std::vector<std::string> sharedLibraryNameList; std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin(); @@ -61,7 +67,7 @@ RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirecto for (; dirIter < dirIterEnd; ++dirIter) { const char* directoryName = dirIter->c_str(); - logInfo("Searching for HookPlugins in",directoryName); + logInfo("Searching for HookPlugins in", directoryName); DIR *directory = opendir(directoryName); if (!directory) @@ -101,7 +107,7 @@ RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirecto for (; iter != iterEnd; ++iter) { - logInfo("RoutingSender::RoutingSender try loading: " , *iter); + logInfo("RoutingSender::RoutingSender try loading: ", *iter); RoutingSendInterface* (*createFunc)(); void* tempLibHandle = NULL; @@ -125,9 +131,14 @@ RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirecto routerInterface.routingInterface = router; //check libversion - if (router->getInterfaceVersion() < REQUIRED_INTERFACE_VERSION) + std::string version; + router->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + if (majorVersion < REQUIRED_INTERFACE_VERSION_MAJOR || ((majorVersion == REQUIRED_INTERFACE_VERSION_MAJOR) && (minorVersion > REQUIRED_INTERFACE_VERSION_MINOR))) { - logError("RoutingSender::RoutingSender RoutingPlugin initialization failed. Version of Interface to old"); + logInfo("RoutingPlugin initialization failed. Version of Interface to old"); continue; } @@ -154,19 +165,22 @@ RoutingSender::~RoutingSender() } } -void RoutingSender::routingInterfacesReady() -{ - CALL_ALL_INTERFACES(routingInterfacesReady()) -} - -void RoutingSender::routingInterfacesRundown() +am_Error_e RoutingSender::startupInterfaces(RoutingReceiver *iRoutingReceiver) { - CALL_ALL_INTERFACES(routingInterfacesRundown()) -} + mRoutingReceiver = iRoutingReceiver; + am_Error_e returnError = E_OK; -void RoutingSender::startupRoutingInterface(RoutingReceiveInterface *routingreceiveinterface) -{ - CALL_ALL_INTERFACES(startupRoutingInterface(routingreceiveinterface)) + std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); + std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + am_Error_e error = (*iter).routingInterface->startupInterface(iRoutingReceiver); + if (error != E_OK) + { + returnError = error; + } + } + return returnError; } am_Error_e RoutingSender::asyncAbort(const am_Handle_s& handle) @@ -479,6 +493,30 @@ RoutingSender::am_handleData_c RoutingSender::returnHandleData(const am_Handle_s return (it->second); } +void am::RoutingSender::setRoutingReady() +{ + mRoutingReceiver->waitOnStartup(false); + std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); + std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingReady(mRoutingReceiver->getStartupHandle()); + } + mRoutingReceiver->waitOnStartup(true); +} + +void am::RoutingSender::setRoutingRundown() +{ + mRoutingReceiver->waitOnRundown(false); + std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); + std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end(); + for (; iter < iterEnd; ++iter) + { + (*iter).routingInterface->setRoutingRundown(mRoutingReceiver->getStartupHandle()); + } + mRoutingReceiver->waitOnRundown(true); +} + void RoutingSender::unloadLibraries(void) { std::vector<void*>::iterator iterator = mListLibraryHandles.begin(); @@ -489,7 +527,7 @@ void RoutingSender::unloadLibraries(void) mListLibraryHandles.clear(); } -am_Error_e am::RoutingSender::getListPlugins(std::vector<std::string>& interfaces) const +am_Error_e RoutingSender::getListPlugins(std::vector<std::string>& interfaces) const { std::vector<InterfaceNamePairs>::const_iterator it = mListInterfaces.begin(); for (; it != mListInterfaces.end(); ++it) @@ -499,8 +537,8 @@ am_Error_e am::RoutingSender::getListPlugins(std::vector<std::string>& interface return E_OK; } -uint16_t RoutingSender::getInterfaceVersion() const +void RoutingSender::getInterfaceVersion(std::string & version) const { - return (RoutingSendVersion); + version = RoutingSendVersion; } diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index b4f0e99..dee5edb 100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -277,7 +277,7 @@ int main(int argc, char *argv[]) TelnetServer iTelnetServer(&iSocketHandler, &iCommandSender, &iCommandReceiver, &iRoutingSender, &iRoutingReceiver, &iControlSender, &iControlReceiver, &iDatabaseHandler, &iRouter, telnetport, maxConnections); DatabaseObserver iObserver(&iCommandSender, &iRoutingSender, &iSocketHandler, &iTelnetServer); #else /*WITH_TELNET*/ - DatabaseObserver iObserver(&iCommandSender, &iSocketHandler, &iRoutingSender); + DatabaseObserver iObserver(&iCommandSender,&iRoutingSender, &iSocketHandler); #endif #else /*WITH_DBUS_WRAPPER*/ CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler); @@ -295,11 +295,11 @@ int main(int argc, char *argv[]) //startup all the Plugins and Interfaces iControlSender.startupController(&iControlReceiver); - iCommandSender.startupInterface(&iCommandReceiver); - iRoutingSender.startupRoutingInterface(&iRoutingReceiver); + iCommandSender.startupInterfaces(&iCommandReceiver); + iRoutingSender.startupInterfaces(&iRoutingReceiver); //when the routingInterface is done, all plugins are loaded: - iControlSender.hookAllPluginsLoaded(); + iControlSender.setControllerReady(); //start the mainloop here.... iSocketHandler.start_listenting(); |