1 /*
2  * Copyright (C) 2022 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 Defines a bluetooth system that provides basic bluetooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  */
24 
25 /**
26  * @file bluetooth_pan.h
27  *
28  * @brief Declares PAN role framework functions, including basic and observer functions.
29  *
30  */
31 #ifndef BLUETOOTH_PAN_H
32 #define BLUETOOTH_PAN_H
33 
34 #include <string>
35 #include <vector>
36 #include <memory>
37 
38 #include "bluetooth_def.h"
39 #include "bluetooth_remote_device.h"
40 #include "bluetooth_types.h"
41 #include "bluetooth_no_destructor.h"
42 namespace OHOS {
43 namespace Bluetooth {
44 /**
45  * @brief Class for pan observer functions.
46  *
47  */
48 class PanObserver {
49 public:
50     /**
51      * @brief The observer function to notify connection state changed.
52      *
53      * @param device Remote device object.
54      * @param state Connection state.
55      * @param cause Connection cause.
56      */
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state,int cause)57     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state, int cause)
58     {}
59 
60     /**
61      * @brief Destroy the PanObserver object.
62      *
63      */
~PanObserver()64     virtual ~PanObserver()
65     {}
66 };
67 
68 /**
69  * @brief Class for Pan API.
70  *
71  */
72 class BLUETOOTH_API Pan {
73 public:
74     /**
75      * @brief Get the instance of Pan object.
76      *
77      * @return Returns the pointer to the Pan instance.
78      */
79     static Pan *GetProfile();
80 
81     /**
82      * @brief Get remote Pan device list which are in the specified states.
83      *
84      * @param states List of remote device states.
85      * @return Returns the list of devices.
86      */
87     int32_t GetDevicesByStates(std::vector<int> states, std::vector<BluetoothRemoteDevice> &result);
88 
89     /**
90      * @brief Get the connection state of the specified remote Pan device.
91      *
92      * @param device Remote device object.
93      * @return Returns the connection state of the remote device.
94      */
95     int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state);
96 
97     /**
98      * @brief Release the connection from remote Pan device.
99      *
100      * @param device Remote device object.
101      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
102      */
103     int32_t Disconnect(const BluetoothRemoteDevice &device);
104 
105         /**
106      * @brief Register Pan observer instance.
107      *
108      * @param observer Pan observer instance.
109      */
110     void RegisterObserver(std::shared_ptr<PanObserver> observer);
111 
112     /**
113      * @brief Deregister Pan observer instance.
114      *
115      * @param observer Pan observer instance.
116      */
117     void DeregisterObserver(std::shared_ptr<PanObserver> observer);
118 
119     /**
120      * @brief Set Tethering
121      *
122      * @param value Set Network Sharing.
123      */
124     int32_t SetTethering(bool value);
125 
126     /**
127      * @brief Is Tethering On.
128      *
129      */
130     int32_t IsTetheringOn(bool &value);
131 
132     /**
133      * @brief The external process calls the Pan profile interface before the Bluetooth process starts. At this
134      * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the
135      * Pan proflie.
136      */
137     void Init();
138 
139     /**
140      * @brief Static Pan observer instance.
141      *
142      */
143     static PanObserver *instance_;
144 
145 private:
146     Pan();
147     ~Pan();
148     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(Pan);
149     BLUETOOTH_DECLARE_IMPL();
150 
151 #ifdef DTFUZZ_TEST
152     friend class BluetoothNoDestructor<Pan>;
153 #endif
154 };
155 }  // namespace Bluetooth
156 }  // namespace OHOS
157 #endif  // BLUETOOTH_PAN_H