• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "fs_task_signal.h"
17 
18 #include "file_utils.h"
19 #include "filemgmt_libhilog.h"
20 #include "fs_utils.h"
21 
22 namespace OHOS {
23 namespace FileManagement {
24 namespace ModuleFileIO {
25 using namespace std;
26 
Constructor(shared_ptr<TaskSignal> taskSignal,shared_ptr<TaskSignalListener> signalListener)27 FsResult<unique_ptr<FsTaskSignal>> FsTaskSignal::Constructor(
28     shared_ptr<TaskSignal> taskSignal, shared_ptr<TaskSignalListener> signalListener)
29 {
30     if (!taskSignal) {
31         HILOGE("Invalid taskSignal");
32         return FsResult<unique_ptr<FsTaskSignal>>::Error(EINVAL);
33     }
34     if (!signalListener) {
35         HILOGE("Invalid signalListener");
36         return FsResult<unique_ptr<FsTaskSignal>>::Error(EINVAL);
37     }
38     auto copySignal = CreateUniquePtr<FsTaskSignal>();
39     if (copySignal == nullptr) {
40         HILOGE("Failed to request heap memory.");
41         return FsResult<unique_ptr<FsTaskSignal>>::Error(ENOMEM);
42     }
43     copySignal->taskSignal_ = move(taskSignal);
44     copySignal->signalListener_ = move(signalListener);
45     return FsResult<unique_ptr<FsTaskSignal>>::Success(move(copySignal));
46 }
47 
Cancel()48 FsResult<void> FsTaskSignal::Cancel()
49 {
50     if (taskSignal_ == nullptr) {
51         HILOGE("Failed to get taskSignal");
52         return FsResult<void>::Error(EINVAL);
53     }
54 
55     auto ret = taskSignal_->Cancel();
56     if (ret != ERRNO_NOERR) {
57         HILOGE("Failed to cancel the task.");
58         return FsResult<void>::Error(CANCEL_ERR);
59     }
60     return FsResult<void>::Success();
61 }
62 
OnCancel()63 FsResult<void> FsTaskSignal::OnCancel()
64 {
65     if (taskSignal_ == nullptr) {
66         HILOGE("Failed to get taskSignal");
67         return FsResult<void>::Error(EINVAL);
68     }
69     taskSignal_->SetTaskSignalListener(signalListener_.get());
70     return FsResult<void>::Success();
71 }
72 
GetTaskSignal() const73 shared_ptr<TaskSignal> FsTaskSignal::GetTaskSignal() const
74 {
75     return taskSignal_;
76 }
77 
FsTaskSignal()78 FsTaskSignal::FsTaskSignal()
79 {
80     taskSignal_ = CreateSharedPtr<TaskSignal>();
81 }
82 
83 } // namespace ModuleFileIO
84 } // namespace FileManagement
85 } // namespace OHOS