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 Register Hid Host observer instance. 113 * 114 * @param observer Hid Host observer instance. 115 */ 116 void RegisterObserver(HidHostObserver *observer); 117 118 /** 119 * @brief Deregister Hid Host observer instance. 120 * 121 * @param observer Hid Host observer instance. 122 */ 123 void DeregisterObserver(HidHostObserver *observer); 124 125 /** 126 * @brief Hid Host VCUnplug. 127 * 128 * @param observer Hid Host device id size type. 129 */ 130 void HidHostVCUnplug(std::string device, uint8_t id, uint16_t size, uint8_t type); 131 132 /** 133 * @brief Hid Host Send Data. 134 * 135 * @param observer Hid Host device id size type. 136 */ 137 void HidHostSendData(std::string device, uint8_t id, uint16_t size, uint8_t type); 138 139 /** 140 * @brief Hid Host Set Report. 141 * 142 * @param observer Hid Host device type size report. 143 */ 144 void HidHostSetReport(std::string device, uint8_t type, uint16_t size, uint8_t report); 145 146 /** 147 * @brief Hid Host Get Report. 148 * 149 * @param observer Hid Host device id size type. 150 */ 151 void HidHostGetReport(std::string device, uint8_t id, uint16_t size, uint8_t type); 152 153 /** 154 * @brief Static Hid Host observer instance. 155 * 156 */ 157 static HidHostObserver *instance_; 158 159 private: 160 HidHost(); 161 ~HidHost(); 162 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HidHost); 163 BLUETOOTH_DECLARE_IMPL(); 164 }; 165 } // namespace Bluetooth 166 } // namespace OHOS 167 #endif // BLUETOOTH_HID_HOST_H