1 /*
2 * Copyright (c) 2021-2022 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 "status_receiver_impl.h"
17
18 #include "app_log_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
22 namespace {
23 const int32_t MINIMUM_WAITTING_TIME = 180; // 3 mins
24 } // namespace
25
StatusReceiverImpl(int32_t waittingTime)26 StatusReceiverImpl::StatusReceiverImpl(int32_t waittingTime) : waittingTime_(waittingTime)
27 {
28 APP_LOGI("create status receiver instance");
29 }
30
StatusReceiverImpl()31 StatusReceiverImpl::StatusReceiverImpl() : waittingTime_(MINIMUM_WAITTING_TIME)
32 {
33 APP_LOGI("create status receiver instance");
34 }
35
~StatusReceiverImpl()36 StatusReceiverImpl::~StatusReceiverImpl()
37 {
38 APP_LOGI("destroy status receiver instance");
39 }
40
OnFinished(const int32_t resultCode,const std::string & resultMsg)41 void StatusReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg)
42 {
43 APP_LOGI("on finished result is %{public}d, %{public}s", resultCode, resultMsg.c_str());
44 resultMsgSignal_.set_value(resultCode);
45 }
46
OnStatusNotify(const int progress)47 void StatusReceiverImpl::OnStatusNotify(const int progress)
48 {
49 APP_LOGI("on OnStatusNotify is %{public}d", progress);
50 }
51
GetResultCode() const52 int32_t StatusReceiverImpl::GetResultCode() const
53 {
54 auto future = resultMsgSignal_.get_future();
55 if (future.wait_for(std::chrono::seconds(waittingTime_)) == std::future_status::ready) {
56 int32_t resultCode = future.get();
57 return resultCode;
58 }
59 return ERR_OPERATION_TIME_OUT;
60 }
61 } // namespace AppExecFwk
62 } // namespace OHOS