1 /*
2 * Copyright (c) 2021-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 "mission/mission_changed_notify.h"
17
18 #include "datetime_ex.h"
19 #include "parcel_helper.h"
20 #include "string_ex.h"
21
22 namespace OHOS {
23 namespace DistributedSchedule {
24 namespace {
25 constexpr int32_t CODE_NOTIFY_MISSION = 0;
26 constexpr int32_t NOTIFY_SNAP_SHOT = 1;
27 constexpr int32_t NOTIFY_NET_DISCONNECT = 2;
28
29 const std::u16string DESCRIPTOR = u"ohos.aafwk.RemoteMissionListener";
30 const std::string TAG = "MissionChangedNotify";
31 }
NotifyMissionsChanged(const sptr<IRemoteObject> & remoteObject,const std::u16string & deviceId)32 void MissionChangedNotify::NotifyMissionsChanged(const sptr<IRemoteObject>& remoteObject,
33 const std::u16string& deviceId)
34 {
35 if (remoteObject == nullptr) {
36 HILOGE("NotifyMissionsChanged remote service is null!");
37 return;
38 }
39
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option(MessageOption::TF_ASYNC);
43 if (!data.WriteInterfaceToken(DESCRIPTOR)) {
44 HILOGE("NotifyMissionsChanged write interface token failed!");
45 return;
46 }
47 PARCEL_WRITE_HELPER_NORET(data, String, Str16ToStr8(deviceId));
48 HILOGI("[PerformanceTest] NotifyMissionsChanged called, IPC begin = %{public}" PRId64, GetTickCount());
49 int32_t error = remoteObject->SendRequest(CODE_NOTIFY_MISSION, data, reply, option);
50 if (error != ERR_NONE) {
51 HILOGE("NotifyMissionsChanged fail, error: %{public}d", error);
52 return;
53 }
54 HILOGI("NotifyMissionsChanged finished!");
55 }
56
NotifySnapshot(const sptr<IRemoteObject> & remoteObject,const std::u16string & deviceId,int32_t missionId)57 void MissionChangedNotify::NotifySnapshot(const sptr<IRemoteObject>& remoteObject, const std::u16string& deviceId,
58 int32_t missionId)
59 {
60 if (remoteObject == nullptr) {
61 HILOGE("NotifySnapshot remote service is null!");
62 return;
63 }
64
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option(MessageOption::TF_ASYNC);
68 if (!data.WriteInterfaceToken(DESCRIPTOR)) {
69 HILOGE("NotifySnapshot write interface token failed!");
70 return;
71 }
72 PARCEL_WRITE_HELPER_NORET(data, String, Str16ToStr8(deviceId));
73 PARCEL_WRITE_HELPER_NORET(data, Int32, missionId);
74 HILOGI("[PerformanceTest] NotifySnapshot called, IPC begin = %{public}" PRId64, GetTickCount());
75 int32_t error = remoteObject->SendRequest(NOTIFY_SNAP_SHOT, data, reply, option);
76 if (error != ERR_NONE) {
77 HILOGE("NotifySnapshot fail, error: %{public}d", error);
78 return;
79 }
80 HILOGI("NotifySnapshot finished!");
81 }
82
NotifyNetDisconnect(const sptr<IRemoteObject> & remoteObject,const std::u16string & deviceId,int32_t state)83 void MissionChangedNotify::NotifyNetDisconnect(const sptr<IRemoteObject>& remoteObject, const std::u16string& deviceId,
84 int32_t state)
85 {
86 if (remoteObject == nullptr) {
87 HILOGE("NotifyNetDisconnect remote service is null!");
88 return;
89 }
90
91 MessageParcel data;
92 MessageParcel reply;
93 MessageOption option(MessageOption::TF_ASYNC);
94 if (!data.WriteInterfaceToken(DESCRIPTOR)) {
95 HILOGE("NotifyNetDisconnect write interface token failed!");
96 return;
97 }
98 PARCEL_WRITE_HELPER_NORET(data, String, Str16ToStr8(deviceId));
99 PARCEL_WRITE_HELPER_NORET(data, Int32, state);
100 HILOGI("[PerformanceTest] NotifyNetDisconnect called, IPC begin = %{public}" PRId64, GetTickCount());
101 int32_t error = remoteObject->SendRequest(NOTIFY_NET_DISCONNECT, data, reply, option);
102 if (error != ERR_NONE) {
103 HILOGE("NotifyNetDisconnect fail, error: %{public}d", error);
104 return;
105 }
106 HILOGI("NotifyNetDisconnect finished!");
107 }
108 } // namespace DistributedSchedule
109 } // namespace OHOS
110