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 /** 17 * @file audio_renderer_death_recipient.h 18 * 19 * @brief audio renderer death recipient. 20 */ 21 22 #ifndef AUDIO_STREAM_DEATH_RECIPIENT_H 23 #define AUDIO_STREAM_DEATH_RECIPIENT_H 24 25 #include "iremote_object.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 class AudioStreamDeathRecipient : public IRemoteObject::DeathRecipient { 31 public: AudioStreamDeathRecipient(pid_t pid)32 explicit AudioStreamDeathRecipient(pid_t pid) : m_pid(pid) {}; 33 34 ~AudioStreamDeathRecipient() override = default; 35 DISALLOW_COPY_AND_MOVE(AudioStreamDeathRecipient); 36 OnRemoteDied(const wptr<IRemoteObject> & remote)37 void OnRemoteDied(const wptr <IRemoteObject> &remote) override 38 { 39 (void) remote; 40 if (m_callback != nullptr) { 41 m_callback(m_pid); 42 } 43 } 44 45 using ServerDiedCallback = std::function<void(pid_t)>; 46 SetServerDiedCallback(ServerDiedCallback callback)47 void SetServerDiedCallback(ServerDiedCallback callback) 48 { 49 m_callback = callback; 50 } 51 52 private: 53 pid_t m_pid = 0; 54 ServerDiedCallback m_callback = nullptr; 55 }; 56 } 57 } 58 59 #endif // AUDIO_STREAM_DEATH_RECIPIENT_H 60