• 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 #ifndef ANI_DATASHARE_INNER_OBSERVER_H
17 #define ANI_DATASHARE_INNER_OBSERVER_H
18 
19 #include <ani.h>
20 
21 #include "datashare_log.h"
22 #include "datashare_helper.h"
23 
24 namespace OHOS {
25 namespace DataShare {
26 class ANIInnerObserver : public std::enable_shared_from_this<ANIInnerObserver> {
27 public:
28     ANIInnerObserver(ani_vm *vm, ani_ref callback);
29     virtual ~ANIInnerObserver();
30     void OnChange(const DataShareObserver::ChangeInfo &changeInfo = {}, bool isNotifyDetails = false);
31     ani_ref GetCallback();
32 
33 private:
34     ani_object GetNewChangeInfo(ani_env *env);
35     ani_enum_item GetEnumItem(ani_env *env, int32_t type);
36     ani_object Convert2TSValue(ani_env *env, const std::monostate &value = {});
37     ani_object Convert2TSValue(ani_env *env, int64_t value);
38     ani_object Convert2TSValue(ani_env *env, double value);
39     ani_object Convert2TSValue(ani_env *env, bool value);
40     ani_object Convert2TSValue(ani_env *env, const std::string &value);
41     ani_object Convert2TSValue(ani_env *env, const std::vector<uint8_t> &values);
42     template<class... Types>
43     ani_object Convert2TSValue(ani_env *env, const std::variant<Types...> &value);
44     ani_object Convert2TSValue(ani_env *env, const DataShareValuesBucket &valueBucket);
45     template<typename T>
46     ani_object Convert2TSValue(ani_env *env, const std::vector<T> &values);
47     ani_object Convert2TSValue(ani_env *env, const DataShareObserver::ChangeInfo& changeInfo);
48     template<typename _VTp>
49     ani_object ReadVariant(ani_env *env, size_t step, size_t index, const _VTp &value);
50     template<typename _VTp, typename _First, typename ..._Rest>
51     ani_object ReadVariant(ani_env *env, size_t step, size_t index, const _VTp &value);
52 
53 private:
54     ani_vm *vm_;
55     ani_ref callback_;
56 };
57 }  // namespace DataShare
58 }  // namespace OHOS
59 #endif //ANI_DATASHARE_INNER_OBSERVER_H