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 "continuation_manager/device_selection_notifier_proxy.h"
17
18 #include <string>
19
20 #include "base/continuationmgr_log.h"
21 #include "base/parcel_helper.h"
22 #include "continuation_result.h"
23 #include "iremote_object.h"
24 #include "message_option.h"
25 #include "message_parcel.h"
26
27 namespace OHOS {
28 namespace DistributedSchedule {
29 namespace {
30 const std::u16string DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDeviceSelectionNotifier";
31 const std::string TAG = "DeviceSelectionNotifierProxy";
32 }
33
OnDeviceConnect(const std::vector<ContinuationResult> & continuationResults)34 void DeviceSelectionNotifierProxy::OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults)
35 {
36 HILOGD("called");
37 MessageParcel data;
38 if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
39 return;
40 }
41 MessageParcel reply;
42 MessageOption option;
43 if (!ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults)) {
44 return;
45 }
46 sptr<IRemoteObject> remote = Remote();
47 if (remote == nullptr) {
48 HILOGE("Register remote is null");
49 return;
50 }
51 int32_t errCode = remote->SendRequest(static_cast<uint32_t>
52 (IDRequestInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
53 HILOGD("result = %{public}d", errCode);
54 }
55
OnDeviceDisconnect(const std::vector<ContinuationResult> & continuationResults)56 void DeviceSelectionNotifierProxy::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
57 {
58 HILOGD("called");
59 MessageParcel data;
60 if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
61 return;
62 }
63 MessageParcel reply;
64 MessageOption option;
65 if (!ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults)) {
66 return;
67 }
68 sptr<IRemoteObject> remote = Remote();
69 if (remote == nullptr) {
70 HILOGE("Register remote is null");
71 return;
72 }
73 int32_t errCode = remote->SendRequest(static_cast<uint32_t>
74 (IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
75 HILOGD("result = %{public}d", errCode);
76 }
77 } // namespace DistributedSchedule
78 } // namespace OHOS