• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_RETURN_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_RETURN_LOG(remote != nullptr, "get remote service failed");
35     CHECK_AND_RETURN_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_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
43     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&state), "write PlaybackState failed");
44 
45     MessageParcel reply;
46     MessageOption option = { MessageOption::TF_ASYNC };
47     auto remote = Remote();
48     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
49     CHECK_AND_RETURN_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_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
57     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&data), "write AVMetaData failed");
58 
59     MessageParcel reply;
60     MessageOption option = { MessageOption::TF_ASYNC };
61     auto remote = Remote();
62     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
63     CHECK_AND_RETURN_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_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
71     CHECK_AND_RETURN_LOG(parcel.WriteBool(isActive), "write bool failed");
72 
73     MessageParcel reply;
74     MessageOption option = { MessageOption::TF_ASYNC };
75     auto remote = Remote();
76     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
77     CHECK_AND_RETURN_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_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
85     CHECK_AND_RETURN_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_RETURN_LOG(remote != nullptr, "get remote service failed");
91     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_VALID_COMMAND_CHANGE, parcel, reply, option) == 0,
92         "send request failed");
93 }
94 
OnOutputDeviceChange(const int32_t connectionState,const OutputDeviceInfo & outputDeviceInfo)95 void AVControllerCallbackProxy::OnOutputDeviceChange(const int32_t connectionState,
96     const OutputDeviceInfo& outputDeviceInfo)
97 {
98     MessageParcel parcel;
99     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
100     CHECK_AND_RETURN_LOG(parcel.WriteInt32(connectionState), "write connectionState failed");
101 
102     int32_t deviceInfoSize = static_cast<int32_t>(outputDeviceInfo.deviceInfos_.size());
103     CHECK_AND_RETURN_LOG(parcel.WriteInt32(deviceInfoSize), "write deviceInfoSize failed");
104     for (DeviceInfo deviceInfo : outputDeviceInfo.deviceInfos_) {
105         CHECK_AND_RETURN_LOG(parcel.WriteInt32(deviceInfo.castCategory_), "write castCategory failed");
106         CHECK_AND_RETURN_LOG(parcel.WriteString(deviceInfo.deviceId_), "write deviceId failed");
107         CHECK_AND_RETURN_LOG(parcel.WriteString(deviceInfo.deviceName_), "write deviceName failed");
108         CHECK_AND_RETURN_LOG(parcel.WriteInt32(deviceInfo.deviceType_), "write deviceType failed");
109         CHECK_AND_RETURN_LOG(parcel.WriteString(deviceInfo.ipAddress_), "write ipAddress failed");
110         CHECK_AND_RETURN_LOG(parcel.WriteInt32(deviceInfo.providerId_), "write providerId failed");
111     }
112 
113     MessageParcel reply;
114     MessageOption option = { MessageOption::TF_ASYNC };
115     auto remote = Remote();
116     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
117     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_OUTPUT_DEVICE_CHANGE, parcel, reply, option) == 0,
118         "send request failed");
119 }
120 
OnSessionEventChange(const std::string & event,const AAFwk::WantParams & args)121 void AVControllerCallbackProxy::OnSessionEventChange(const std::string& event, const AAFwk::WantParams& args)
122 {
123     MessageParcel parcel;
124     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
125     CHECK_AND_RETURN_LOG(parcel.WriteString(event), "write event string failed");
126     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&args), "Write Want failed");
127     MessageParcel reply;
128     MessageOption option = { MessageOption::TF_ASYNC };
129     auto remote = Remote();
130     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
131     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_SET_SESSION_EVENT, parcel, reply, option) == 0,
132         "send request failed");
133 }
134 
OnQueueItemsChange(const std::vector<AVQueueItem> & items)135 void AVControllerCallbackProxy::OnQueueItemsChange(const std::vector<AVQueueItem>& items)
136 {
137     MessageParcel parcel;
138     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
139 
140     CHECK_AND_RETURN_LOG(parcel.WriteInt32(items.size()), "write items num int32 failed");
141     for (auto &parcelable : items) {
142         CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&parcelable), "Write items failed");
143     }
144 
145     MessageParcel reply;
146     MessageOption option = { MessageOption::TF_ASYNC };
147     auto remote = Remote();
148     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
149     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_QUEUE_ITEMS_CHANGE, parcel, reply, option) == 0,
150         "send request failed");
151 }
152 
OnQueueTitleChange(const std::string & title)153 void AVControllerCallbackProxy::OnQueueTitleChange(const std::string& title)
154 {
155     MessageParcel parcel;
156     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
157     CHECK_AND_RETURN_LOG(parcel.WriteString(title), "write string failed");
158     MessageParcel reply;
159     MessageOption option = { MessageOption::TF_ASYNC };
160     auto remote = Remote();
161     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
162     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_QUEUE_TITLE_CHANGE, parcel, reply, option) == 0,
163         "send request failed");
164 }
165 
OnExtrasChange(const AAFwk::WantParams & extras)166 void AVControllerCallbackProxy::OnExtrasChange(const AAFwk::WantParams& extras)
167 {
168     MessageParcel parcel;
169     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
170     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&extras), "Write extras failed");
171     MessageParcel reply;
172     MessageOption option = { MessageOption::TF_ASYNC };
173     auto remote = Remote();
174     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
175     CHECK_AND_RETURN_LOG(remote->SendRequest(CONTROLLER_CMD_ON_SET_EXTRAS_EVENT, parcel, reply, option) == 0,
176         "send request failed");
177 }
178 } // namespace OHOS::AVSession
179