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 #include "session_listener_client.h" 17 #include "avsession_log.h" 18 19 namespace OHOS::AVSession { SessionListenerClient(const std::shared_ptr<SessionListener> & listener)20SessionListenerClient::SessionListenerClient(const std::shared_ptr<SessionListener>& listener) 21 : listener_(listener) 22 { 23 SLOGD("construct"); 24 } 25 ~SessionListenerClient()26SessionListenerClient::~SessionListenerClient() 27 { 28 SLOGI("SessionListenerClient gone"); 29 } 30 OnSessionCreate(const AVSessionDescriptor & descriptor)31void SessionListenerClient::OnSessionCreate(const AVSessionDescriptor& descriptor) 32 { 33 auto copiedListener = listener_; 34 if (copiedListener) { 35 SLOGI("on session create for bundle %{public}s", descriptor.elementName_.GetBundleName().c_str()); 36 copiedListener->OnSessionCreate(descriptor); 37 } else { 38 SLOGE("on session create with out listener"); 39 } 40 } 41 OnSessionRelease(const AVSessionDescriptor & descriptor)42void SessionListenerClient::OnSessionRelease(const AVSessionDescriptor& descriptor) 43 { 44 auto copiedListener = listener_; 45 if (copiedListener) { 46 copiedListener->OnSessionRelease(descriptor); 47 } 48 } 49 OnTopSessionChange(const AVSessionDescriptor & descriptor)50void SessionListenerClient::OnTopSessionChange(const AVSessionDescriptor& descriptor) 51 { 52 auto copiedListener = listener_; 53 if (copiedListener) { 54 copiedListener->OnTopSessionChange(descriptor); 55 } 56 } 57 OnAudioSessionChecked(const int32_t uid)58void SessionListenerClient::OnAudioSessionChecked(const int32_t uid) 59 { 60 auto copiedListener = listener_; 61 if (copiedListener) { 62 copiedListener->OnAudioSessionChecked(uid); 63 } 64 } 65 OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)66void SessionListenerClient::OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) 67 { 68 auto copiedListener = listener_; 69 if (copiedListener) { 70 copiedListener->OnDeviceAvailable(castOutputDeviceInfo); 71 } 72 } 73 OnDeviceLogEvent(const DeviceLogEventCode eventId,const int64_t param)74void SessionListenerClient::OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) 75 { 76 auto copiedListener = listener_; 77 if (copiedListener) { 78 copiedListener->OnDeviceLogEvent(eventId, param); 79 } 80 } 81 OnDeviceOffline(const std::string & deviceId)82void SessionListenerClient::OnDeviceOffline(const std::string& deviceId) 83 { 84 auto copiedListener = listener_; 85 if (copiedListener) { 86 copiedListener->OnDeviceOffline(deviceId); 87 } 88 } 89 OnRemoteDistributedSessionChange(const std::vector<sptr<IRemoteObject>> & sessionControllers)90void SessionListenerClient::OnRemoteDistributedSessionChange( 91 const std::vector<sptr<IRemoteObject>>& sessionControllers) 92 { 93 auto copiedListener = listener_; 94 if (copiedListener) { 95 copiedListener->OnRemoteDistributedSessionChange(sessionControllers); 96 } 97 } 98 } // namespace OHOS::AVSession 99