16 #ifndef ACSDKBLUETOOTH_BLUETOOTH_H_ 17 #define ACSDKBLUETOOTH_BLUETOOTH_H_ 26 #include <unordered_set> 72 namespace acsdkBluetooth {
120 :
public std::enable_shared_from_this<Bluetooth>
230 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
231 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
232 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
233 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothStorageInterface> bluetoothStorage,
234 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceManagerInterface> deviceManager,
235 std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> eventBus,
236 std::shared_ptr<registrationManager::CustomerDataManagerInterface> customerDataManager,
237 std::shared_ptr<acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface>
238 audioPipelineFactory,
242 std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface> shutdownNotifier,
246 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothDeviceConnectionRulesProviderInterface>
247 connectionRulesProvider,
248 std::shared_ptr<BluetoothMediaInputTransformer> mediaInputTransformer,
249 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothNotifierInterface> bluetoothNotifier);
255 void preHandleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
256 void handleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
257 void cancelDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info)
override;
341 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
342 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
343 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
344 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
345 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothStorageInterface> bluetoothStorage,
346 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceManagerInterface> deviceManager,
347 std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> eventBus,
348 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer,
349 std::shared_ptr<registrationManager::CustomerDataManagerInterface> customerDataManager,
350 std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceConnectionRuleInterface>>
351 enabledConnectionRules,
352 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> bluetoothChannelVolumeInterface,
353 std::shared_ptr<BluetoothMediaInputTransformer> mediaInputTransformer,
354 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothNotifierInterface> bluetoothNotifier);
367 void syncWithDeviceManager();
371 void executeUpdateContext();
382 bool extractAvsProfiles(
383 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
384 rapidjson::Document::AllocatorType& allocator,
392 void executeSetHandlingCompleted(std::shared_ptr<DirectiveInfo> info);
399 void removeDirective(std::shared_ptr<DirectiveInfo> info);
408 void sendExceptionEncountered(
409 std::shared_ptr<CapabilityAgent::DirectiveInfo> info,
414 void executeEnterForeground();
420 void executeEnterNone();
425 void executeHandleEnterDiscoverableMode();
430 void executeHandleExitDiscoverableMode();
435 void executeHandleScanDevices();
443 bool executeHandlePairDevices(
const std::unordered_set<std::string>& uuids);
451 bool executeHandleUnpairDevices(
const std::unordered_set<std::string>& uuids);
460 bool executeHandleConnectByDeviceIds(
const std::unordered_set<std::string>& uuids);
469 bool executeHandleDisconnectDevices(
const std::unordered_set<std::string>& uuids);
477 bool executeSetDiscoverableMode(
bool discoverable);
486 bool executeSetScanMode(
bool scanning,
bool shouldReport =
true);
494 bool executePairDevices(
const std::unordered_set<std::string>& uuids);
502 bool executeUnpairDevices(
const std::unordered_set<std::string>& uuids);
510 std::map<std::string, std::string> executeSetDeviceCategories(
511 const std::map<std::string, std::string>& uuidCategoryMap);
519 void executeConnectByDeviceIds(
const std::unordered_set<std::string>& uuids);
537 void executeDisconnectDevices(
const std::unordered_set<std::string>& uuids);
553 void executeOnDeviceDisconnect(
554 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
563 void executeOnDeviceConnect(
564 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
565 bool shouldNotifyConnection =
true);
573 bool executeFunctionOnDevice(
574 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>& device,
575 std::function<std::future<bool>(
576 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>&)>
function);
583 void executePlay(std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
590 void executeStop(std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
597 void executeNext(std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
604 void executePrevious(std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
607 void executeInitializeMediaSource();
610 void cleanupMediaSource();
613 void executeAbortMediaPlayback();
622 void setCurrentStream(std::shared_ptr<avsCommon::utils::bluetooth::FormattedAudioStreamAdapter> stream);
627 void onFormattedAudioStreamAdapterData(
629 const unsigned char* buffer,
630 size_t size)
override;
640 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> retrieveDeviceByMac(
649 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> retrieveDeviceByUuid(
666 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceConnectionRuleInterface>
667 retrieveConnectionRuleByUuid(
const std::string& uuid);
685 std::unordered_set<std::string> retrieveUuidsFromConnectionPayload(
const rapidjson::Document& payload);
688 void clearUnusedUuids();
713 void executeSendScanDevicesReport(
714 const std::list<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>& devices,
718 void executeSendScanDevicesFailed();
721 void executeSendEnterDiscoverableModeSucceeded();
724 void executeSendEnterDiscoverableModeFailed();
731 void executeSendPairDevicesSucceeded(
732 const std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>&
741 void executeSendPairFailedEvent(
const std::string& eventName,
const std::unordered_set<std::string>& uuids);
748 void executeSendPairDevicesFailed(
const std::unordered_set<std::string>& uuids);
755 void executeSendUnpairDevicesSucceeded(
756 const std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>&
764 void executeSendUnpairDevicesFailed(
const std::unordered_set<std::string>& uuids);
771 void executeSetDeviceCategoriesSucceeded(
const std::map<std::string, std::string>& uuidCategoryMap);
778 void executeSetDeviceCategoriesFailed(
const std::map<std::string, std::string>& uuidCategoryMap);
786 void executeSendConnectByDeviceIdsSucceeded(
787 const std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>&
797 void executeSendConnectByDeviceIdsFailed(
798 const std::unordered_set<std::string>& uuids,
808 void executeSendConnectByProfileSucceeded(
809 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
828 void executeSendDisconnectDevicesSucceeded(
829 const std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>&
840 void executeSendConnectFailedEvent(
842 const std::unordered_set<std::string>& uuids,
851 void executeSendDisconnectDevicesFailed(
852 const std::unordered_set<std::string>& uuids,
861 void executeSendMediaControlEvent(
863 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
870 void executeSendMediaControlPlaySucceeded(
871 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
878 void executeSendMediaControlPlayFailed(
879 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
886 void executeSendMediaControlStopSucceeded(
887 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
894 void executeSendMediaControlStopFailed(
895 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
902 void executeSendMediaControlNextSucceeded(
903 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
910 void executeSendMediaControlNextFailed(
911 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
918 void executeSendMediaControlPreviousSucceeded(
919 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
926 void executeSendMediaControlPreviousFailed(
927 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
935 void executeSendStreamingEvent(
937 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
944 void executeSendStreamingStarted(
945 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
952 void executeSendStreamingEnded(
953 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
959 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
968 template <
typename ServiceType>
969 std::shared_ptr<ServiceType> getService(
970 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device);
980 void executeInsertBluetoothEventState(
981 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
993 std::shared_ptr<BluetoothEventState> executeRemoveBluetoothEventState(
994 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> device,
1000 void executeRestrictA2DPDevices();
1006 void executeUnrestrictA2DPDevices();
1013 void executeAcquireFocus(
const std::string& callingMethodName =
"");
1020 void executeReleaseFocus(
const std::string& callingMethodName =
"");
1023 std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
1026 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
1029 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
1032 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> m_focusManager;
1058 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceManagerInterface> m_deviceManager;
1061 std::queue<std::pair<std::string, std::string>> m_eventQueue;
1064 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> m_activeA2DPDevice;
1067 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface> m_disabledA2DPDevice;
1070 std::vector<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>> m_restrictedDevices;
1073 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> m_mediaPlayer;
1076 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothStorageInterface> m_db;
1079 std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> m_eventBus;
1082 std::shared_ptr<BluetoothMediaInputTransformer> m_mediaInputTransformer;
1085 std::shared_ptr<avsCommon::utils::bluetooth::FormattedAudioStreamAdapter> m_mediaStream;
1088 std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> m_mediaAttachment;
1091 std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter> m_mediaAttachmentWriter;
1094 std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> m_mediaAttachmentReader;
1099 std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceConnectionRuleInterface>>
1100 m_enabledConnectionRules;
1103 std::map<DeviceCategory, std::set<std::shared_ptr<avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceInterface>>>
1107 std::map<std::string, std::unordered_set<std::shared_ptr<BluetoothEventState>>> m_bluetoothEventStates;
1111 std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface> m_bluetoothChannelVolumeInterface;
1114 std::shared_ptr<acsdkBluetoothInterfaces::BluetoothNotifierInterface> m_bluetoothNotifier;
1117 std::atomic<uint8_t> m_pendingFocusTransitions;
1136 return "PENDING_PAUSED";
1138 return "PENDING_ACTIVE";
1170 return "PENDING_INTERNAL";
1201 return "PENDING_ACTIVE";
1224 #endif // ACSDKBLUETOOTH_BLUETOOTH_H_
Definition: AudioFocusAnnotation.h:25
void onPlaybackError(avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::SourceId id, const avsCommon::utils::mediaPlayer::ErrorType &type, std::string error, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CapabilityAgent.h:47
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
MixingBehavior
Definition: MixingBehavior.h:25
Media playback is currently ongoing.
Definition: CapabilityConfigurationInterface.h:32
void handleDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
void cancelDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
void connect(const std::string &addr) override
FocusTransitionState
Definition: Bluetooth.h:155
Definition: Bluetooth.h:119
Focus in Bluetooth class is lost because another class has taken focus.
::std::string string
Definition: gtest-port.h:1097
void disconnect(const std::string &addr) override
ContextRequestError
Definition: ContextRequesterInterface.h:40
Single-thread executor implementation.
Definition: Executor.h:45
Definition: EndpointCapabilitiesRegistrarInterface.h:35
Definition: BluetoothEventListenerInterface.h:29
Definition: BluetoothLocalInterface.h:35
Definition: RequiresShutdown.h:32
ExceptionErrorType
Definition: ExceptionErrorType.h:28
AVRCP Pause is sent, waiting for local playback to stop.
std::string scanningStateToString(Bluetooth::ScanningTransitionState state)
Definition: Bluetooth.h:1196
static const constexpr char * BLUETOOTH_MEDIA_PLAYER_NAME
String to identify the Bluetooth media player to render audio.
Definition: Bluetooth.h:75
FocusState
Definition: FocusState.h:29
Definition: FocusManagerInterface.h:54
void pair(const std::string &addr) override
std::string focusTransitionStateToString(Bluetooth::FocusTransitionState state)
Definition: Bluetooth.h:1163
Definition: BluetoothDeviceObserverInterface.h:28
void setDiscoverableMode(bool discoverable) override
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
void setPairingPin(const std::string &addr, const std::string &pin) override
No focus transition in progress,.
void onFirstByteRead(avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
void setScanMode(bool scanning) override
Definition: DefaultEndpointAnnotation.h:26
std::ostream & operator<<(std::ostream &stream, const Bluetooth::StreamingState state)
Definition: Bluetooth.h:1153
void clearData() override
void unpair(const std::string &addr) override
bool Value(const T &value, M matcher)
Definition: gmock-matchers.h:4347
Focus in Bluetooth class is lost because it explicitly released focus.
Definition: Annotated.h:35
void onContextAvailable(const std::string &jsonContext) override
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
void onPlaybackStopped(avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
DeviceCategory
Definition: DeviceCategory.h:24
AVRCP Play is sent, waiting for local playback to start.
void preHandleDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
void onEventFired(const avsCommon::utils::bluetooth::BluetoothEvent &event) override
Initial state or after a disconnect.
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onFocusChanged(avsCommon::avs::FocusState newFocus, avsCommon::avs::MixingBehavior behavior) override
DeviceState
Definition: BluetoothDeviceInterface.h:48
void onPlaybackStarted(avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
type
Definition: upload.py:443
void onPlaybackFinished(avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
void onContextFailure(const avsCommon::sdkInterfaces::ContextRequestError error) override
std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations() override
ScanningTransitionState
Definition: Bluetooth.h:177
static std::shared_ptr< Bluetooth > createBluetoothCapabilityAgent(std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender, std::shared_ptr< acsdkBluetoothInterfaces::BluetoothStorageInterface > bluetoothStorage, std::shared_ptr< avsCommon::sdkInterfaces::bluetooth::BluetoothDeviceManagerInterface > deviceManager, std::shared_ptr< avsCommon::utils::bluetooth::BluetoothEventBus > eventBus, std::shared_ptr< registrationManager::CustomerDataManagerInterface > customerDataManager, std::shared_ptr< acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface > audioPipelineFactory, acsdkManufactory::Annotated< avsCommon::sdkInterfaces::AudioFocusAnnotation, avsCommon::sdkInterfaces::FocusManagerInterface > audioFocusManager, std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > shutdownNotifier, acsdkManufactory::Annotated< avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > endpointCapabilitiesRegistrar, std::shared_ptr< acsdkBluetoothInterfaces::BluetoothDeviceConnectionRulesProviderInterface > connectionRulesProvider, std::shared_ptr< BluetoothMediaInputTransformer > mediaInputTransformer, std::shared_ptr< acsdkBluetoothInterfaces::BluetoothNotifierInterface > bluetoothNotifier)
void doShutdown() override
StreamingState
Definition: Bluetooth.h:135
Definition: BluetoothDeviceObserverInterface.h:33
Media playback is no longer occurring.
Requester
An enum class indicating whether an operation originated from a Device or Cloud (AVS).
Definition: Requester.h:24
tuple message
Definition: gtest_output_test.py:331
Definition: CustomerDataHandler.h:34
std::string streamingStateToString(Bluetooth::StreamingState state)
Definition: Bluetooth.h:1129
Base class for a BluetoothEvent.
Definition: BluetoothEvents.h:66