1/*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef BLUETOOTH_PBAP_PSE_H
17#define BLUETOOTH_PBAP_PSE_H
18
19#include <memory>
20#include <string>
21#include <vector>
22#include "bluetooth_def.h"
23#include "bluetooth_remote_device.h"
24#include "bluetooth_types.h"
25#include "bluetooth_no_destructor.h"
26
27namespace OHOS {
28namespace Bluetooth {
29/**
30 * @brief Class for Pbap PSE observer functions.
31 *
32 */
33class PbapPseObserver {
34public:
35    /**
36     * @brief Destroy the PbapPseObserver object.
37     *
38     */
39    virtual ~PbapPseObserver() = default;
40
41    /**
42     * @brief The observer function to notify connection state changed.
43     *
44     * @param device Remote device object.
45     * @param state Connection state.
46     * @param cause Connection cause.
47     */
48    virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int32_t state, int32_t cause)
49    {}
50};
51
52/**
53 * @brief Class for Pbap Server API.
54 *
55 */
56class BLUETOOTH_API PbapPse {
57public:
58    /**
59     * @brief Get the instance of PbapPse object.
60     *
61     * @return Returns the pointer to the PbapPse instance.
62     */
63    static PbapPse *GetProfile();
64
65    /**
66     * @brief Register PbapPse observer instance.
67     *
68     * @param observer PbapPse observer instance.
69     */
70    void RegisterObserver(std::shared_ptr<PbapPseObserver> observer);
71
72    /**
73     * @brief Deregister PbapPse observer instance.
74     *
75     * @param observer PbapPse observer instance.
76     */
77    void DeregisterObserver(std::shared_ptr<PbapPseObserver> observer);
78
79    /**
80     * @brief Get remote pbap pse device list which are in the specified states.
81     *
82     * @param states List of remote device states.
83     * @param result the list of devices
84     * @return Returns operate result.
85     */
86    int32_t GetDevicesByStates(const std::vector<int32_t> &states, std::vector<BluetoothRemoteDevice> &result) const;
87
88    /**
89     * @brief Get the connection state of the specified remote pbap device.
90     *
91     * @param device Remote device object.
92     * @param state the connection state of the remote device
93     * @return Returns operate result.
94     */
95    int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state) const;
96
97    /**
98     * @brief Release the connection from remote pbap device.
99     *
100     * @param device Remote device object.
101     * @return Returns operate result.
102     */
103    int32_t Disconnect(const BluetoothRemoteDevice &device);
104
105    /**
106     * @brief Set connection strategy for remote bluetooth device.
107     *
108     * @param device Remote device object.
109     * @param strategy The device connect strategy.
110     * @return Returns operate result
111     */
112    int32_t SetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t strategy);
113
114    /**
115     * @brief Get connection strategy of remote bluetooth device.
116     *
117     * @param device The address of the peer bluetooth device.
118     * @param strategy The device connect strategy.
119     * @return Returns operate result.
120     */
121    int32_t GetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t &strategy) const;
122
123    /**
124     * @brief Set share type for remote bluetooth device.
125     *
126     * @param device Remote device object.
127     * @param shareType The share type.
128     * @return Returns operate result
129     */
130    int32_t SetShareType(const BluetoothRemoteDevice &device, int32_t shareType);
131
132    /**
133     * @brief Get share type of remote bluetooth device.
134     *
135     * @param device The address of the peer bluetooth device.
136     * @param shareType The share type.
137     * @return Returns operate result.
138     */
139    int32_t GetShareType(const BluetoothRemoteDevice &device, int32_t &shareType) const;
140
141    /**
142     * @brief Set accessAuthorization for remote bluetooth device.
143     *
144     * @param device Remote device object.
145     * @param accessAuthorization The accessAuthorization.
146     * @return Returns operate result
147     */
148    int32_t SetPhoneBookAccessAuthorization(const BluetoothRemoteDevice &device, int32_t accessAuthorization);
149
150    /**
151     * @brief Get accessAuthorization of remote bluetooth device.
152     *
153     * @param device The address of the peer bluetooth device.
154     * @param accessAuthorization The accessAuthorization.
155     * @return Returns operate result.
156     */
157    int32_t GetPhoneBookAccessAuthorization(const BluetoothRemoteDevice &device, int32_t &accessAuthorization) const;
158
159    void Init();
160    void Uinit();
161
162private:
163    /**
164     * @brief constructor.
165     *
166     */
167    PbapPse();
168
169    /**
170     * @brief deconstructor.
171     *
172     */
173    ~PbapPse();
174
175    BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(PbapPse);
176    BLUETOOTH_DECLARE_IMPL();
177
178#ifdef DTFUZZ_TEST
179    friend class BluetoothNoDestructor<PbapPse>;
180#endif
181};
182}  // namespace Bluetooth
183}  // namespace OHOS
184#endif  // BLUETOOTH_PBAP_PSE_H