1 /* 2 * Copyright (c) 2023 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 STATIONARY_MANAGER_H 17 #define STATIONARY_MANAGER_H 18 19 #include <functional> 20 #include <memory> 21 22 #include "nocopyable.h" 23 24 #include "devicestatus_common.h" 25 #include "stationary_callback.h" 26 #include "stationary_data.h" 27 28 namespace OHOS { 29 namespace Msdp { 30 namespace DeviceStatus { 31 class StationaryManager { 32 public: 33 34 /** 35 * @brief Obtains a <b>StationaryManager</b> instance. 36 * @return Returns a <b>StationaryManager</b> instance. 37 * @since 9 38 */ 39 static StationaryManager *GetInstance(); 40 41 /** 42 * @brief Subscribes to device status changes. 43 * @param type Indicates the device status type. 44 * @param event Indicates the event type, which can be <b>ENTER</b>, <b>EXIT</b>, and <b>ENTER_EXIT</b>. 45 * @param latency Indicates the reporting interval. 46 * @param callback Indicates the callback used to return the device status changes. 47 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 48 * @since 9 49 */ 50 int32_t SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency, 51 sptr<IRemoteDevStaCallback> callback); 52 53 /** 54 * @brief Unsubscribes from device status changes. 55 * @param type Indicates the device status type. 56 * @param event Indicates the event type, which can be <b>ENTER</b>, <b>EXIT</b>, and <b>ENTER_EXIT</b>. 57 * @param callback Indicates the callback used to return the device status changes. 58 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 59 * @since 9 60 */ 61 int32_t UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback); 62 63 /** 64 * @brief Obtains the device status data. 65 * @param type Indicates the device status type. 66 * @return Returns the device status data. 67 * @since 9 68 */ 69 Data GetDeviceStatusData(const Type type); 70 private: 71 StationaryManager() = default; 72 DISALLOW_COPY_AND_MOVE(StationaryManager); 73 static StationaryManager *instance_; 74 }; 75 } // namespace DeviceStatus 76 } // namespace Msdp 77 } // namespace OHOS 78 #endif // STATIONARY_MANAGER_H