/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @addtogroup Bluetooth * @{ * * @brief The framework interface and callback function of a2dp sink are defined. * * @since 6 */ #ifndef BLUETOOTH_A2DP_SNK_H #define BLUETOOTH_A2DP_SNK_H #include #include "bluetooth_types.h" #include "bluetooth_remote_device.h" #include "bluetooth_no_destructor.h" namespace OHOS { namespace Bluetooth { /** * @brief A2dp sink API callback function. * * @since 6.0 */ class A2dpSinkObserver { public: /** * @brief A destructor used to delete the a2dp sink Observer instance. * * @since 6.0 */ virtual ~A2dpSinkObserver() = default; /** * @brief ConnectionState Changed observer * @param device bluetooth device address * @param state Connecton state * @param cause Connecton cause * @since 12 */ virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state, int cause) {}; }; /** * @brief A2dp sink API. * * @since 6.0 */ class BLUETOOTH_API A2dpSink { public: /** * @brief Get a2dp sink instance. * * @return Returns an instance of a2dp sink. * @since 6.0 */ static A2dpSink *GetProfile(); /** * @brief Get devices by connection states. * * @param states The connection states of the bluetooth device. * @return Returns devices that match the connection states. * @since 6.0 */ std::vector GetDevicesByStates(std::vector states) const; /** * @brief Get device connection state by address. * * @param device The address of the peer bluetooth device. * @return Returns A2DP_DISCONNECTED if device connect state is disconnected; * Returns A2DP_DISCONNECTING if device connect state is disconnecting; * Returns A2DP_CONNECTED if device connect state is connected; * Returns A2DP_CONNECTING if device connect state is connecting; * Returns A2DP_INVALID_STATUS if can not find peer device. * @since 6.0 */ int GetDeviceState(const BluetoothRemoteDevice &device) const; /** * @brief Get device playing state by address when peer device is on connected. * * @param device The address of the peer bluetooth device. * @return Returns 1 if device is on playing; * Returns 0 if device is not on playing. * @since 6.0 */ int GetPlayingState(const BluetoothRemoteDevice &device) const; /** * @brief Get device playing state by address when peer device is on connected. * * @param device The address of the peer bluetooth device. * @param state The playing state of the peer bluetooth device. * @return Returns 1 if device is on playing; * Returns 0 if device is not on playing. * @since 6.0 */ int GetPlayingState(const BluetoothRemoteDevice &device, int &state) const; /** * @brief Connect to the peer bluetooth device. * * @param device The address of the peer bluetooth device. * @return Returns true Perform normal connection processing. * Returns false Target device is on connected,or connecting, or device is not allowed to connect,or the connection fails. * @since 6.0 */ bool Connect(const BluetoothRemoteDevice &device); /** * @brief Disconnect with the peer bluetooth service. * * @param device The address of the peer bluetooth device. * @return Returns true if perform normal disconnection processing. * Returns false if target device is on disconnected,or disconnecting,or disconnection fails. * @since 6.0 */ bool Disconnect(const BluetoothRemoteDevice &device); /** * @brief Set connection strategy for peer bluetooth device. * If peer device is connected and the policy is set not allowed,then perform disconnect operation. * If peer device is disconnected and the policy is set allowed,then perform connect operation. * * @param device The address of the peer bluetooth device. * @param strategy The device connect strategy. * @return Returns true if the operation is successful. * Returns false if the operation fails. * @since 6.0 */ bool SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy); /** * @brief Get connection strategy of peer bluetooth device. * * @param device The address of the peer bluetooth device. * @return Returns A2DP_CONNECT_POLICY_AGREE if the peer device is allowed to connect. * Returns A2DP_CONNECT_POLICY_DISAGREE if the peer device is not allowed to connect. * @since 6.0 */ int GetConnectStrategy(const BluetoothRemoteDevice &device) const; /** * @brief Send delay reporting. * * @param device The address of the peer bluetooth device. * @param delayValue The delay value. * @return Returns true Set delay reporting success. * Returns false Set delay reporting failed, */ bool SendDelay(const BluetoothRemoteDevice &device, uint16_t delayValue); /** * @brief Register callback function of framework. * * @param observer Reference to the a2dp sink observer. * @since 6.0 */ void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister callback function of framework. * * @param observer Reference to the a2dp sink observer. * @since 6.0 */ void DeregisterObserver(std::shared_ptr observer); /** * @brief The external process calls the A2dpSink profile interface before the Bluetooth process starts. At this * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the * A2dpSink proflie. */ void Init(); private: /** * @brief A constructor used to create a a2dp sink instance. * * @since 6.0 */ A2dpSink(void); /** * @brief A destructor used to delete the a2dp sink instance. * * @since 6.0 */ ~A2dpSink(void); BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(A2dpSink); BLUETOOTH_DECLARE_IMPL(); #ifdef DTFUZZ_TEST friend class BluetoothNoDestructor; #endif }; } // namespace Bluetooth } // namespace OHOS #endif // BLUETOOTH_A2DP_SNK_H