• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief The framework interface and callback function of pbap server are defined.
21  *
22  * @since 6
23  */
24 
25 /**
26  * @file bluetooth_pbap_server.h
27  *
28  * @brief pbap server interface.
29  *
30  * @since 6
31  */
32 
33 #ifndef BLUETOOTH_PBAP_SERVER_H
34 #define BLUETOOTH_PBAP_SERVER_H
35 
36 #include <memory>
37 #include <string>
38 #include <vector>
39 #include "bluetooth_remote_device.h"
40 #include "bluetooth_types.h"
41 #include "bluetooth_def.h"
42 
43 namespace OHOS {
44 namespace Bluetooth {
45 /**
46  * @brief obsever for pbap server
47  * when pbap server occur event, call these
48  */
49 class PbapObserver {
50 public:
51     /**
52      * @brief deconstructor
53      * @details deconstructor
54      * @return
55      * @since 6
56      */
57     virtual ~PbapObserver() = default;
58     /**
59      * @brief  ConnectionState Changed
60      *
61      * @param  device     bluetooth address
62      * @param  state      changed status
63      * @since 6
64      */
OnServiceConnectionStateChanged(const BluetoothRemoteDevice & device,int state)65     virtual void OnServiceConnectionStateChanged(const BluetoothRemoteDevice &device, int state)
66     {}
67     /**
68      * @brief connect permission event call back
69      * @details when connect permission require call it
70      * @param device remote device
71      * @return void
72      * @since 6
73      */
OnServicePermission(const BluetoothRemoteDevice & device)74     virtual void OnServicePermission(const BluetoothRemoteDevice &device)
75     {}
76     /**
77      * @brief connect password input call back
78      * @details when connect password input call  it
79      * @param device remote device
80      * @param description description bytes
81      * @param charset description bytes's chartset
82      * @param fullAccess fullAccess
83      * @since 6
84      */
85     virtual void OnServicePasswordRequired(const BluetoothRemoteDevice &device,
86         const std::vector<uint8_t> &description, uint8_t charset, bool fullAccess = true)
87     {}
88 };
89 
90 /**
91  * @brief pbap server
92  * pbap server
93  */
94 class BLUETOOTH_API PbapServer {
95 public:
96     /**
97      * @brief get PbapServer
98      * @details get PbapServer instance
99      * @return PbapServer instance
100      * @since 6
101      */
102     static PbapServer *GetProfile();
103 
104     /**
105      * @brief regist observer
106      * @details regist observer for the service of phone book server
107      * @param observer the pointer that point to a PbapObserver
108      * @return void
109      * @since 6
110      */
111     void RegisterObserver(PbapObserver *observer);
112 
113     /**
114      * @brief remove observer
115      * @details remove observer for the service of phone book server
116      * @param observer the pointer that point to a PbapObserver
117      * @return void
118      * @since 6
119      */
120     void DeregisterObserver(PbapObserver *observer);
121 
122     /**
123      * @brief get the remote devices
124      * @details get the remote device with the specified states
125      * @param states states
126      * @return std::vector remote devices
127      * @since 6
128      */
129     std::vector<BluetoothRemoteDevice> GetDevicesByStates(const std::vector<int> &states);
130 
131     /**
132      * @brief get connected devices
133      * @details get the remote device with the connected states
134      * @param states states
135      * @return std::vector remote devices
136      * @since 6
137      */
138     std::vector<BluetoothRemoteDevice> GetConnectedDevices();
139 
140     /**
141      * @brief get the state of device
142      * @details get the state with the specified remote device
143      * @param device  remote device
144      * @return int @c not -1 state of the specified remote device
145      *             @c -1 device is not exist
146      * @since 6
147      */
148     int GetDeviceState(const BluetoothRemoteDevice &device);
149 
150     /**
151      * @brief disconnect device
152      * @details disconnect from remote device
153      * @param device  remote device
154      * @return Returns true if the operation is successful;returns false if the operation fails.
155      * @since 6
156      */
157     bool Disconnect(const BluetoothRemoteDevice &device);
158     /**
159      * @brief Set the connection policy of the specified device.
160      *
161      * @param device Reference to the remote bluetooth device.
162      * @param strategy Reference to the connection policy,
163      *     @c 0 : the connection policy for unkown state.
164      *     @c 1 : the connection policy for allowed state.
165      *     @c 2 : the connection policy for forbidden state.
166      * @return Returns true if the operation is successful;returns false if the operation fails.
167      * @since 6
168      */
169     bool SetConnectionStrategy(const BluetoothRemoteDevice &device, int strategy);
170 
171     /**
172      * @brief Get the connection policy of the specified device.
173      *
174      * @param device Reference to the remote bluetooth device.
175      * @return Returns the connection police of the specified bluetooth address.
176      * @since 6
177      */
178     int GetConnectionStrategy(const BluetoothRemoteDevice &device) const;
179     /**
180      * @brief Set whether to authorize the connection.
181      *
182      * @param device Reference to the remote bluetooth device.
183      * @param allow Reference to grant authorization.
184      *     @c true : accept connection.
185      *     @c false : reject connection.
186      * @param save Always accept/reject connection from this device.
187      * @since 6
188      */
189     void GrantPermission(const BluetoothRemoteDevice &device, bool allow, bool save = false);
190     /**
191      * @brief Set device's password. please call after OnServicePasswordRequired event.
192      *
193      * @param device device
194      * @param password device's password
195      * @param userId device's userId
196      * @return int @c 0 ok
197      *             @c -1 fail
198      * @since 6
199      */
200     int SetDevicePassword(const BluetoothRemoteDevice &device, const std::string &password, std::string userId = "");
201 
202 private:
203     /**
204      * @brief constructor
205      * @details constructor
206      */
207     PbapServer();
208 
209     /**
210      * @brief deconstructor
211      * @details deconstructor
212      */
213     ~PbapServer();
214 
215     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(PbapServer);
216     BLUETOOTH_DECLARE_IMPL();
217 };
218 }  // namespace Bluetooth
219 }  // namespace OHOS
220 #endif  // BLUETOOTH_PBAP_SERVER_H
221