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