1 /*
2 * Copyright (c) 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 "startup_task_result.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
22 StartupTaskResult::StartupTaskResult() = default;
23
24 StartupTaskResult::~StartupTaskResult() = default;
25
StartupTaskResult(int32_t resultCode,const std::string & resultMessage)26 StartupTaskResult::StartupTaskResult(int32_t resultCode, const std::string &resultMessage)
27 : resultCode_(resultCode), resultMessage_(resultMessage)
28 {}
29
SetResult(int32_t resultCode,const std::string & resultMessage)30 void StartupTaskResult::SetResult(int32_t resultCode, const std::string &resultMessage)
31 {
32 resultCode_ = resultCode;
33 resultMessage_ = resultMessage;
34 }
35
SetResultMessage(const std::string & resultMessage)36 void StartupTaskResult::SetResultMessage(const std::string &resultMessage)
37 {
38 resultMessage_ = resultMessage;
39 }
40
GetResultCode() const41 int32_t StartupTaskResult::GetResultCode() const
42 {
43 return resultCode_;
44 }
45
GetResultMessage() const46 const std::string& StartupTaskResult::GetResultMessage() const
47 {
48 return resultMessage_;
49 }
50
GetResultType() const51 StartupTaskResult::ResultType StartupTaskResult::GetResultType() const
52 {
53 return ResultType::INVALID;
54 }
55
OnCompletedCallback(OnCompletedCallbackFunc callbackFunc)56 OnCompletedCallback::OnCompletedCallback(OnCompletedCallbackFunc callbackFunc)
57 : callbackFunc_(std::move(callbackFunc))
58 {}
59
60 OnCompletedCallback::~OnCompletedCallback() = default;
61
Call(const std::shared_ptr<StartupTaskResult> & result)62 void OnCompletedCallback::Call(const std::shared_ptr<StartupTaskResult> &result)
63 {
64 if (isCalled_) {
65 TAG_LOGD(AAFwkTag::STARTUP, "callback already called");
66 return;
67 }
68 if (callbackFunc_ == nullptr) {
69 TAG_LOGE(AAFwkTag::STARTUP, "callbackFunc null");
70 return;
71 }
72 callbackFunc_(result);
73 isCalled_ = true;
74 }
75
IsCalled() const76 bool OnCompletedCallback::IsCalled() const
77 {
78 return isCalled_;
79 }
80 } // namespace AbilityRuntime
81 } // namespace OHOS
82