• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_errors.h"
18 #include "avsession_log.h"
19 
20 namespace OHOS::AVSession {
SessionListenerClient(const std::shared_ptr<SessionListener> & listener)21 SessionListenerClient::SessionListenerClient(const std::shared_ptr<SessionListener>& listener)
22     : listener_(listener)
23 {
24     SLOGD("construct");
25 }
26 
~SessionListenerClient()27 SessionListenerClient::~SessionListenerClient()
28 {
29     SLOGI("SessionListenerClient gone");
30 }
31 
OnSessionCreate(const AVSessionDescriptor & descriptor)32 ErrCode SessionListenerClient::OnSessionCreate(const AVSessionDescriptor& descriptor)
33 {
34     auto copiedListener = listener_;
35     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
36     SLOGI("on session create for bundle %{public}s", descriptor.elementName_.GetBundleName().c_str());
37     copiedListener->OnSessionCreate(descriptor);
38     return AVSESSION_SUCCESS;
39 }
40 
OnSessionRelease(const AVSessionDescriptor & descriptor)41 ErrCode SessionListenerClient::OnSessionRelease(const AVSessionDescriptor& descriptor)
42 {
43     auto copiedListener = listener_;
44     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
45     copiedListener->OnSessionRelease(descriptor);
46     return AVSESSION_SUCCESS;
47 }
48 
OnTopSessionChange(const AVSessionDescriptor & descriptor)49 ErrCode SessionListenerClient::OnTopSessionChange(const AVSessionDescriptor& descriptor)
50 {
51     auto copiedListener = listener_;
52     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
53     copiedListener->OnTopSessionChange(descriptor);
54     return AVSESSION_SUCCESS;
55 }
56 
OnAudioSessionChecked(const int32_t uid)57 ErrCode SessionListenerClient::OnAudioSessionChecked(const int32_t uid)
58 {
59     auto copiedListener = listener_;
60     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
61     copiedListener->OnAudioSessionChecked(uid);
62     return AVSESSION_SUCCESS;
63 }
64 
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)65 ErrCode SessionListenerClient::OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo)
66 {
67     auto copiedListener = listener_;
68     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
69     copiedListener->OnDeviceAvailable(castOutputDeviceInfo);
70     return AVSESSION_SUCCESS;
71 }
72 
OnDeviceLogEvent(const int32_t eventId,const int64_t param)73 ErrCode SessionListenerClient::OnDeviceLogEvent(const int32_t eventId, const int64_t param)
74 {
75     auto copiedListener = listener_;
76     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
77     DeviceLogEventCode eventCode = static_cast<DeviceLogEventCode>(eventId);
78     CHECK_AND_RETURN_RET_LOG(eventCode > 0 &&  eventCode < DeviceLogEventCode::DEVICE_LOG_MAX,
79         AVSESSION_ERROR, "there is no this eventCode");
80     copiedListener->OnDeviceLogEvent(eventCode, param);
81     return AVSESSION_SUCCESS;
82 }
83 
OnDeviceOffline(const std::string & deviceId)84 ErrCode SessionListenerClient::OnDeviceOffline(const std::string& deviceId)
85 {
86     auto copiedListener = listener_;
87     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
88     copiedListener->OnDeviceOffline(deviceId);
89     return AVSESSION_SUCCESS;
90 }
91 
OnRemoteDistributedSessionChange(const std::vector<sptr<IRemoteObject>> & sessionControllers)92 ErrCode SessionListenerClient::OnRemoteDistributedSessionChange(
93     const std::vector<sptr<IRemoteObject>>& sessionControllers)
94 {
95     auto copiedListener = listener_;
96     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
97     copiedListener->OnRemoteDistributedSessionChange(sessionControllers);
98     return AVSESSION_SUCCESS;
99 }
100 
OnDeviceStateChange(const DeviceState & deviceState)101 ErrCode SessionListenerClient::OnDeviceStateChange(const DeviceState& deviceState)
102 {
103     auto copiedListener = listener_;
104     CHECK_AND_RETURN_RET_LOG(copiedListener, AVSESSION_ERROR, "listener_ is null");
105     copiedListener->OnDeviceStateChange(deviceState);
106     return AVSESSION_SUCCESS;
107 }
108 } // namespace OHOS::AVSession
109