• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "distributed_file_daemon_manager.h"
17 #include "pasteboard_hilog.h"
18 #include "pasteboard_progress_signal.h"
19 
20 namespace OHOS {
21 namespace MiscServices {
22 std::mutex ProgressSignalClient::mutex_;
23 ProgressSignalClient *ProgressSignalClient::instance_ = nullptr;
24 
GetInstance()25 ProgressSignalClient &ProgressSignalClient::GetInstance()
26 {
27     if (instance_ == nullptr) {
28         std::lock_guard<std::mutex> lock(mutex_);
29         instance_ = new ProgressSignalClient();
30     }
31     return *instance_;
32 }
33 
Init()34 void ProgressSignalClient::Init()
35 {
36     instance_ = nullptr;
37     needCancel_.store(false);
38     remoteTask_.store(false);
39 }
40 
Cancel()41 void ProgressSignalClient::Cancel()
42 {
43     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "ProgressSignalClient Cancel in!");
44     needCancel_.store(true);
45 }
46 
IsCanceled()47 bool ProgressSignalClient::IsCanceled()
48 {
49     return needCancel_.load() || remoteTask_.load();
50 }
51 
CheckCancelIfNeed()52 bool ProgressSignalClient::CheckCancelIfNeed()
53 {
54     if (!needCancel_.load()) {
55         return false;
56     }
57     return true;
58 }
59 
SetRemoteTaskCancel()60 void ProgressSignalClient::SetRemoteTaskCancel()
61 {
62     needCancel_.store(true);
63 }
64 } // namespace MiscServices
65 } // namespace OHOS