1 /* 2 * Copyright (c) 2021 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 #ifndef GENERIC_VIRTUAL_DEVICE_H 16 #define GENERIC_VIRTUAL_DEVICE_H 17 18 #include <string> 19 20 #include "ikvdb_sync_interface.h" 21 #include "meta_data.h" 22 #include "remote_executor.h" 23 #include "subscribe_manager.h" 24 #include "sync_task_context.h" 25 #include "store_types.h" 26 #include "virtual_communicator_aggregator.h" 27 28 namespace DistributedDB { 29 class GenericVirtualDevice { 30 public: 31 explicit GenericVirtualDevice(std::string deviceId); 32 virtual ~GenericVirtualDevice(); 33 34 int Initialize(VirtualCommunicatorAggregator *comAggregator, ISyncInterface *syncInterface); 35 void SetDeviceId(const std::string &deviceId); 36 std::string GetDeviceId() const; 37 int MessageCallback(const std::string &deviceId, Message *inMsg); 38 void OnRemoteDataChanged(const std::function<void(const std::string &)> &callback); 39 void Online(); 40 void Offline(); 41 int StartResponseTask(); 42 TimeOffset GetLocalTimeOffset() const; 43 virtual int Sync(SyncMode mode, bool wait); 44 virtual int Sync(SyncMode mode, const Query &query, bool wait); 45 virtual int Sync(SyncMode mode, const Query &query, const SyncOperation::UserCallback &callBack, bool wait); 46 virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition, 47 uint64_t timeout, std::shared_ptr<ResultSet> &result); 48 void SetClearRemoteStaleData(bool isStaleData); 49 protected: 50 ICommunicator *communicateHandle_; 51 VirtualCommunicatorAggregator *communicatorAggregator_; 52 ISyncInterface *storage_; 53 std::shared_ptr<Metadata> metadata_; 54 std::string deviceId_; 55 std::string remoteDeviceId_; 56 SyncTaskContext *context_; 57 std::function<void(const std::string &)> onRemoteDataChanged_; 58 59 std::shared_ptr<SubscribeManager> subManager_; 60 RemoteExecutor *executor_; 61 }; 62 } 63 #endif // GENERIC_VIRTUAL_DEVICE_H 64