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 int32_t errCode = Remote()->SendRequest(static_cast<uint32_t>
47 (IDRequestInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
48 HILOGD("result = %{public}d", errCode);
49 }
50
OnDeviceDisconnect(const std::vector<ContinuationResult> & continuationResults)51 void DeviceSelectionNotifierProxy::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
52 {
53 HILOGD("called");
54 MessageParcel data;
55 if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
56 return;
57 }
58 MessageParcel reply;
59 MessageOption option;
60 if (!ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults)) {
61 return;
62 }
63 int32_t errCode = Remote()->SendRequest(static_cast<uint32_t>
64 (IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
65 HILOGD("result = %{public}d", errCode);
66 }
67 } // namespace DistributedSchedule
68 } // namespace OHOS