1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#include "ability_connection_wrapper_proxy.h"
17686862fbSopenharmony_ci
18686862fbSopenharmony_ci#include "dtbschedmgr_log.h"
19686862fbSopenharmony_ci#include "ipc_object_proxy.h"
20686862fbSopenharmony_ci#include "ipc_types.h"
21686862fbSopenharmony_ci#include "parcel_helper.h"
22686862fbSopenharmony_ci
23686862fbSopenharmony_cinamespace OHOS {
24686862fbSopenharmony_cinamespace DistributedSchedule {
25686862fbSopenharmony_cinamespace {
26686862fbSopenharmony_ciconst std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
27686862fbSopenharmony_ciconst std::string TAG = "AbilityConnectionWrapperProxy";
28686862fbSopenharmony_ci}
29686862fbSopenharmony_ci
30686862fbSopenharmony_civoid AbilityConnectionWrapperProxy::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
31686862fbSopenharmony_ci    const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
32686862fbSopenharmony_ci{
33686862fbSopenharmony_ci    HILOGD("AbilityConnectionWrapperProxy::OnAbilityConnectDone called");
34686862fbSopenharmony_ci    MessageParcel data;
35686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
36686862fbSopenharmony_ci        return;
37686862fbSopenharmony_ci    }
38686862fbSopenharmony_ci
39686862fbSopenharmony_ci    MessageParcel reply;
40686862fbSopenharmony_ci    MessageOption option;
41686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
42686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, RemoteObject, remoteObject);
43686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Int32, resultCode);
44686862fbSopenharmony_ci
45686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
46686862fbSopenharmony_ci    if (remote == nullptr) {
47686862fbSopenharmony_ci        HILOGE("remote service null");
48686862fbSopenharmony_ci        return;
49686862fbSopenharmony_ci    }
50686862fbSopenharmony_ci    int32_t errCode = remote->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
51686862fbSopenharmony_ci    HILOGD("AbilityConnectionWrapperProxy::OnAbilityConnectDone result %{public}d", errCode);
52686862fbSopenharmony_ci}
53686862fbSopenharmony_ci
54686862fbSopenharmony_civoid AbilityConnectionWrapperProxy::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int32_t resultCode)
55686862fbSopenharmony_ci{
56686862fbSopenharmony_ci    HILOGD("AbilityConnectionWrapperProxy::OnAbilityDisconnectDone called");
57686862fbSopenharmony_ci    MessageParcel data;
58686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
59686862fbSopenharmony_ci        return;
60686862fbSopenharmony_ci    }
61686862fbSopenharmony_ci
62686862fbSopenharmony_ci    MessageParcel reply;
63686862fbSopenharmony_ci    MessageOption option;
64686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
65686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Int32, resultCode);
66686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
67686862fbSopenharmony_ci    if (remote == nullptr) {
68686862fbSopenharmony_ci        HILOGE("remote service null");
69686862fbSopenharmony_ci        return;
70686862fbSopenharmony_ci    }
71686862fbSopenharmony_ci    int32_t errCode = remote->SendRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
72686862fbSopenharmony_ci    HILOGD("AbilityConnectionWrapperProxy::OnAbilityDisconnectDone result %{public}d", errCode);
73686862fbSopenharmony_ci}
74686862fbSopenharmony_ci} // namespace DistributedSchedule
75686862fbSopenharmony_ci} // namespace OHOS