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 OHOS_HDI_CODEC_V3_0_CODECDEATHRECIPIENT_H 17#define OHOS_HDI_CODEC_V3_0_CODECDEATHRECIPIENT_H 18 19#include <functional> 20#include "iremote_object.h" 21#include "refbase.h" 22#include "codec_component_manager_service.h" 23 24namespace OHOS { 25namespace HDI { 26namespace Codec { 27namespace V3_0 { 28 29void CleanResourceOfDiedService(sptr<IRemoteObject> remote, wptr<CodecComponentManagerService> service); 30void RegisterDeathRecipientService(const sptr<ICodecCallback> callback, uint32_t componentId, 31 wptr<CodecComponentManagerService> service); 32void RemoveMapperOfDestoryedComponent(uint32_t componentId); 33 34class CodecDeathRecipient : public IRemoteObject::DeathRecipient { 35public: 36 explicit CodecDeathRecipient(const wptr<CodecComponentManagerService> &service) : mgr(service) {}; 37 virtual ~CodecDeathRecipient() = default; 38 void OnRemoteDied(const wptr<IRemoteObject> &object) override 39 { 40 sptr<IRemoteObject> remote = object.promote(); 41 if (remote == nullptr) { 42 return; 43 } 44 CleanResourceOfDiedService(remote, mgr); 45 }; 46private: 47 wptr<CodecComponentManagerService> mgr; 48}; 49 50} // namespace V3_0 51} // namespace Codec 52} // namespace HDI 53} // namespace OHOS 54 55#endif // OHOS_HDI_CODEC_V3_0_CODECDEATHRECIPIENT_H 56