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