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
16 #include "avcontroller_callback_proxy.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
AVControllerCallbackProxy(const sptr<IRemoteObject> & impl)20 AVControllerCallbackProxy::AVControllerCallbackProxy(const sptr<IRemoteObject>& impl)
21 : IRemoteProxy<IAVControllerCallback>(impl)
22 {
23 SLOGD("construct");
24 }
25
OnSessionDestroy()26 void AVControllerCallbackProxy::OnSessionDestroy()
27 {
28 MessageParcel parcel;
29 CHECK_AND_PRINT_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
30
31 MessageParcel reply;
32 MessageOption option = { MessageOption::TF_ASYNC };
33 auto remote = Remote();
34 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
35 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_SESSION_DESTROY, parcel, reply, option) == 0,
36 "send request failed");
37 }
38
OnPlaybackStateChange(const AVPlaybackState & state)39 void AVControllerCallbackProxy::OnPlaybackStateChange(const AVPlaybackState& state)
40 {
41 MessageParcel parcel;
42 CHECK_AND_PRINT_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
43 CHECK_AND_PRINT_LOG(parcel.WriteParcelable(&state), "write PlaybackState failed");
44
45 MessageParcel reply;
46 MessageOption option = { MessageOption::TF_ASYNC };
47 auto remote = Remote();
48 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
49 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_PLAYBACK_STATE_CHANGE, parcel, reply, option) == 0,
50 "send request failed");
51 }
52
OnMetaDataChange(const AVMetaData & data)53 void AVControllerCallbackProxy::OnMetaDataChange(const AVMetaData& data)
54 {
55 MessageParcel parcel;
56 CHECK_AND_PRINT_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
57 CHECK_AND_PRINT_LOG(parcel.WriteParcelable(&data), "write AVMetaData failed");
58
59 MessageParcel reply;
60 MessageOption option = { MessageOption::TF_ASYNC };
61 auto remote = Remote();
62 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
63 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_METADATA_CHANGE, parcel, reply, option) == 0,
64 "send request failed");
65 }
66
OnActiveStateChange(bool isActive)67 void AVControllerCallbackProxy::OnActiveStateChange(bool isActive)
68 {
69 MessageParcel parcel;
70 CHECK_AND_PRINT_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
71 CHECK_AND_PRINT_LOG(parcel.WriteBool(isActive), "write bool failed");
72
73 MessageParcel reply;
74 MessageOption option = { MessageOption::TF_ASYNC };
75 auto remote = Remote();
76 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
77 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_ACTIVE_STATE_CHANGE, parcel, reply, option) == 0,
78 "send request failed");
79 }
80
OnValidCommandChange(const std::vector<int32_t> & cmds)81 void AVControllerCallbackProxy::OnValidCommandChange(const std::vector<int32_t>& cmds)
82 {
83 MessageParcel parcel;
84 CHECK_AND_PRINT_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
85 CHECK_AND_PRINT_LOG(parcel.WriteInt32Vector(cmds), "write int32 vector failed");
86
87 MessageParcel reply;
88 MessageOption option = { MessageOption::TF_ASYNC };
89 auto remote = Remote();
90 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
91 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_VALID_COMMAND_CHANGE, parcel, reply, option) == 0,
92 "send request failed");
93 }
94
OnOutputDeviceChange(const OutputDeviceInfo & outputDeviceInfo)95 void AVControllerCallbackProxy::OnOutputDeviceChange(const OutputDeviceInfo& outputDeviceInfo)
96 {
97 MessageParcel parcel;
98 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
99 CHECK_AND_RETURN_LOG(parcel.WriteBool(outputDeviceInfo.isRemote_), "write isRemote_ failed");
100 CHECK_AND_RETURN_LOG(parcel.WriteStringVector(outputDeviceInfo.deviceIds_), "write deviceIds_ failed");
101 CHECK_AND_RETURN_LOG(parcel.WriteStringVector(outputDeviceInfo.deviceNames_), "write deviceNames_ failed");
102
103 MessageParcel reply;
104 MessageOption option = { MessageOption::TF_ASYNC };
105 auto remote = Remote();
106 CHECK_AND_PRINT_LOG(remote != nullptr, "get remote service failed");
107 CHECK_AND_PRINT_LOG(remote->SendRequest(CONTROLLER_CMD_ON_OUTPUT_DEVICE_CHANGE, parcel, reply, option) == 0,
108 "send request failed");
109 }
110 }