1 /* 2 * Copyright (c) 2022-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 DEVICESTATUS_AGENT_H 17 #define DEVICESTATUS_AGENT_H 18 19 #include <memory> 20 21 #include "devicestatus_callback_stub.h" 22 #include "stationary_data.h" 23 24 namespace OHOS { 25 namespace Msdp { 26 namespace DeviceStatus { 27 class DeviceStatusAgent : public std::enable_shared_from_this<DeviceStatusAgent> { 28 public: DeviceStatusAgent()29 DeviceStatusAgent() {}; ~DeviceStatusAgent()30 ~DeviceStatusAgent() {}; 31 32 class DeviceStatusAgentEvent { 33 public: 34 virtual ~DeviceStatusAgentEvent() = default; 35 virtual bool OnEventResult(const Data& devicestatusData) = 0; 36 }; 37 38 class DeviceStatusAgentCallback : public DeviceStatusCallbackStub { 39 public: DeviceStatusAgentCallback(std::shared_ptr<DeviceStatusAgent> agent)40 explicit DeviceStatusAgentCallback(std::shared_ptr<DeviceStatusAgent> agent) : agent_(agent) {}; ~DeviceStatusAgentCallback()41 virtual ~DeviceStatusAgentCallback() {}; 42 void OnDeviceStatusChanged(const Data& devicestatusData) override; 43 44 private: 45 std::weak_ptr<DeviceStatusAgent> agent_; 46 }; 47 48 int32_t SubscribeAgentEvent(Type type, ActivityEvent event, ReportLatencyNs latency, 49 std::shared_ptr<DeviceStatusAgent::DeviceStatusAgentEvent> agentEvent); 50 int32_t UnsubscribeAgentEvent(Type type, ActivityEvent event); 51 friend class DeviceStatusAgentCallback; 52 53 private: 54 void RegisterServiceEvent(Type type, ActivityEvent event, ReportLatencyNs latency); 55 void UnRegisterServiceEvent(Type type, ActivityEvent event); 56 57 sptr<IRemoteDevStaCallback> callback_ { nullptr }; 58 std::shared_ptr<DeviceStatusAgentEvent> agentEvent_ { nullptr }; 59 }; 60 } // namespace DeviceStatus 61 } // namespace Msdp 62 } // namespace OHOS 63 #endif // DEVICESTATUS_AGENT_H 64