• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 }