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 "start_stop_result_call_back_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 {
StartStopResultCallbackStub()27 StartStopResultCallbackStub::StartStopResultCallbackStub() {}
28 
~StartStopResultCallbackStub()29 StartStopResultCallbackStub::~StartStopResultCallbackStub() {}
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t StartStopResultCallbackStub::OnRemoteRequest(
32     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34     std::u16string descriptor = data.ReadInterfaceToken();
35     if (descriptor != IStartStopResultCallback::GetDescriptor()) {
36         return ERR_DH_INPUT_IPC_INVALID_DESCRIPTOR;
37     }
38     IStartStopResultCallback::Message msgCode = static_cast<IStartStopResultCallback::Message>(code);
39     switch (msgCode) {
40         case IStartStopResultCallback::Message::RESULT_START: {
41             std::string srcId = data.ReadString();
42             std::string sinkId = data.ReadString();
43             uint32_t size = data.ReadUint32();
44             if (size > IPC_VECTOR_MAX_SIZE) {
45                 DHLOGI("OnRemoteRequest start data size too large.");
46                 return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
47             }
48             std::vector<std::string> dhIds;
49             for (uint32_t i = 0; i < size; i++) {
50                 std::string dhId = data.ReadString();
51                 dhIds.push_back(dhId);
52             }
53             DHLOGW("OnStart received.");
54             OnStart(srcId, sinkId, dhIds);
55             break;
56         }
57         case IStartStopResultCallback::Message::RESULT_STOP: {
58             std::string srcId = data.ReadString();
59             std::string sinkId = data.ReadString();
60             uint32_t size = data.ReadUint32();
61             if (size > IPC_VECTOR_MAX_SIZE) {
62                 DHLOGI("OnRemoteRequest stop data size too large.");
63                 return ERR_DH_INPUT_IPC_READ_VALID_FAIL;
64             }
65             std::vector<std::string> dhIds;
66             for (uint32_t i = 0; i < size; i++) {
67                 std::string dhId = data.ReadString();
68                 dhIds.push_back(dhId);
69             }
70             DHLOGW("OnStop received.");
71             OnStop(srcId, sinkId, dhIds);
72             break;
73         }
74         default:
75             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
76     }
77     return DH_SUCCESS;
78 }
79 } // namespace DistributedInput
80 } // namespace DistributedHardware
81 } // namespace OHOS
82