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 "AudioConcurrencyStateListenerStub"
17 #endif
18 
19 
20 #include "audio_policy_log.h"
21 #include "audio_concurrency_state_listener_stub.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 
AudioConcurrencyStateListenerStub()26 AudioConcurrencyStateListenerStub::AudioConcurrencyStateListenerStub()
27 {
28     AUDIO_DEBUG_LOG("concurrencyCbStub ctor");
29 }
30 
~AudioConcurrencyStateListenerStub()31 AudioConcurrencyStateListenerStub::~AudioConcurrencyStateListenerStub()
32 {
33     AUDIO_DEBUG_LOG("concurrencyCbStub dtor");
34 }
35 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int AudioConcurrencyStateListenerStub::OnRemoteRequest(
37     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39     CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(),
40         AUDIO_INVALID_PARAM, "ReadInterfaceToken failed");
41     switch (code) {
42         case ON_CONCEDE_STREAM: {
43             OnConcedeStream();
44             return AUDIO_OK;
45         }
46         default: {
47             AUDIO_ERR_LOG("default case, need check AudioListenerStub");
48             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49         }
50     }
51 }
52 
OnConcedeStream()53 void AudioConcurrencyStateListenerStub::OnConcedeStream()
54 {
55     std::shared_ptr<AudioConcurrencyCallback> cb = callback_.lock();
56     if (cb != nullptr) {
57         cb->OnConcedeStream();
58     } else {
59         AUDIO_WARNING_LOG("callback is nullptr");
60     }
61 }
62 
SetConcurrencyCallback(const std::weak_ptr<AudioConcurrencyCallback> & callback)63 void AudioConcurrencyStateListenerStub::SetConcurrencyCallback(const std::weak_ptr<AudioConcurrencyCallback> &callback)
64 {
65     callback_ = callback;
66 }
67 
68 } // namespace AudioStandard
69 } // namespace OHOS