• 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 GRD_API_MANAGER_H
17 #define GRD_API_MANAGER_H
18 
19 #include "grd_type_export.h"
20 
21 namespace OHOS::CollaborationEdit {
22 // 1. Database open/close library interface encapsulation
23 typedef int32_t (*DBOpen)(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db);
24 typedef int32_t (*DBClose)(GRD_DB *db, uint32_t flags);
25 typedef int32_t (*SetLocalId)(GRD_DB *db,  const char *equipId);
26 typedef int32_t (*GetLocalId)(GRD_DB *db, char **localId);
27 typedef int32_t (*ApplyUpdate)(GRD_DB *db, char *equipId, char **applyInfo);
28 typedef int32_t (*WriteUpdate)(
29     GRD_DB *db, const char *equipId, const uint8_t *data, uint32_t size, const char *watermark);
30 typedef int32_t (*GetRelativePos)(GRD_DB *db, const char *tableName, const char *nodeSize, uint32_t pos, char **relPos);
31 typedef int32_t (*GetAbsolutePos)(
32     GRD_DB *db, const char *tableName, const char *relPos, const char *nodeSize, uint32_t *pos);
33 // 2. Node operation interface encapsulation
34 typedef int32_t (*InsertElements)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, uint32_t index,
35     GRD_DocNodeInfoT *nodeInfo, GRD_ElementIdT **outElementId);
36 typedef int32_t (*DeleteElements)(GRD_DB *db, const char *tableName, const GRD_ElementIdT *elementId, uint32_t index,
37     uint32_t length);
38 typedef int32_t (*GetElements)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, uint32_t index, uint32_t length,
39     char **respXml);
40 typedef int32_t (*FragmentToString)(GRD_DB *db, const char *tableName, const GRD_ElementIdT *elementId,
41     char **replyJson);
42 // 3. XmlElement attribute operation interface encapsulation
43 typedef int32_t (*ElementSetAttr)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, const char *attributeName,
44     const char *attributeValue, uint32_t flags);
45 typedef int32_t (*ElementRemoveAttr)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, const char *attributeName);
46 typedef int32_t (*ElementGetAttrs)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, char **allAttributes);
47 // 4. Text operation interface encapsulation
48 typedef int32_t (*TextInsert)(GRD_DB *db, GRD_XmlOpPositionT *opPos, uint32_t index, const char *content,
49     const char *formatStr);
50 typedef int32_t (*TextDelete)(GRD_DB *db, GRD_XmlOpPositionT *opPos, uint32_t index, uint32_t length);
51 typedef int32_t (*TextFormat)(GRD_DB *db, GRD_XmlOpPositionT *opPos, uint32_t index, uint32_t length,
52     const char *formatStr);
53 typedef int32_t (*TextGetLength)(GRD_DB *db, GRD_XmlOpPositionT *opPos, uint32_t *length);
54 typedef int32_t (*TextReadInStrMode)(GRD_DB *db, GRD_XmlOpPositionT *opPos, char **value);
55 typedef int32_t (*TextReadInDeltaMode)(GRD_DB *db, GRD_XmlOpPositionT *opPos, const char *snapshot,
56     const char *snapshotPrev, char **delta);
57 // 5. Undo/Redo operation interface encapsulation
58 typedef int32_t (*DocUndoManager)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, GRD_UndoParamT *param);
59 typedef int32_t (*DocCloseUndoManager)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr);
60 typedef int32_t (*DocUndo)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, char **modify);
61 typedef int32_t (*DocRedo)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr, char **modify);
62 typedef int32_t (*DocStopCapturing)(GRD_DB *db, GRD_XmlOpPositionT *elementAddr);
63 // 6. Sync operation interface encapsulation
64 typedef int32_t (*Sync)(GRD_DB *db, GRD_SyncConfigT *config);
65 typedef int32_t (*RegistryThreadPool)(GRD_DB *db, GRD_ThreadPoolT *ThreadPool);
66 // Last. Memory free and others
67 typedef void (*FreeElementId)(GRD_ElementIdT *outElementId);
68 typedef int32_t (*FreeValue)(char *value);
69 typedef int32_t (*SetCloudDb)(GRD_DB *db, GRD_ICloudDBT *iCloud);
70 
71 
72 struct GRD_APIInfo {
73     // 1. Database open/close library interface encapsulation
74     DBOpen DBOpenApi = nullptr;
75     DBClose DBCloseApi = nullptr;
76     SetLocalId SetLocalIdApi = nullptr;
77     GetLocalId GetLocalIdApi = nullptr;
78     ApplyUpdate ApplyUpdateApi = nullptr;
79     WriteUpdate WriteUpdateApi = nullptr;
80     GetRelativePos GetRelativePosApi = nullptr;
81     GetAbsolutePos GetAbsolutePosApi = nullptr;
82     // 2. Node operation inter
83     InsertElements InsertElementsApi = nullptr;
84     DeleteElements DeleteElementsApi = nullptr;
85     GetElements GetElementsApi = nullptr;
86     FragmentToString FragmentToStringApi = nullptr;
87     // 3. XmlElement attribute operation interface encapsulation
88     ElementSetAttr ElementSetAttrApi = nullptr;
89     ElementRemoveAttr ElementRemoveAttrApi = nullptr;
90     ElementGetAttrs ElementGetAttrsApi = nullptr;
91     // 4. Text operation interface encapsulation
92     TextInsert TextInsertApi = nullptr;
93     TextDelete TextDeleteApi = nullptr;
94     TextFormat TextFormatApi = nullptr;
95     TextGetLength TextGetLengthApi = nullptr;
96     TextReadInStrMode TextReadInStrModeApi = nullptr;
97     TextReadInDeltaMode TextReadInDeltaModeApi = nullptr;
98     // 5. Undo/Redo operation interface encapsulation
99     DocUndoManager DocUndoManagerApi = nullptr;
100     DocCloseUndoManager DocCloseUndoManagerApi = nullptr;
101     DocUndo DocUndoApi = nullptr;
102     DocRedo DocRedoApi = nullptr;
103     DocStopCapturing DocStopCapturingApi = nullptr;
104     // 6. Sync operation interface encapsulation
105     Sync SyncApi = nullptr;
106     RegistryThreadPool RegistryThreadPoolApi = nullptr;
107     // Last. Memory free and others
108     FreeElementId FreeElementIdApi = nullptr;
109     FreeValue FreeValueApi = nullptr;
110     SetCloudDb SetCloudDbApi = nullptr;
111 };
112 
113 GRD_APIInfo GetApiInfoInstance();
114 }  // namespace NativeRdb
115 
116 #endif  // GRD_API_MANAGER_H
117