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_watcher_ani.h"
17
18 #include "error_handler.h"
19 #include "filemgmt_libhilog.h"
20 #include "fs_watcher.h"
21 #include "fs_watcher_wrapper.h"
22 #include "type_converter.h"
23
24 namespace OHOS {
25 namespace FileManagement {
26 namespace ModuleFileIO {
27 namespace ANI {
28 using namespace OHOS::FileManagement::ModuleFileIO;
29 using namespace std;
30
Start(ani_env * env,ani_object object)31 void FsWatcherAni::Start(ani_env *env, [[maybe_unused]] ani_object object)
32 {
33 auto watcher = FsWatcherWrapper::Unwrap(env, object);
34 if (watcher == nullptr) {
35 HILOGE("Cannot unwrap watcher!");
36 ErrorHandler::Throw(env, UNKNOWN_ERR);
37 return;
38 }
39 auto ret = watcher->Start();
40 if (!ret.IsSuccess()) {
41 HILOGE("Cannot start watcher!");
42 const auto &err = ret.GetError();
43 ErrorHandler::Throw(env, err);
44 return;
45 }
46 }
47
Stop(ani_env * env,ani_object object)48 void FsWatcherAni::Stop(ani_env *env, [[maybe_unused]] ani_object object)
49 {
50 auto watcher = FsWatcherWrapper::Unwrap(env, object);
51 if (watcher == nullptr) {
52 HILOGE("Cannot unwrap watcher!");
53 ErrorHandler::Throw(env, UNKNOWN_ERR);
54 return;
55 }
56 auto ret = watcher->Stop();
57 if (!ret.IsSuccess()) {
58 HILOGE("Cannot stop watcher!");
59 const auto &err = ret.GetError();
60 ErrorHandler::Throw(env, err);
61 return;
62 }
63 }
64
65 } // namespace ANI
66 } // namespace ModuleFileIO
67 } // namespace FileManagement
68 } // namespace OHOS