• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "distributed_extension_proxy.h"
17 
18 #include "dtbschedmgr_log.h"
19 
20 namespace OHOS {
21 namespace DistributedSchedule {
22 const std::string TAG = "DExtensionProxy";
23 
TriggerOnCreate(AAFwk::Want & want)24 int32_t DExtensionProxy::TriggerOnCreate(AAFwk::Want &want)
25 {
26     HILOGI("TriggerOnCreate");
27     sptr<IRemoteObject> remote = Remote();
28     if (remote == nullptr) {
29         HILOGE("Register remote is null");
30         return ERR_NULL_OBJECT;
31     }
32     MessageParcel data;
33     if (!data.WriteInterfaceToken(GetDescriptor())) {
34         HILOGE("DExtensionProxy::TriggerOnCreate Write interface token failed!");
35         return ERR_FLATTEN_OBJECT;
36     }
37 
38     if (!data.WriteParcelable(&want)) {
39         HILOGE("DExtensionProxy::TriggerOnCreate due to write want fail");
40         return ERR_INVALID_VALUE;
41     }
42 
43     MessageParcel reply;
44     MessageOption option;
45     int32_t ret =
46         remote->SendRequest(static_cast<uint32_t>(IDExtensionInterfaceCode::CMD_ON_CREATE), data, reply, option);
47     if (ret != NO_ERROR) {
48         HILOGE("DExtensionProxy::TriggerOnCreate Transact ErrCode = %{public}d", ret);
49         return ret;
50     }
51     HILOGI("TriggerOnCreate Success");
52 
53     return NO_ERROR;
54 }
55 
TriggerOnDestroy(void)56 int32_t DExtensionProxy::TriggerOnDestroy(void)
57 {
58     HILOGI("TriggerOnDestroy");
59     sptr<IRemoteObject> remote = Remote();
60     if (remote == nullptr) {
61         HILOGE("Register remote is null");
62         return ERR_NULL_OBJECT;
63     }
64     MessageParcel data;
65     if (!data.WriteInterfaceToken(GetDescriptor())) {
66         HILOGE("DExtensionProxy::TriggerOnDestroy Write interface token failed!");
67         return ERR_FLATTEN_OBJECT;
68     }
69 
70     MessageParcel reply;
71     MessageOption option;
72     int32_t ret =
73         remote->SendRequest(static_cast<uint32_t>(IDExtensionInterfaceCode::CMD_ON_DESTORY), data, reply, option);
74     if (ret != NO_ERROR) {
75         HILOGE("DExtensionProxy::TriggerOnDestroy Transact ErrCode = %{public}d", ret);
76         return ret;
77     }
78     HILOGI("TriggerOnDestroy Success");
79 
80     return NO_ERROR;
81 }
82 
TriggerOnCollaborate(AAFwk::WantParams & wantParam)83 int32_t DExtensionProxy::TriggerOnCollaborate(AAFwk::WantParams &wantParam)
84 {
85     HILOGI("TriggerOnCollaborate");
86     sptr<IRemoteObject> remote = Remote();
87     if (remote == nullptr) {
88         HILOGE("Register remote is null");
89         return ERR_NULL_OBJECT;
90     }
91     MessageParcel data;
92     if (!data.WriteInterfaceToken(GetDescriptor())) {
93         HILOGE("DExtensionProxy::TriggerOnCollaborate Write interface token failed!");
94         return ERR_FLATTEN_OBJECT;
95     }
96 
97     if (!data.WriteParcelable(&wantParam)) {
98         HILOGE("DExtensionProxy::TriggerOnCollaborate due to write want fail");
99         return ERR_INVALID_VALUE;
100     }
101 
102     MessageParcel reply;
103     MessageOption option;
104     int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDExtensionInterfaceCode::CMD_ON_COLLAB_REQUEST),
105         data, reply, option);
106     if (ret != NO_ERROR) {
107         HILOGE("DExtensionProxy::TriggerOnCollaborate Transact ErrCode = %{public}d", ret);
108         return ret;
109     }
110     HILOGI("TriggerOnCollaborate Success");
111 
112     return NO_ERROR;
113 }
114 }
115 } // namespace OHOS
116