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 "sharing_dhid_listener_stub.h"
17
18 #include "string_ex.h"
19
20 #include "constants_dinput.h"
21 #include "dinput_errcode.h"
22 #include "dinput_log.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace DistributedInput {
SharingDhIdListenerStub()27 SharingDhIdListenerStub::SharingDhIdListenerStub() {}
28
~SharingDhIdListenerStub()29 SharingDhIdListenerStub::~SharingDhIdListenerStub() {}
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t SharingDhIdListenerStub::OnRemoteRequest(
32 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34 if (data.ReadInterfaceToken() != GetDescriptor()) {
35 DHLOGE("SharingDhIdListenerStub read token valid failed");
36 return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
37 }
38 ISharingDhIdListener::Message msgCode = static_cast<ISharingDhIdListener::Message>(code);
39 switch (msgCode) {
40 case ISharingDhIdListener::Message::SHARING: {
41 std::string dhId = data.ReadString();
42 int32_t ret = OnSharing(dhId);
43 if (!reply.WriteInt32(ret)) {
44 DHLOGE("SharingDhIdListenerStub write ret failed");
45 return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
46 }
47 break;
48 }
49 case ISharingDhIdListener::Message::NO_SHARING: {
50 std::string dhId = data.ReadString();
51 int32_t ret = OnNoSharing(dhId);
52 if (!reply.WriteInt32(ret)) {
53 DHLOGE("SharingDhIdListenerStub write ret failed");
54 return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL;
55 }
56 break;
57 }
58 default:
59 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61 return DH_SUCCESS;
62 }
63 } // namespace DistributedInput
64 } // namespace DistributedHardware
65 } // namespace OHOS
66