• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_hid_host.h
27  *
28  * @brief Declares HID HOST role framework functions, including basic and observer functions.
29  *
30  */
31 #ifndef BLUETOOTH_HID_HOST_H
32 #define BLUETOOTH_HID_HOST_H
33 
34 #include <string>
35 #include <vector>
36 #include <memory>
37 
38 #include "bluetooth_def.h"
39 #include "bluetooth_types.h"
40 #include "bluetooth_remote_device.h"
41 namespace OHOS {
42 namespace Bluetooth {
43 /**
44  * @brief Class for Hid Host observer functions.
45  *
46  */
47 class HidHostObserver {
48 public:
49     /**
50      * @brief The observer function to notify connection state changed.
51      *
52      * @param device Remote device object.
53      * @param state Connection state.
54      */
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state)55     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state)
56     {}
57 
58     /**
59      * @brief Destroy the HidHostObserver object.
60      *
61      */
~HidHostObserver()62     virtual ~HidHostObserver()
63     {}
64 };
65 
66 /**
67  * @brief Class for Hid Host API.
68  *
69  */
70 class BLUETOOTH_API HidHost {
71 public:
72     /**
73      * @brief Get the instance of HidHost object.
74      *
75      * @return Returns the pointer to the HidHost instance.
76      */
77     static HidHost *GetProfile();
78 
79     /**
80      * @brief Get remote Hid device list which are in the specified states.
81      *
82      * @param states List of remote device states.
83      * @return Returns the list of devices.
84      */
85     int32_t GetDevicesByStates(std::vector<int> states, std::vector<BluetoothRemoteDevice> &result);
86 
87     /**
88      * @brief Get the connection state of the specified remote Hid device.
89      *
90      * @param device Remote device object.
91      * @return Returns the connection state of the remote device.
92      */
93     int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state);
94 
95     /**
96      * @brief Initiate the establishment of a service level connection to remote Hid device.
97      *
98      * @param device Remote device object.
99      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
100      */
101     int32_t Connect(const BluetoothRemoteDevice &device);
102 
103     /**
104      * @brief Release the connection from remote Hid device.
105      *
106      * @param device Remote device object.
107      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
108      */
109     int32_t Disconnect(const BluetoothRemoteDevice &device);
110 
111     /**
112      * @brief Set connection strategy for peer bluetooth device.
113      *        If peer device is connected and the policy is set not allowed,then perform disconnect operation.
114      *        If peer device is disconnected and the policy is set allowed,then perform connect operation.
115      *
116      * @param device The address of the peer bluetooth device.
117      * @param strategy The device connect strategy.
118      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
119      *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
120      *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
121      *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
122      *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
123      * @since 10.0
124      */
125     int SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy);
126 
127     /**
128      * @brief Get connection strategy of peer bluetooth device.
129      *
130      * @param device The address of the peer bluetooth device.
131      * @param strategy The device connect strategy.
132      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
133      *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
134      *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
135      *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
136      *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
137      * @since 10.0
138      */
139     int GetConnectStrategy(const BluetoothRemoteDevice &device, int &strategy) const;
140 
141         /**
142      * @brief Register Hid Host observer instance.
143      *
144      * @param observer Hid Host observer instance.
145      */
146     void RegisterObserver(HidHostObserver *observer);
147 
148     /**
149      * @brief Deregister Hid Host observer instance.
150      *
151      * @param observer Hid Host observer instance.
152      */
153     void DeregisterObserver(HidHostObserver *observer);
154 
155     /**
156      * @brief Hid Host VCUnplug.
157      *
158      * @param observer Hid Host device id size type.
159      */
160     void HidHostVCUnplug(std::string device, uint8_t id, uint16_t size, uint8_t type);
161 
162     /**
163      * @brief Hid Host Send Data.
164      *
165      * @param observer Hid Host device id size type.
166      */
167     void HidHostSendData(std::string device, uint8_t id, uint16_t size, uint8_t type);
168 
169     /**
170      * @brief Hid Host Set Report.
171      *
172      * @param observer Hid Host device type size report.
173      */
174     void HidHostSetReport(std::string device, uint8_t type, uint16_t size, uint8_t report);
175 
176     /**
177      * @brief Hid Host Get Report.
178      *
179      * @param observer Hid Host device id size type.
180      */
181     void HidHostGetReport(std::string device, uint8_t id, uint16_t size, uint8_t type);
182 
183     /**
184      * @brief The external process calls the HidHost profile interface before the Bluetooth process starts. At this
185      * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the
186      * HidHost proflie.
187      */
188     void Init();
189 
190     /**
191      * @brief Static Hid Host observer instance.
192      *
193      */
194     static HidHostObserver *instance_;
195 
196 private:
197     HidHost();
198     ~HidHost();
199     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HidHost);
200     BLUETOOTH_DECLARE_IMPL();
201 };
202 }  // namespace Bluetooth
203 }  // namespace OHOS
204 #endif  // BLUETOOTH_HID_HOST_H