• 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 #define LOG_TAG "GrdAdapter"
16 #include <dlfcn.h>
17 
18 #include "grd_adapter_manager.h"
19 #include "logger.h"
20 
21 namespace OHOS::DistributedDataAip {
GrdAdapterHolderInit(GrdAdapterHolder & adapterHolder)22 void GrdAdapterHolderInit(GrdAdapterHolder &adapterHolder)
23 {
24     adapterHolder.Open = (Open)dlsym(g_library, "GRD_DBOpen");
25     adapterHolder.Close = (Close)dlsym(g_library, "GRD_DBClose");
26     adapterHolder.Repair = (Repair)dlsym(g_library, "GRD_DBRepair");
27     adapterHolder.Backup = (Backup)dlsym(g_library, "GRD_DBBackup");
28     adapterHolder.Restore = (Restore)dlsym(g_library, "GRD_DBRestore");
29     adapterHolder.Rekey = (Rekey)dlsym(g_library, "GRD_DBRekey");
30 
31     adapterHolder.Prepare = (Prepare)dlsym(g_library, "GRD_GqlPrepare");
32     adapterHolder.Reset = (Reset)dlsym(g_library, "GRD_GqlReset");
33     adapterHolder.Finalize = (Finalize)dlsym(g_library, "GRD_GqlFinalize");
34     adapterHolder.Step = (Step)dlsym(g_library, "GRD_GqlStep");
35     adapterHolder.ColumnCount = (ColumnCount)dlsym(g_library, "GRD_GqlColumnCount");
36     adapterHolder.GetColumnType = (GetColumnType)dlsym(g_library, "GRD_GqlColumnType");
37     adapterHolder.ColumnBytes = (ColumnBytes)dlsym(g_library, "GRD_GqlColumnBytes");
38     adapterHolder.ColumnName = (ColumnName)dlsym(g_library, "GRD_GqlColumnName");
39     adapterHolder.ColumnValue = (ColumnValue)dlsym(g_library, "GRD_GqlColumnValue");
40     adapterHolder.ColumnInt64 = (ColumnInt64)dlsym(g_library, "GRD_GqlColumnInt64");
41     adapterHolder.ColumnInt = (ColumnInt)dlsym(g_library, "GRD_GqlColumnInt");
42     adapterHolder.ColumnDouble = (ColumnDouble)dlsym(g_library, "GRD_GqlColumnDouble");
43     adapterHolder.ColumnText = (ColumnText)dlsym(g_library, "GRD_GqlColumnText");
44 }
45 
IsSupportArkDataDb()46 bool IsSupportArkDataDb()
47 {
48 #ifdef ARKDATA_DB_CORE_IS_EXISTS
49     return true;
50 #else
51     return false;
52 #endif
53 }
54 
GetAdapterHolder()55 GrdAdapterHolder GetAdapterHolder()
56 {
57     GrdAdapterHolder adapterHolder;
58     if (g_library == nullptr) {
59         g_library = dlopen("libarkdata_db_core.z.so", RTLD_LAZY);
60     }
61     if (g_library == nullptr) {
62         LOG_WARN("use default db kernel");
63         return adapterHolder;
64     }
65     GrdAdapterHolderInit(adapterHolder);
66     return adapterHolder;
67 }
68 
69 } // namespace OHOS::DistributedDataAip
70