• 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 #include "grd_api_manager.h"
17 
18 #ifndef _WIN32
19 #include <dlfcn.h>
20 #endif
21 
22 #ifndef _WIN32
23 static void *g_library = nullptr;
24 #endif
25 
26 namespace OHOS::CollaborationEdit {
GRD_DBApiInitEnhance(GRD_APIInfo & GRD_DBApiInfo)27 void GRD_DBApiInitEnhance(GRD_APIInfo &GRD_DBApiInfo)
28 {
29 #ifndef _WIN32
30     // 1. Database open/close library interface encapsulation
31     GRD_DBApiInfo.DBOpenApi = (DBOpen)dlsym(g_library, "GRD_DBOpen");
32     GRD_DBApiInfo.DBCloseApi = (DBClose)dlsym(g_library, "GRD_DBClose");
33     GRD_DBApiInfo.SetLocalIdApi = (SetLocalId)dlsym(g_library, "GRD_SetEquipId");
34     GRD_DBApiInfo.GetLocalIdApi = (GetLocalId)dlsym(g_library, "GRD_GetEquipId");
35     GRD_DBApiInfo.ApplyUpdateApi = (ApplyUpdate)dlsym(g_library, "GRD_OplogRelayApply");
36     GRD_DBApiInfo.WriteUpdateApi = (WriteUpdate)dlsym(g_library, "GRD_WriteLogWithEquipId");
37     GRD_DBApiInfo.GetRelativePosApi = (GetRelativePos)dlsym(g_library, "GRD_AbsolutePositionToRelativePosition");
38     GRD_DBApiInfo.GetAbsolutePosApi = (GetAbsolutePos)dlsym(g_library, "GRD_RelativePositionToAbsolutePosition");
39     // 2. Node operation interface encapsulation
40     GRD_DBApiInfo.InsertElementsApi = (InsertElements)dlsym(g_library, "GRD_XmlFragmentInsert");
41     GRD_DBApiInfo.DeleteElementsApi = (DeleteElements)dlsym(g_library, "GRD_XmlFragmentDelete");
42     GRD_DBApiInfo.GetElementsApi = (GetElements)dlsym(g_library, "GRD_XmlFragmentGet");
43     GRD_DBApiInfo.FragmentToStringApi = (FragmentToString)dlsym(g_library, "GRD_XmlFragmentToString");
44     // 3. XmlElement attribute operation interface encapsulation
45     GRD_DBApiInfo.ElementSetAttrApi = (ElementSetAttr)dlsym(g_library, "GRD_XmlElementSetAttribute");
46     GRD_DBApiInfo.ElementRemoveAttrApi = (ElementRemoveAttr)dlsym(g_library, "GRD_XmlElementRemoveAttribute");
47     GRD_DBApiInfo.ElementGetAttrsApi = (ElementGetAttrs)dlsym(g_library, "GRD_XmlElementGetAttributes");
48     // 4. Text operation interface encapsulation
49     GRD_DBApiInfo.TextInsertApi = (TextInsert)dlsym(g_library, "GRD_TextInsert");
50     GRD_DBApiInfo.TextDeleteApi = (TextDelete)dlsym(g_library, "GRD_TextDelete");
51     GRD_DBApiInfo.TextFormatApi = (TextFormat)dlsym(g_library, "GRD_TextAssignFormats");
52     GRD_DBApiInfo.TextGetLengthApi = (TextGetLength)dlsym(g_library, "GRD_TextGetLength");
53     GRD_DBApiInfo.TextReadInStrModeApi = (TextReadInStrMode)dlsym(g_library, "GRD_TextReadInStrMode");
54     GRD_DBApiInfo.TextReadInDeltaModeApi = (TextReadInDeltaMode)dlsym(g_library, "GRD_TextReadInDeltaMode");
55     // 5. Undo/Redo operation interface encapsulation
56     GRD_DBApiInfo.DocUndoManagerApi = (DocUndoManager)dlsym(g_library, "GRD_DocUndoManager");
57     GRD_DBApiInfo.DocCloseUndoManagerApi = (DocCloseUndoManager)dlsym(g_library, "GRD_DocUndoManagerClose");
58     GRD_DBApiInfo.DocUndoApi = (DocUndo)dlsym(g_library, "GRD_DocUndo");
59     GRD_DBApiInfo.DocRedoApi = (DocRedo)dlsym(g_library, "GRD_DocRedo");
60     GRD_DBApiInfo.DocStopCapturingApi = (DocStopCapturing)dlsym(g_library, "GRD_DocStopCapturing");
61     // 6. Sync operation interface encapsulation
62     GRD_DBApiInfo.SyncApi = (Sync)dlsym(g_library, "GRD_Sync");
63     GRD_DBApiInfo.RegistryThreadPoolApi = (RegistryThreadPool)dlsym(g_library, "GRD_RegistryThreadPool");
64     // Last. Memory free and others
65     GRD_DBApiInfo.FreeElementIdApi = (FreeElementId)dlsym(g_library, "GRD_XmlFreeElementId");
66     GRD_DBApiInfo.FreeValueApi = (FreeValue)dlsym(g_library, "GRD_DocFree");
67     GRD_DBApiInfo.SetCloudDbApi = (SetCloudDb)dlsym(g_library, "GRD_RegistryCloudDB");
68 #endif
69 }
70 
GetApiInfoInstance()71 GRD_APIInfo GetApiInfoInstance()
72 {
73     GRD_APIInfo GRD_TempApiStruct;
74 #ifndef _WIN32
75     g_library = dlopen("libarkdata_db_core.z.so", RTLD_LAZY);
76     if (g_library) {
77         GRD_DBApiInitEnhance(GRD_TempApiStruct);
78     }
79 #endif
80     return GRD_TempApiStruct;
81 }
82 }  // namespace OHOS::CollaborationEdit
83