1 /*
2 * Copyright (c) 2022-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 "device_selection_notifier_stub.h"
17
18 #include <iosfwd>
19 #include <string>
20 #include <vector>
21
22 #include "base/continuationmgr_log.h"
23 #include "base/parcel_helper.h"
24 #include "errors.h"
25 #include "ipc_object_stub.h"
26 #include "ipc_types.h"
27
28 namespace OHOS {
29 namespace DistributedSchedule {
30 namespace {
31 const std::string TAG = "DeviceSelectionNotifierStub";
32 }
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t DeviceSelectionNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
35 MessageParcel& reply, MessageOption& option)
36 {
37 HILOGI("code = %{public}u", code);
38 std::u16string descriptor = IDeviceSelectionNotifier::GetDescriptor();
39 std::u16string remoteDescriptor = data.ReadInterfaceToken();
40 if (descriptor != remoteDescriptor) {
41 HILOGE("descriptor check failed");
42 return ERR_INVALID_VALUE;
43 }
44 switch (code) {
45 case static_cast<uint32_t>(IDRequestInterfaceCode::EVENT_DEVICE_CONNECT): {
46 std::vector<ContinuationResult> continuationResults;
47 if (!ContinuationResult::ReadContinuationResultsFromParcel(data, continuationResults)) {
48 return ERR_FLATTEN_OBJECT;
49 }
50 int32_t result = OnDeviceConnectInner(continuationResults);
51 return result;
52 }
53 case static_cast<uint32_t>(IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT): {
54 std::vector<ContinuationResult> continuationResults;
55 if (!ContinuationResult::ReadContinuationResultsFromParcel(data, continuationResults)) {
56 return ERR_FLATTEN_OBJECT;
57 }
58 int32_t result = OnDeviceDisconnectInner(continuationResults);
59 return result;
60 }
61 default: {
62 HILOGE("unknown request code, please check");
63 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
64 }
65 }
66 }
67
OnDeviceConnectInner(const std::vector<ContinuationResult> & continuationResults)68 int32_t DeviceSelectionNotifierStub::OnDeviceConnectInner(const std::vector<ContinuationResult>& continuationResults)
69 {
70 HILOGD("called");
71 OnDeviceConnect(continuationResults);
72 return ERR_OK;
73 }
74
OnDeviceDisconnectInner(const std::vector<ContinuationResult> & continuationResults)75 int32_t DeviceSelectionNotifierStub::OnDeviceDisconnectInner(const std::vector<ContinuationResult>& continuationResults)
76 {
77 HILOGD("called");
78 OnDeviceDisconnect(continuationResults);
79 return ERR_OK;
80 }
81 } // namespace DistributedSchedule
82 } // namespace OHOS