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 "session_listener_proxy.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
SessionListenerProxy(const sptr<IRemoteObject> & impl)20 SessionListenerProxy::SessionListenerProxy(const sptr<IRemoteObject>& impl)
21 : IRemoteProxy<ISessionListener>(impl)
22 {
23 SLOGD("construct");
24 }
25
OnSessionCreate(const AVSessionDescriptor & descriptor)26 void SessionListenerProxy::OnSessionCreate(const AVSessionDescriptor& descriptor)
27 {
28 MessageParcel data;
29 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
30 CHECK_AND_RETURN_LOG(descriptor.WriteToParcel(data), "write descriptor failed");
31
32 auto remote = Remote();
33 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
34 MessageParcel reply;
35 MessageOption option = { MessageOption::TF_ASYNC };
36 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_ON_CREATE, data, reply, option) == 0, "send request fail");
37 }
38
OnSessionRelease(const AVSessionDescriptor & descriptor)39 void SessionListenerProxy::OnSessionRelease(const AVSessionDescriptor& descriptor)
40 {
41 MessageParcel data;
42 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
43 CHECK_AND_RETURN_LOG(descriptor.WriteToParcel(data), "write descriptor failed");
44
45 auto remote = Remote();
46 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
47 MessageParcel reply;
48 MessageOption option = { MessageOption::TF_ASYNC };
49 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_ON_RELEASE, data, reply, option) == 0, "send request fail");
50 }
51
OnTopSessionChange(const AVSessionDescriptor & descriptor)52 void SessionListenerProxy::OnTopSessionChange(const AVSessionDescriptor& descriptor)
53 {
54 MessageParcel data;
55 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
56 CHECK_AND_RETURN_LOG(descriptor.WriteToParcel(data), "write descriptor failed");
57
58 auto remote = Remote();
59 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
60 MessageParcel reply;
61 MessageOption option = { MessageOption::TF_ASYNC };
62 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_TOP_CHANGED, data, reply, option) == 0, "send request fail");
63 }
64
OnAudioSessionChecked(const int32_t uid)65 void SessionListenerProxy::OnAudioSessionChecked(const int32_t uid)
66 {
67 MessageParcel data;
68 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
69 CHECK_AND_RETURN_LOG(data.WriteInt32(uid), "write uid failed");
70
71 auto remote = Remote();
72 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
73 MessageParcel reply;
74 MessageOption option = { MessageOption::TF_ASYNC };
75 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_AUDIO_CHECKED, data, reply, option) == 0,
76 "send request fail");
77 }
78
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)79 void SessionListenerProxy::OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo)
80 {
81 MessageParcel data;
82 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
83 CHECK_AND_RETURN_LOG(castOutputDeviceInfo.WriteToParcel(data), "write castOutputDeviceInfo failed");
84
85 auto remote = Remote();
86 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
87 MessageParcel reply;
88 MessageOption option = { MessageOption::TF_ASYNC };
89 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_DEVICE_AVAILABLE, data, reply, option) == 0,
90 "send request fail");
91 }
92
OnDeviceLogEvent(const DeviceLogEventCode eventId,const int64_t param)93 void SessionListenerProxy::OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param)
94 {
95 MessageParcel data;
96 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
97 CHECK_AND_RETURN_LOG(data.WriteInt32(static_cast<int32_t>(eventId)), "write eventId failed");
98 CHECK_AND_RETURN_LOG(data.WriteInt64(param), "write param failed");
99
100 auto remote = Remote();
101 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
102 MessageParcel reply;
103 MessageOption option = { MessageOption::TF_ASYNC };
104 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_DEVICE_LOG_EVENT, data, reply, option) == 0,
105 "send request fail");
106 }
107
OnDeviceOffline(const std::string & deviceId)108 void SessionListenerProxy::OnDeviceOffline(const std::string& deviceId)
109 {
110 MessageParcel data;
111 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
112 CHECK_AND_RETURN_LOG(data.WriteString(deviceId), "write deviceId failed");
113
114 auto remote = Remote();
115 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
116 MessageParcel reply;
117 MessageOption option = { MessageOption::TF_ASYNC };
118 CHECK_AND_RETURN_LOG(remote->SendRequest(LISTENER_CMD_DEVICE_OFFLINE, data, reply, option) == 0,
119 "send request fail");
120 }
121 } // namespace OHOS::AVSession
122