1 /*
2  * Copyright (c) 2021-2024 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioConcurrencyStateListenerProxy"
17 #endif
18 
19 #include "audio_concurrency_state_listener_proxy.h"
20 #include "audio_policy_log.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
AudioConcurrencyStateListenerProxy(const sptr<IRemoteObject> & impl)24 AudioConcurrencyStateListenerProxy::AudioConcurrencyStateListenerProxy(const sptr<IRemoteObject> &impl)
25     : IRemoteProxy<IStandardConcurrencyStateListener>(impl)
26 {
27     AUDIO_DEBUG_LOG("instances create");
28 }
29 
~AudioConcurrencyStateListenerProxy()30 AudioConcurrencyStateListenerProxy::~AudioConcurrencyStateListenerProxy()
31 {
32     AUDIO_DEBUG_LOG("instance destroy");
33 }
34 
OnConcedeStream()35 void AudioConcurrencyStateListenerProxy::OnConcedeStream()
36 {
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option(MessageOption::TF_ASYNC);
40     if (!data.WriteInterfaceToken(GetDescriptor())) {
41         AUDIO_ERR_LOG("AudioConcurrencyStateListenerProxy: WriteInterfaceToken failed");
42         return;
43     }
44 
45     int error = Remote()->SendRequest(ON_CONCEDE_STREAM, data, reply, option);
46     if (error != ERR_NONE) {
47         AUDIO_ERR_LOG("OnConcedeStream failed, error: %{public}d", error);
48     }
49 }
50 
AudioConcurrencyListenerCallback(const sptr<IStandardConcurrencyStateListener> & listener)51 AudioConcurrencyListenerCallback::AudioConcurrencyListenerCallback(
52     const sptr<IStandardConcurrencyStateListener> &listener) : listener_(listener)
53 {
54     AUDIO_DEBUG_LOG("instance create");
55 }
56 
~AudioConcurrencyListenerCallback()57 AudioConcurrencyListenerCallback::~AudioConcurrencyListenerCallback()
58 {
59     AUDIO_DEBUG_LOG("instance destroy");
60 }
61 
OnConcedeStream()62 void AudioConcurrencyListenerCallback::OnConcedeStream()
63 {
64     if (listener_ != nullptr) {
65         listener_->OnConcedeStream();
66     }
67 }
68 
69 } // namespace AudioStandard
70 } // namespace OHOS