• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "distributed_input_sink_stub.h"
17 
18 #include "constants_dinput.h"
19 #include "dinput_errcode.h"
20 #include "dinput_ipc_interface_code.h"
21 #include "dinput_log.h"
22 #include "dinput_utils_tool.h"
23 #include "i_sharing_dhid_listener.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 namespace DistributedInput {
DistributedInputSinkStub()28 DistributedInputSinkStub::DistributedInputSinkStub()
29 {
30     DHLOGI("DistributedInputSinkStub ctor!");
31     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::INIT)] =
32         &DistributedInputSinkStub::InitInner;
33     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::RELEASE)] =
34         &DistributedInputSinkStub::ReleaseInner;
35     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::NOTIFY_START_DSCREEN)] =
36         &DistributedInputSinkStub::NotifyStartDScreenInner;
37     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::NOTIFY_STOP_DSCREEN)] =
38         &DistributedInputSinkStub::NotifyStopDScreenInner;
39     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::REGISTER_SHARING_DHID_LISTENER)] =
40         &DistributedInputSinkStub::RegisterSharingDhIdListenerInner;
41     memberFuncMap_[static_cast<uint32_t>(IDInputSinkInterfaceCode::GET_SINK_SCREEN_INFOS)] =
42         &DistributedInputSinkStub::RegisterGetSinkScreenInfosInner;
43 }
44 
~DistributedInputSinkStub()45 DistributedInputSinkStub::~DistributedInputSinkStub()
46 {
47     DHLOGI("DistributedInputSinkStub dtor!");
48     memberFuncMap_.clear();
49 }
50 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
52     MessageOption &option)
53 {
54     if (data.ReadInterfaceToken() != GetDescriptor()) {
55         DHLOGE("DistributedInputSinkStub read token valid failed");
56         return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
57     }
58     auto iter = memberFuncMap_.find(code);
59     if (iter == memberFuncMap_.end()) {
60         DHLOGE("invalid request code is %d.", code);
61         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62     }
63     DistributedInputSinkFunc &func = iter->second;
64     return (this->*func)(data, reply, option);
65 }
66 
InitInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)67 int32_t DistributedInputSinkStub::InitInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
68 {
69     DHLOGI("DistributedInputSinkStub InitInner start");
70     int32_t ret = Init();
71     if (!reply.WriteInt32(ret)) {
72         DHLOGE("DistributedInputSinkStub write ret failed, ret = %d", ret);
73         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
74     }
75     return ret;
76 }
77 
ReleaseInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)78 int32_t DistributedInputSinkStub::ReleaseInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
79 {
80     int32_t ret = Release();
81     if (!reply.WriteInt32(ret)) {
82         DHLOGE("DistributedInputSinkStub write ret failed, ret = %d", ret);
83         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
84     }
85     return ret;
86 }
87 
NotifyStartDScreenInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)88 int32_t DistributedInputSinkStub::NotifyStartDScreenInner(MessageParcel &data, MessageParcel &reply,
89     MessageOption &option)
90 {
91     std::string devId = data.ReadString();
92     int32_t sessionId = data.ReadInt32();
93     std::string uuid = data.ReadString();
94     uint64_t sourceWinId = data.ReadUint64();
95     uint32_t sourceWinWidth = data.ReadUint32();
96     uint32_t sourceWinHeight = data.ReadUint32();
97     std::string sourcePhyId = data.ReadString();
98     uint32_t sourcePhyFd = data.ReadUint32();
99     uint32_t sourcePhyWidth = data.ReadUint32();
100     uint32_t sourcePhyHeight = data.ReadUint32();
101     DHLOGI("OnRemoteRequest the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d, sourceWinHeight: %d,"
102         "sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d", GetAnonyString(devId).c_str(),
103         sourceWinId, sourceWinWidth, sourceWinHeight, GetAnonyString(sourcePhyId).c_str(), sourcePhyFd, sourcePhyWidth,
104         sourcePhyHeight);
105     SrcScreenInfo srcScreenInfo = {
106         .devId = devId,
107         .sessionId = sessionId,
108         .uuid = uuid,
109         .sourceWinId = sourceWinId,
110         .sourceWinWidth = sourceWinWidth,
111         .sourceWinHeight = sourceWinHeight,
112         .sourcePhyId = sourcePhyId,
113         .sourcePhyFd = sourcePhyFd,
114         .sourcePhyWidth = sourcePhyWidth,
115         .sourcePhyHeight = sourcePhyHeight,
116     };
117     int32_t ret = NotifyStartDScreen(srcScreenInfo);
118     if (!reply.WriteInt32(ret)) {
119         DHLOGE("write reply failed ret = %d", ret);
120         return ERR_DH_INPUT_RPC_REPLY_FAIL;
121     }
122     return ret;
123 }
124 
NotifyStopDScreenInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)125 int32_t DistributedInputSinkStub::NotifyStopDScreenInner(MessageParcel &data, MessageParcel &reply,
126     MessageOption &option)
127 {
128     std::string srcScreenInfoKey = data.ReadString();
129     DHLOGI("OnRemoteRequest srcScreenInfoKey: %s", GetAnonyString(srcScreenInfoKey).c_str());
130     int ret = NotifyStopDScreen(srcScreenInfoKey);
131     if (!reply.WriteInt32(ret)) {
132         DHLOGE("write version failed, ret = %d", ret);
133         return ERR_DH_INPUT_RPC_REPLY_FAIL;
134     }
135     return ret;
136 }
137 
RegisterSharingDhIdListenerInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)138 int32_t DistributedInputSinkStub::RegisterSharingDhIdListenerInner(MessageParcel &data, MessageParcel &reply,
139     MessageOption &option)
140 {
141     sptr<ISharingDhIdListener> listener = iface_cast<ISharingDhIdListener>(data.ReadRemoteObject());
142     if (listener == nullptr) {
143         DHLOGE("RegisterSharingDhIdListenerInner failed, listener is nullptr.");
144         return ERR_DH_INPUT_POINTER_NULL;
145     }
146     int32_t ret = RegisterSharingDhIdListener(listener);
147     if (!reply.WriteInt32(ret)) {
148         DHLOGE("RegisterSharingDhIdListenerInner write ret failed, ret = %d", ret);
149         return ERR_DH_INPUT_SINK_STUB_REGISTER_SHARING_DHID_LISTENER_FAIL;
150     }
151 
152     return DH_SUCCESS;
153 }
154 
RegisterGetSinkScreenInfosInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)155 int32_t DistributedInputSinkStub::RegisterGetSinkScreenInfosInner(MessageParcel &data, MessageParcel &reply,
156     MessageOption &option)
157 {
158     sptr<IGetSinkScreenInfosCallback> callback =
159         iface_cast<IGetSinkScreenInfosCallback>(data.ReadRemoteObject());
160     if (callback == nullptr) {
161         DHLOGE("RegisterGetSinkScreenInfosInner failed, callback is nullptr.");
162         return ERR_DH_INPUT_POINTER_NULL;
163     }
164     int32_t ret = RegisterGetSinkScreenInfosCallback(callback);
165     if (!reply.WriteInt32(ret)) {
166         DHLOGE("write ret failed, ret = %d", ret);
167         return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
168     }
169     return ret;
170 }
171 } // namespace DistributedInput
172 } // namespace DistributedHardware
173 } // namespace OHOS
174