• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "audio_log.h"
16 #include "audio_volume_key_event_callback_proxy.h"
17 
18 namespace OHOS {
19 namespace AudioStandard {
AudioVolumeKeyEventCallbackProxy(const sptr<IRemoteObject> & impl)20 AudioVolumeKeyEventCallbackProxy::AudioVolumeKeyEventCallbackProxy(const sptr<IRemoteObject> &impl)
21     : IRemoteProxy<IAudioVolumeKeyEventCallback>(impl) { }
22 
OnVolumeKeyEvent(VolumeEvent volumeEvent)23 void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(VolumeEvent volumeEvent)
24 {
25     AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent");
26     MessageParcel data;
27     MessageParcel reply;
28     MessageOption option(MessageOption::TF_ASYNC);
29 
30     if (!data.WriteInterfaceToken(GetDescriptor())) {
31         AUDIO_ERR_LOG("AudioVolumeKeyEventCallbackProxy: WriteInterfaceToken failed");
32         return;
33     }
34     data.WriteInt32(static_cast<int32_t>(volumeEvent.volumeType));
35     data.WriteInt32(volumeEvent.volume);
36     data.WriteBool(volumeEvent.updateUi);
37     data.WriteInt32(volumeEvent.volumeGroupId);
38     data.WriteString(volumeEvent.networkId);
39     int error = Remote()->SendRequest(ON_VOLUME_KEY_EVENT, data, reply, option);
40     if (error != 0) {
41         AUDIO_DEBUG_LOG("Error while sending volume key event %{public}d", error);
42     }
43     reply.ReadInt32();
44 }
45 
VolumeKeyEventCallbackListner(const sptr<IAudioVolumeKeyEventCallback> & listener)46 VolumeKeyEventCallbackListner::VolumeKeyEventCallbackListner(const sptr<IAudioVolumeKeyEventCallback> &listener)
47     : listener_(listener)
48 {
49     AUDIO_DEBUG_LOG("VolumeKeyEventCallbackListner");
50 }
51 
~VolumeKeyEventCallbackListner()52 VolumeKeyEventCallbackListner::~VolumeKeyEventCallbackListner()
53 {
54     AUDIO_DEBUG_LOG("VolumeKeyEventCallbackListner desctrutor");
55 }
56 
OnVolumeKeyEvent(VolumeEvent volumeEvent)57 void VolumeKeyEventCallbackListner::OnVolumeKeyEvent(VolumeEvent volumeEvent)
58 {
59     AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy VolumeKeyEventCallbackListner");
60     if (listener_ != nullptr) {
61         listener_->OnVolumeKeyEvent(volumeEvent);
62     }
63 }
64 } // namespace AudioStandard
65 } // namespace OHOS
66