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 "continuation_manager/device_selection_notifier_proxy.h"
17
18 #include <string>
19
20 #include "continuation_result.h"
21 #include "dtbschedmgr_log.h"
22 #include "iremote_object.h"
23 #include "message_option.h"
24 #include "message_parcel.h"
25 #include "parcel_helper.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(IDeviceSelectionNotifier::EVENT_DEVICE_CONNECT, data, reply, option);
47 HILOGD("result = %{public}d", errCode);
48 }
49
OnDeviceDisconnect(const std::vector<ContinuationResult> & continuationResults)50 void DeviceSelectionNotifierProxy::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
51 {
52 HILOGD("called");
53 MessageParcel data;
54 if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
55 return;
56 }
57 MessageParcel reply;
58 MessageOption option;
59 if (!ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults)) {
60 return;
61 }
62 int32_t errCode = Remote()->SendRequest(IDeviceSelectionNotifier::EVENT_DEVICE_DISCONNECT, data, reply, option);
63 HILOGD("result = %{public}d", errCode);
64 }
65 } // namespace DistributedSchedule
66 } // namespace OHOS