1 /*
2 * Copyright (c) 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_client_tracker_callback_proxy.h"
17
18 namespace OHOS {
19 namespace AudioStandard {
AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> & impl)20 AudioClientTrackerCallbackProxy::AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> &impl)
21 : IRemoteProxy<IStandardClientTracker>(impl) { }
22
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)23 void AudioClientTrackerCallbackProxy::PausedStreamImpl(
24 const StreamSetStateEventInternal &streamSetStateEventInternal)
25 {
26 MessageParcel data;
27 MessageParcel reply;
28 MessageOption option(MessageOption::TF_ASYNC);
29 if (!data.WriteInterfaceToken(GetDescriptor())) {
30 AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: PausedStreamImpl WriteInterfaceToken failed");
31 return;
32 }
33
34 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
35 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.audioStreamType));
36 int error = Remote()->SendRequest(PAUSEDSTREAM, data, reply, option);
37 if (error != ERR_NONE) {
38 AUDIO_ERR_LOG("PausedStreamImpl failed, error: %{public}d", error);
39 }
40 }
41
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)42 void AudioClientTrackerCallbackProxy::ResumeStreamImpl(
43 const StreamSetStateEventInternal &streamSetStateEventInternal)
44 {
45 MessageParcel data;
46 MessageParcel reply;
47 MessageOption option(MessageOption::TF_ASYNC);
48 if (!data.WriteInterfaceToken(GetDescriptor())) {
49 AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: ResumeStreamImpl WriteInterfaceToken failed");
50 return;
51 }
52
53 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
54 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.audioStreamType));
55 int error = Remote()->SendRequest(RESUMESTREAM, data, reply, option);
56 if (error != ERR_NONE) {
57 AUDIO_ERR_LOG("ResumeStreamImpl failed, error: %{public}d", error);
58 }
59 }
60
SetLowPowerVolumeImpl(float volume)61 void AudioClientTrackerCallbackProxy::SetLowPowerVolumeImpl(float volume)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66 if (!data.WriteInterfaceToken(GetDescriptor())) {
67 AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: WriteInterfaceToken failed");
68 return;
69 }
70
71 data.WriteFloat(static_cast<float>(volume));
72 int error = Remote()->SendRequest(SETLOWPOWERVOL, data, reply, option);
73 if (error != ERR_NONE) {
74 AUDIO_ERR_LOG("SETLOWPOWERVOL failed, error: %{public}d", error);
75 }
76 }
77
GetLowPowerVolumeImpl(float & volume)78 void AudioClientTrackerCallbackProxy::GetLowPowerVolumeImpl(float &volume)
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option;
83 if (!data.WriteInterfaceToken(GetDescriptor())) {
84 AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: WriteInterfaceToken failed");
85 return;
86 }
87
88 int error = Remote()->SendRequest(GETLOWPOWERVOL, data, reply, option);
89 if (error != ERR_NONE) {
90 AUDIO_ERR_LOG("GETLOWPOWERVOL failed, error: %{public}d", error);
91 }
92
93 volume = reply.ReadFloat();
94 }
95
GetSingleStreamVolumeImpl(float & volume)96 void AudioClientTrackerCallbackProxy::GetSingleStreamVolumeImpl(float &volume)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101 if (!data.WriteInterfaceToken(GetDescriptor())) {
102 AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: WriteInterfaceToken failed");
103 return;
104 }
105
106 int error = Remote()->SendRequest(GETSINGLESTREAMVOL, data, reply, option);
107 if (error != ERR_NONE) {
108 AUDIO_ERR_LOG("GETSINGLESTREAMVOL failed, error: %{public}d", error);
109 }
110
111 volume = reply.ReadFloat();
112 }
113
ClientTrackerCallbackListener(const sptr<IStandardClientTracker> & listener)114 ClientTrackerCallbackListener::ClientTrackerCallbackListener(const sptr<IStandardClientTracker> &listener)
115 : listener_(listener)
116 {
117 AUDIO_DEBUG_LOG("ClientTrackerCallbackListener");
118 }
119
~ClientTrackerCallbackListener()120 ClientTrackerCallbackListener::~ClientTrackerCallbackListener()
121 {
122 AUDIO_DEBUG_LOG("ClientTrackerCallbackListener destructor");
123 }
124
125
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)126 void ClientTrackerCallbackListener::PausedStreamImpl(
127 const StreamSetStateEventInternal &streamSetStateEventInternal)
128 {
129 if (listener_ != nullptr) {
130 listener_->PausedStreamImpl(streamSetStateEventInternal);
131 }
132 }
133
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)134 void ClientTrackerCallbackListener::ResumeStreamImpl(
135 const StreamSetStateEventInternal &streamSetStateEventInternal)
136 {
137 if (listener_ != nullptr) {
138 listener_->ResumeStreamImpl(streamSetStateEventInternal);
139 }
140 }
141
SetLowPowerVolumeImpl(float volume)142 void ClientTrackerCallbackListener::SetLowPowerVolumeImpl(float volume)
143 {
144 if (listener_ != nullptr) {
145 listener_->SetLowPowerVolumeImpl(volume);
146 }
147 }
148
GetLowPowerVolumeImpl(float & volume)149 void ClientTrackerCallbackListener::GetLowPowerVolumeImpl(float &volume)
150 {
151 if (listener_ != nullptr) {
152 listener_->GetLowPowerVolumeImpl(volume);
153 }
154 }
155
GetSingleStreamVolumeImpl(float & volume)156 void ClientTrackerCallbackListener::GetSingleStreamVolumeImpl(float &volume)
157 {
158 if (listener_ != nullptr) {
159 listener_->GetSingleStreamVolumeImpl(volume);
160 }
161 }
162 } // namespace AudioStandard
163 } // namespace OHOS
164