• 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 #ifndef OHOS_DISTRIBUTED_DATA_GDB_JS_NAPI_GDB_JS_UTILS_H
17 #define OHOS_DISTRIBUTED_DATA_GDB_JS_NAPI_GDB_JS_UTILS_H
18 #include "full_result.h"
19 #include "gdb_store_config.h"
20 #include "js_utils.h"
21 #include "logger.h"
22 #include "napi_gdb_context.h"
23 
24 namespace OHOS::AppDataMgrJsKit::JSUtils {
25 using namespace GraphStoreJsKit;
26 using StoreConfig = DistributedDataAip::StoreConfig;
27 using Vertex = OHOS::DistributedDataAip::Vertex;
28 using Edge = OHOS::DistributedDataAip::Edge;
29 using PathSegment = OHOS::DistributedDataAip::PathSegment;
30 using Path = OHOS::DistributedDataAip::Path;
31 
32 #define GRAPH_ASSERT(condition, message, retVal)                 \
33     do {                                                         \
34         if (!(condition)) {                                      \
35             LOG_ERROR("test (" #condition ") failed: " message); \
36             return retVal;                                       \
37         }                                                        \
38     } while (0)
39 
40 #define NAPI_CALL_RETURN_ERR(theCall, retVal) \
41     do {                                      \
42         if ((theCall) != napi_ok) {           \
43             return retVal;                    \
44         }                                     \
45     } while (0)
46 
47 #ifndef PATH_SPLIT
48 #define PATH_SPLIT '/'
49 #endif
50 
LogLabel()51 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
52 {
53     return { LOG_CORE, 0xD001660, "GdbJSUtils" };
54 }
55 
56 template<>
57 int32_t Convert2Value(napi_env env, napi_value jsValue, ContextParam &context);
58 
59 template<>
60 int32_t Convert2Value(napi_env env, napi_value jsValue, StoreConfig &config);
61 
62 template<>
63 napi_value Convert2JSValue(napi_env env, const std::shared_ptr<Result> &result);
64 
65 template<>
66 napi_value Convert2JSValue(napi_env env, const std::shared_ptr<Vertex> &value);
67 
68 template<>
69 napi_value Convert2JSValue(napi_env env, const std::shared_ptr<Edge> &edge);
70 
71 template<>
72 napi_value Convert2JSValue(napi_env env, const std::shared_ptr<PathSegment> &pathSegment);
73 
74 template<>
75 napi_value Convert2JSValue(napi_env env, const std::shared_ptr<Path> &path);
76 
77 std::tuple<int32_t, std::shared_ptr<Error>> GetRealPath(StoreConfig &config, ContextParam &param);
78 } // namespace OHOS::AppDataMgrJsKit::JSUtils
79 
80 #endif