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