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 COLLABORATION_EDIT_RD_ADAPTER_H 17 #define COLLABORATION_EDIT_RD_ADAPTER_H 18 19 #include "db_store.h" 20 #include "grd_type_export.h" 21 #include "rd_utils.h" 22 23 namespace OHOS::CollaborationEdit { 24 static constexpr const uint8_t NUMBER_OF_CHARS_IN_LABEL_PREFIX = 2; 25 const uint8_t LABEL_FRAGMENT = 5; // See kernel struct DmElementContentType 26 27 struct ID { IDID28 ID(const std::string deviceId, uint64_t clock) 29 { 30 this->deviceId = deviceId; 31 this->clock = clock; 32 } 33 std::string deviceId; 34 uint64_t clock; 35 }; 36 37 class RdAdapter { 38 public: 39 RdAdapter(); 40 ~RdAdapter(); 41 void SetDBStore(std::shared_ptr<DBStore> dbStore); 42 std::shared_ptr<DBStore> GetDBStore(); 43 void SetTableName(std::string name); 44 std::string GetTableName(); 45 void SetID(std::optional<ID> id); 46 std::optional<ID> GetID(); 47 48 std::pair<int32_t, std::optional<ID>> InsertNode(uint32_t index, std::string nodeName); 49 std::pair<int32_t, std::optional<ID>> InsertText(uint32_t index); 50 int32_t DeleteChildren(uint32_t index, uint32_t length); 51 std::pair<int32_t, std::string> GetChildren(uint32_t index, uint32_t length); 52 std::pair<int32_t, std::string> GetJsonString(); 53 int32_t SetAttribute(const std::string &attributeName, const std::string &attributeValue, uint32_t flags); 54 int32_t RemoveAttrribute(const std::string &attributeName); 55 std::pair<int32_t, std::string> GetAttributes(); 56 57 int32_t TextInsert(uint32_t index, const std::string &content, const std::string &formatStr); 58 int32_t TextDelete(uint32_t index, uint32_t length); 59 int32_t TextFormat(uint32_t index, uint32_t length, const std::string &formatStr); 60 std::pair<int32_t, uint32_t> GetTextLength(); 61 std::pair<int32_t, std::string> ReadDeltaText(const std::string &snapshot, const std::string &snapshotPerv); 62 std::pair<int32_t, std::string> ReadStringText(); 63 64 int32_t CreateUndoManager(uint64_t captureTimeout); 65 int32_t CloseUndoManager(); 66 int32_t Undo(); 67 int32_t Redo(); 68 69 private: 70 std::shared_ptr<DBStore> dbStore_; 71 std::string tableName_; 72 std::optional<ID> id_; 73 }; 74 } // namespace OHOS::CollaborationEdit 75 #endif // COLLABORATION_EDIT_RD_ADAPTER_H 76