1 /* 2 * Copyright (C) 2021-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 #ifndef POWER_MANAGER_H 17 #define POWER_MANAGER_H 18 19 #include "bt_def.h" 20 #include "dispatcher.h" 21 #include "raw_address.h" 22 23 namespace OHOS { 24 namespace bluetooth { 25 /** 26 * @brief request status 27 * use to 28 * StatusUpdate(). 29 */ 30 enum class RequestStatus : int { CONNECT_ON, CONNECT_OFF, SCO_ON, SCO_OFF, BUSY, IDLE }; 31 32 /** 33 * @brief power mode 34 * use to 35 * GetPowerMode(). 36 */ 37 enum class BTPowerMode : int { 38 MODE_INVALID = 0x00, 39 MODE_ACTIVE = 0x100, 40 MODE_SNIFF_LEVEL_LOW = 0x201, 41 MODE_SNIFF_LEVEL_MID = 0x202, 42 MODE_SNIFF_LEVEL_HIG = 0x203, 43 }; 44 45 /** 46 * @brief Represents power manager interface. 47 * 48 * @since 6 49 */ 50 class IPowerManager { 51 public: 52 virtual ~IPowerManager() = default; 53 54 /** 55 * @brief Get power manager singleton interface reference. 56 * 57 * @return Returns the singleton interface reference. 58 * @since 6 59 */ 60 static IPowerManager &GetInstance(); 61 62 /** 63 * @brief initialize power manager. 64 * 65 * @param dispatcher dispatcher. 66 * @since 6 67 */ 68 static void Initialize(utility::Dispatcher &dispatcher); 69 70 /** 71 * @brief Uninitialize power manager. 72 * 73 * @since 6 74 */ 75 static void Uninitialize(); 76 77 /** 78 * @brief enable power manager. 79 * 80 * @param dispatcher dispatcher. 81 * @since 6 82 */ 83 virtual void Enable() = 0; 84 85 /** 86 * @brief disable power manager. 87 * 88 * @since 6 89 */ 90 virtual void Disable() = 0; 91 92 /** 93 * @brief Update profile connect status. 94 * 95 * @param status Profile Status. 96 * @param profileName Profile Name. 97 * @param addr Peer Address. 98 * @since 6 99 */ 100 virtual void StatusUpdate( 101 const RequestStatus status, const std::string &profileName, const RawAddress &addr) const = 0; 102 103 /** 104 * @brief Get power mode. 105 * 106 * @param address Device address. 107 * @return Returns power mode grade. 108 * BTPowerMode::MODE_INVALID = 0x00, 109 * BTPowerMode::MODE_ACTIVE = 0x100, 110 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 111 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 112 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 113 * @since 6 114 */ 115 virtual BTPowerMode GetPowerMode(const RawAddress &addr) const = 0; 116 }; 117 118 /** 119 * @brief Represents power manager. 120 * 121 * @since 6 122 */ 123 class PowerManager : public IPowerManager { 124 public: 125 /** 126 * @brief Construct PowerManager object. 127 * 128 * @since 6 129 */ 130 explicit PowerManager(utility::Dispatcher &dispatcher); 131 132 /** 133 * @brief Destruct PowerManager object. 134 * 135 * @since 6 136 */ 137 ~PowerManager(); 138 139 /** 140 * @brief Get power manager singleton object reference. 141 * 142 * @return Returns the singleton object reference. 143 * @since 6 144 */ 145 static PowerManager &GetInstance(); 146 147 /** 148 * @brief initialize power manager. 149 * 150 * @param dispatcher dispatcher. 151 * @since 6 152 */ 153 static void Initialize(utility::Dispatcher &dispatcher); 154 155 /** 156 * @brief Uninitialize power manager. 157 * 158 * @since 6 159 */ 160 static void Uninitialize(); 161 162 /** 163 * @brief enable power manager. 164 * 165 * @param dispatcher dispatcher. 166 * @since 6 167 */ 168 void Enable() override; 169 170 /** 171 * @brief disable power manager. 172 * 173 * @since 6 174 */ 175 void Disable() override; 176 177 /** 178 * @brief Update profile connect status. 179 * 180 * @param status Profile Status. 181 * @param profileName Profile Name. 182 * @param addr Peer Address. 183 * @since 6 184 */ 185 void StatusUpdate(RequestStatus status, const std::string &profileName, const RawAddress &addr) const override; 186 187 /** 188 * @brief Get power mode. 189 * 190 * @param address Device address. 191 * @return Returns power mode grade. 192 * BTPowerMode::MODE_INVALID = 0x00, 193 * BTPowerMode::MODE_ACTIVE = 0x100, 194 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 195 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 196 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 197 * @since 6 198 */ 199 BTPowerMode GetPowerMode(const RawAddress &addr) const override; 200 201 private: 202 BT_DISALLOW_COPY_AND_ASSIGN(PowerManager); 203 DECLARE_IMPL(); 204 }; 205 } // namespace bluetooth 206 } // namespace OHOS 207 208 #endif // POWER_MANAGER_H