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 "dscreen_sink_stub.h"
17
18 #include "dscreen_constants.h"
19 #include "dscreen_errcode.h"
20 #include "dscreen_log.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
DScreenSinkStub()24 DScreenSinkStub::DScreenSinkStub()
25 {
26 DHLOGI("DScreenSinkStub construct.");
27 memberFuncMap_[INIT_SINK] = &DScreenSinkStub::InitSinkInner;
28 memberFuncMap_[RELEASE_SINK] = &DScreenSinkStub::ReleaseSinkInner;
29 memberFuncMap_[SUBSCRIBE_DISTRIBUTED_HARDWARE] = &DScreenSinkStub::SubscribeDistributedHardwareInner;
30 memberFuncMap_[UNSUBSCRIBE_DISTRIBUTED_HARDWARE] = &DScreenSinkStub::UnsubscribeDistributedHardwareInner;
31 memberFuncMap_[DSCREEN_NOTIFY] = &DScreenSinkStub::DScreenNotifyInner;
32 }
33
~DScreenSinkStub()34 DScreenSinkStub::~DScreenSinkStub()
35 {
36 DHLOGI("DScreenSinkStub deconstruct.");
37 }
38
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t DScreenSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
40 MessageOption &option)
41 {
42 DHLOGI("OnRemoteRequest, code: %d", code);
43 std::u16string desc = DScreenSinkStub::GetDescriptor();
44 std::u16string remoteDesc = data.ReadInterfaceToken();
45 if (desc != remoteDesc) {
46 DHLOGE("DScreenSinkStub::OnRemoteRequest remoteDesc is invalid!");
47 return ERR_INVALID_DATA;
48 }
49
50 const auto &iter = memberFuncMap_.find(code);
51 if (iter == memberFuncMap_.end()) {
52 DHLOGE("invalid request code.");
53 return ERR_DH_SCREEN_SA_INVALID_IPC_CALL;
54 }
55 DScreenSinkFunc &func = iter->second;
56 return (this->*func)(data, reply, option);
57 }
58
InitSinkInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)59 int32_t DScreenSinkStub::InitSinkInner(MessageParcel &data, MessageParcel &reply,
60 MessageOption &option)
61 {
62 DHLOGI("InitSinkInner");
63 std::string param = data.ReadString();
64 int32_t ret = InitSink(param);
65 reply.WriteInt32(ret);
66 return DH_SUCCESS;
67 }
68
ReleaseSinkInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)69 int32_t DScreenSinkStub::ReleaseSinkInner(MessageParcel &data, MessageParcel &reply,
70 MessageOption &option)
71 {
72 DHLOGI("ReleaseSinkInner");
73 int32_t ret = ReleaseSink();
74 reply.WriteInt32(ret);
75 return DH_SUCCESS;
76 }
77
SubscribeDistributedHardwareInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)78 int32_t DScreenSinkStub::SubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
79 MessageOption &option)
80 {
81 DHLOGI("SubscribeDistributedHardwareInner");
82 std::string dhId = data.ReadString();
83 std::string param = data.ReadString();
84 int32_t ret = SubscribeLocalHardware(dhId, param);
85 reply.WriteInt32(ret);
86 return DH_SUCCESS;
87 }
88
UnsubscribeDistributedHardwareInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)89 int32_t DScreenSinkStub::UnsubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
90 MessageOption &option)
91 {
92 DHLOGI("UnsubscribeDistributedHardwareInner");
93 std::string dhId = data.ReadString();
94 int32_t ret = UnsubscribeLocalHardware(dhId);
95 reply.WriteInt32(ret);
96 return DH_SUCCESS;
97 }
98
DScreenNotifyInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)99 int32_t DScreenSinkStub::DScreenNotifyInner(MessageParcel &data, MessageParcel &reply,
100 MessageOption &option)
101 {
102 DHLOGI("DScreenNotifyInner");
103 std::string devId = data.ReadString();
104 int32_t eventCode = data.ReadInt32();
105 std::string eventContent = data.ReadString();
106
107 DScreenNotify(devId, eventCode, eventContent);
108 return DH_SUCCESS;
109 }
110 } // namespace DistributedHardware
111 } // namespace OHOS