1 /*
2 * Copyright (c) 2022-2024 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 "remote_mission_listener_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
NotifyMissionsChanged(const std::string & deviceId)22 void RemoteMissionListenerProxy::NotifyMissionsChanged(const std::string& deviceId)
23 {
24 MessageParcel data;
25 MessageParcel reply;
26 MessageOption option;
27 if (!data.WriteInterfaceToken(RemoteMissionListenerProxy::GetDescriptor())) {
28 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyMissionsChanged Write interface token failed.");
29 return;
30 }
31 if (!data.WriteString(deviceId)) {
32 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyMissionsChanged Write deviceId failed.");
33 return;
34 }
35 int32_t result = SendTransactCmd(IRemoteMissionListener::NOTIFY_MISSION_CHANGED, data, reply, option);
36 if (result != NO_ERROR) {
37 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyMissionsChanged SendRequest fail, error: %{public}d", result);
38 return;
39 }
40 }
41
NotifySnapshot(const std::string & deviceId,int32_t missionId)42 void RemoteMissionListenerProxy::NotifySnapshot(const std::string& deviceId, int32_t missionId)
43 {
44 MessageParcel data;
45 MessageParcel reply;
46 MessageOption option;
47 if (!data.WriteInterfaceToken(RemoteMissionListenerProxy::GetDescriptor())) {
48 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifySnapshot Write interface token failed.");
49 return;
50 }
51 if (!data.WriteString(deviceId)) {
52 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifySnapshot Write deviceId failed.");
53 return;
54 }
55 if (!data.WriteInt32(missionId)) {
56 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifySnapshot Write missionId failed.");
57 return;
58 }
59 int32_t result = SendTransactCmd(IRemoteMissionListener::NOTIFY_SNAPSHOT, data, reply, option);
60 if (result != NO_ERROR) {
61 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifySnapshot SendRequest fail, error: %{public}d", result);
62 return;
63 }
64 }
65
NotifyNetDisconnect(const std::string & deviceId,int32_t state)66 void RemoteMissionListenerProxy::NotifyNetDisconnect(const std::string& deviceId, int32_t state)
67 {
68 MessageParcel data;
69 MessageParcel reply;
70 MessageOption option;
71 if (!data.WriteInterfaceToken(RemoteMissionListenerProxy::GetDescriptor())) {
72 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyNetDisconnect Write interface token failed.");
73 return;
74 }
75 if (!data.WriteString(deviceId)) {
76 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyNetDisconnect Write deviceId failed.");
77 return;
78 }
79 if (!data.WriteInt32(state)) {
80 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyNetDisconnect Write missionId failed.");
81 return;
82 }
83 int32_t result = SendTransactCmd(IRemoteMissionListener::NOTIFY_NET_DISCONNECT, data, reply, option);
84 if (result != NO_ERROR) {
85 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyNetDisconnect SendRequest fail, error: %{public}d", result);
86 return;
87 }
88 }
89
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)90 int32_t RemoteMissionListenerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
91 MessageParcel &reply, MessageOption &option)
92 {
93 sptr<IRemoteObject> remote = Remote();
94 if (remote == nullptr) {
95 TAG_LOGE(AAFwkTag::ABILITYMGR, "remote object is nullptr.");
96 return ERR_NULL_OBJECT;
97 }
98
99 int32_t ret = remote->SendRequest(code, data, reply, option);
100 if (ret != NO_ERROR) {
101 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest failed. code is %{public}d, ret is %{public}d.", code, ret);
102 return ret;
103 }
104 return NO_ERROR;
105 }
106 } // namespace AAFwk
107 } // namespace OHOS
108