• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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  * Description: supply cast session listener implement stub.
15  * Author: zhangge
16  * Create: 2022-6-15
17  */
18 
19 #include "cast_session_listener_impl_stub.h"
20 
21 #include "cast_engine_common_helper.h"
22 #include "cast_stub_helper.h"
23 
24 namespace OHOS {
25 namespace CastEngine {
26 namespace CastEngineClient {
27 DEFINE_CAST_ENGINE_LABEL("Cast-Client-SessionListener");
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int CastSessionListenerImplStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30     MessageOption &option)
31 {
32     RETRUEN_IF_WRONG_TASK(code, data, reply, option);
33     return EXECUTE_SINGLE_STUB_TASK(code, data, reply);
34 }
35 
CastSessionListenerImplStub(std::shared_ptr<ICastSessionListener> userListener_)36 CastSessionListenerImplStub::CastSessionListenerImplStub(std::shared_ptr<ICastSessionListener> userListener_)
37     : userListener_(userListener_)
38 {
39     FILL_SINGLE_STUB_TASK(ON_DEVICE_STATE, &CastSessionListenerImplStub::DoOnDeviceStateTask);
40     FILL_SINGLE_STUB_TASK(ON_EVENT, &CastSessionListenerImplStub::DoOnEventTask);
41     FILL_SINGLE_STUB_TASK(ON_REMOTE_CTRL_EVENT, &CastSessionListenerImplStub::DoOnRemoteCtrlEventTask);
42 }
43 
DoOnDeviceStateTask(MessageParcel & data,MessageParcel & reply)44 int32_t CastSessionListenerImplStub::DoOnDeviceStateTask(MessageParcel &data, MessageParcel &reply)
45 {
46     static_cast<void>(reply);
47     auto stateInfo = ReadDeviceStateInfo(data);
48     if (stateInfo == nullptr) {
49         CLOGE("sate info is null");
50         return ERR_NULL_OBJECT;
51     }
52     userListener_->OnDeviceState(*stateInfo);
53 
54     return ERR_NONE;
55 }
56 
DoOnEventTask(MessageParcel & data,MessageParcel & reply)57 int32_t CastSessionListenerImplStub::DoOnEventTask(MessageParcel &data, MessageParcel &reply)
58 {
59     static_cast<void>(reply);
60     int32_t eventId;
61     std::string param;
62     if (!ReadEvent(data, eventId, param)) {
63         CLOGE("read event failed");
64         return ERR_NULL_OBJECT;
65     }
66     userListener_->OnEvent(static_cast<EventId>(eventId), param);
67 
68     return ERR_NONE;
69 }
70 
DoOnRemoteCtrlEventTask(MessageParcel & data,MessageParcel & reply)71 int32_t CastSessionListenerImplStub::DoOnRemoteCtrlEventTask(MessageParcel &data, MessageParcel &reply)
72 {
73     static_cast<void>(reply);
74     int32_t eventType = data.ReadInt32();
75     uint32_t len = data.ReadUint32();
76     const uint8_t *buf = data.ReadBuffer(static_cast<size_t>(len));
77     if (len == 0 || buf == nullptr) {
78         CLOGE("invalid buffer, len = %{public}u", len);
79         return ERR_NULL_OBJECT;
80     }
81     CLOGE("DoOnRemoteCtrlEventTask, len = %{public}u", len);
82     userListener_->OnRemoteCtrlEvent(eventType, buf, len);
83 
84     return ERR_NONE;
85 }
86 
OnDeviceState(const DeviceStateInfo & stateInfo)87 void CastSessionListenerImplStub::OnDeviceState(const DeviceStateInfo &stateInfo)
88 {
89     static_cast<void>(stateInfo);
90 }
91 
OnEvent(const EventId & eventId,const std::string & jsonParam)92 void CastSessionListenerImplStub::OnEvent(const EventId &eventId, const std::string &jsonParam)
93 {
94     static_cast<void>(eventId);
95     static_cast<void>(jsonParam);
96 }
97 
OnRemoteCtrlEvent(int eventType,const uint8_t * data,uint32_t len)98 void CastSessionListenerImplStub::OnRemoteCtrlEvent(int eventType, const uint8_t *data, uint32_t len)
99 {
100     static_cast<void>(eventType);
101     static_cast<void>(data);
102     static_cast<void>(len);
103 }
104 } // namespace CastEngineClient
105 } // namespace CastEngine
106 } // namespace OHOS
107