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 #ifndef DEVICESTATUS_CLIENT_H 17 #define DEVICESTATUS_CLIENT_H 18 19 #include <singleton.h> 20 21 #include "idevicestatus.h" 22 #include "idevicestatus_callback.h" 23 #include "devicestatus_data_utils.h" 24 #include "devicestatus_common.h" 25 26 namespace OHOS { 27 namespace Msdp { 28 class DevicestatusClient final : public DelayedRefSingleton<DevicestatusClient> { 29 DECLARE_DELAYED_REF_SINGLETON(DevicestatusClient) 30 31 public: 32 DISALLOW_COPY_AND_MOVE(DevicestatusClient); 33 34 void SubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \ 35 const sptr<IdevicestatusCallback>& callback); 36 void UnSubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \ 37 const sptr<IdevicestatusCallback>& callback); 38 DevicestatusDataUtils::DevicestatusData GetDevicestatusData(const DevicestatusDataUtils::DevicestatusType& type); 39 40 private: 41 class DevicestatusDeathRecipient : public IRemoteObject::DeathRecipient { 42 public: 43 DevicestatusDeathRecipient() = default; 44 ~DevicestatusDeathRecipient() = default; 45 void OnRemoteDied(const wptr<IRemoteObject>& remote); 46 private: 47 DISALLOW_COPY_AND_MOVE(DevicestatusDeathRecipient); 48 }; 49 50 ErrCode Connect(); 51 sptr<Idevicestatus> devicestatusProxy_ {nullptr}; 52 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 53 void ResetProxy(const wptr<IRemoteObject>& remote); 54 std::mutex mutex_; 55 }; 56 } // namespace Msdp 57 } // namespace OHOS 58 #endif // IDEVICESTATUS_H 59