• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef NAPI_DATASHARE_INNER_OBSERVER_H
17 #define NAPI_DATASHARE_INNER_OBSERVER_H
18 
19 #include <uv.h>
20 
21 #include "napi/native_common.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 
25 namespace OHOS {
26 namespace DataShare {
27 class NAPIInnerObserver : public std::enable_shared_from_this<NAPIInnerObserver> {
28 public:
29     NAPIInnerObserver(napi_env env, napi_value callback);
30     void OnChange();
31     void DeleteReference();
32     napi_ref GetCallback();
33 private:
34     static void OnComplete(uv_work_t *work, int status);
35     struct ObserverWorker {
36         std::weak_ptr<NAPIInnerObserver> observer_;
ObserverWorkerObserverWorker37         ObserverWorker(std::shared_ptr<NAPIInnerObserver> observerIn)
38             : observer_(observerIn) {}
39     };
40 
41     napi_env env_ = nullptr;
42     napi_ref ref_ = nullptr;
43     uv_loop_s *loop_ = nullptr;
44 };
45 }  // namespace DataShare
46 }  // namespace OHOS
47 #endif //NAPI_DATASHARE_INNER_OBSERVER_H
48