16 #ifndef ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEAKERMANAGER_INCLUDE_SPEAKERMANAGER_SPEAKERMANAGER_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEAKERMANAGER_INCLUDE_SPEAKERMANAGER_SPEAKERMANAGER_H_
22 #include <unordered_set>
49 namespace capabilityAgents {
50 namespace speakerManager {
93 const std::shared_ptr<avsCommon::sdkInterfaces::storage::MiscStorageInterface>& storage,
94 const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface>& contextManager,
95 const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
96 const std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>&
97 exceptionEncounteredSender,
98 const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
102 const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder);
116 static std::shared_ptr<SpeakerManager>
create(
117 const std::shared_ptr<SpeakerManagerStorageInterface>& storage,
118 const std::vector<std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>>& volumeInterfaces,
119 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
120 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
121 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
122 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder =
nullptr);
128 void preHandleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
129 void handleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
130 void cancelDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
155 bool forceNoNotifications =
false,
161 bool forceNoNotifications =
false,
167 bool forceNoNotifications =
false,
171 #ifdef ENABLE_MAXVOLUME_SETTING
172 std::future<bool> setMaximumVolumeLimit(
const int8_t maximumVolumeLimit)
override;
178 std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerObserverInterface> observer)
override;
180 std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerObserverInterface> observer)
override;
182 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> channelVolumeInterface)
override;
203 const std::shared_ptr<SpeakerManagerStorageInterface>& speakerManagerStorage,
204 const std::vector<std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>>& groupVolumeInterfaces,
205 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
206 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
207 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
208 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder);
211 struct ChannelVolumeInterfaceHash {
213 size_t operator()(
const std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>&
key)
const {
214 if (
nullptr ==
key) {
224 struct ChannelVolumeInterfaceEqualTo {
227 const std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> channelVolumeInterface1,
228 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> channelVolumeInterface2)
const {
229 if (!channelVolumeInterface1 || !channelVolumeInterface2) {
234 return channelVolumeInterface1->getId() == channelVolumeInterface2->getId();
239 using SpeakerSet = std::unordered_set<
240 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>,
241 ChannelVolumeInterfaceHash,
242 ChannelVolumeInterfaceEqualTo>;
251 void addChannelVolumeInterfaceIntoSpeakerMap(
252 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> channelVolumeInterface);
261 bool parseDirectivePayload(std::string payload, rapidjson::Document* document);
268 void executeSetHandlingCompleted(std::shared_ptr<DirectiveInfo> info);
275 void removeDirective(std::shared_ptr<DirectiveInfo> info);
284 void sendExceptionEncountered(
285 std::shared_ptr<CapabilityAgent::DirectiveInfo> info,
286 const std::string& message,
296 bool updateContextManager(
306 void executeSendSpeakerSettingsChangedEvent(
307 const std::string& eventName,
319 bool executeSetVolume(
332 bool executeRestoreVolume(
345 bool executeAdjustVolume(
364 #ifdef ENABLE_MAXVOLUME_SETTING
371 bool executeSetMaximumVolumeLimit(
const int8_t maximumVolumeLimit);
372 #endif // ENABLE_MAXVOLUME_SETTING
382 bool executeGetSpeakerSettings(
394 bool executeSetSpeakerSettings(
415 void executeNotifySettingsChanged(
417 const std::string& eventName,
428 void executeNotifyObserver(
436 void executePersistConfiguration();
444 void convertSettingsToChannelState(
453 int8_t getMaximumVolumeLimit();
464 template <
typename Task,
typename... Args>
465 bool retryAndApplySettings(Task task, Args&&...
args);
474 void presetChannelDefaults(
481 void loadConfiguration();
486 void updateChannelSettings();
500 int8_t adjustVolumeRange(int64_t volume);
506 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
509 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
512 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
515 int m_minUnmuteVolume;
527 std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerObserverInterface>> m_observers;
530 std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
539 const std::size_t m_maxRetries;
542 int8_t m_maximumVolumeLimit;
545 bool m_restoreMuteState;
561 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEAKERMANAGER_INCLUDE_SPEAKERMANAGER_SPEAKERMANAGER_H_