1 /* 2 * Copyright (c) 2025 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_SYNC_SERVICE_H 17 #define GRD_SYNC_SERVICE_H 18 19 #include <atomic> 20 #include <memory> 21 #include <mutex> 22 23 #include "db_store.h" 24 #include "napi_async_call.h" 25 26 namespace OHOS::CollaborationEdit { 27 class SyncService { 28 public: 29 SyncService& operator=(SyncService const&) = delete; 30 31 static std::shared_ptr<SyncService> GetInstance(); 32 uint64_t GetSyncId(); 33 std::shared_ptr<SyncContext> GetSyncContext(uint64_t syncId); 34 void AddSyncContext(uint64_t syncId, std::shared_ptr<SyncContext> syncContext); 35 void RemoveSyncContext(uint64_t syncId); 36 private: 37 std::atomic<uint64_t> syncId_{}; 38 std::mutex contextMutex_; 39 std::map<uint64_t, std::shared_ptr<SyncContext>> syncContextMap_; 40 }; 41 42 } // namespace OHOS::CollaborationEdit 43 #endif // GRD_SYNC_SERVICE_H 44