• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "acquire_share_data_callback_stub.h"
17 #include "hilog_wrapper.h"
18 #include "message_parcel.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
22 
AcquireShareDataCallbackStub()23 AcquireShareDataCallbackStub::AcquireShareDataCallbackStub()
24 {
25     vecMemberFunc_.resize(IAcquireShareDataCallback::CODE_MAX);
26     vecMemberFunc_[ACQUIRE_SHARE_DATA_DONE] = &AcquireShareDataCallbackStub::AcquireShareDataDoneInner;
27 }
28 
~AcquireShareDataCallbackStub()29 AcquireShareDataCallbackStub::~AcquireShareDataCallbackStub()
30 {
31     HILOG_INFO("~AcquireShareDataCallbackStub.");
32 }
33 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t AcquireShareDataCallbackStub::OnRemoteRequest(
35     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37     std::u16string descriptor = AcquireShareDataCallbackStub::GetDescriptor();
38     std::u16string remoteDescriptor = data.ReadInterfaceToken();
39     if (descriptor != remoteDescriptor) {
40         HILOG_INFO("local descriptor is not equal to remote.");
41         return ERR_INVALID_STATE;
42     }
43 
44     if (code < IAcquireShareDataCallback::CODE_MAX) {
45         auto memberFunc = vecMemberFunc_[code];
46         return (this->*memberFunc)(data, reply);
47     }
48     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50 
AcquireShareDataDoneInner(MessageParcel & data,MessageParcel & reply)51 int32_t AcquireShareDataCallbackStub::AcquireShareDataDoneInner(MessageParcel &data, MessageParcel &reply)
52 {
53     int32_t resultCode = data.ReadInt32();
54     std::shared_ptr<WantParams> wantParam(data.ReadParcelable<WantParams>());
55     if (wantParam == nullptr) {
56         HILOG_ERROR("wantParam is nullptr");
57         return ERR_INVALID_VALUE;
58     }
59     return AcquireShareDataDone(resultCode, *wantParam);
60 }
61 
AcquireShareDataDone(int32_t resultCode,WantParams & wantParam)62 int32_t AcquireShareDataCallbackStub::AcquireShareDataDone(int32_t resultCode, WantParams &wantParam)
63 {
64     HILOG_INFO("resultCode:%{public}d, wantParam size:%{public}d", resultCode, wantParam.Size());
65     if (resultCode || wantParam.IsEmpty()) {
66         HILOG_INFO("invaild param.");
67     }
68     auto task = [resultCode, wantParam, shareRuntimeTask = shareRuntimeTask_]() {
69         if (shareRuntimeTask) {
70             shareRuntimeTask(resultCode, wantParam);
71         }
72     };
73     HILOG_INFO("AcquireShareDataDone shareRuntimeTask start.");
74     if (!handler_) {
75         HILOG_ERROR("handler_ object is nullptr.");
76         return OBJECT_NULL;
77     }
78     handler_->PostTask(task, "AcquieShareDataDone.");
79     HILOG_INFO("AcquireShareDataDone shareRuntimeTask end.");
80     return NO_ERROR;
81 }
82 
SetHandler(std::shared_ptr<AppExecFwk::EventHandler> handler)83 void AcquireShareDataCallbackStub::SetHandler(std::shared_ptr<AppExecFwk::EventHandler> handler)
84 {
85     handler_ = handler;
86 }
87 
SetShareRuntimeTask(ShareRuntimeTask & shareRuntimeTask)88 void AcquireShareDataCallbackStub::SetShareRuntimeTask(ShareRuntimeTask &shareRuntimeTask)
89 {
90     shareRuntimeTask_ = shareRuntimeTask;
91 }
92 }
93 }