• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &processMap,
44         const DeviceSyncProcessCallback &onProcess) const;
45     virtual int Sync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess);
46     virtual int Sync(SyncMode mode, bool wait);
47     virtual int Sync(SyncMode mode, const Query &query, bool wait);
48     virtual int Sync(SyncMode mode, const Query &query, const SyncOperation::UserCallback &callBack, bool wait);
49     virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition,
50         uint64_t timeout, std::shared_ptr<ResultSet> &result);
51     void SetClearRemoteStaleData(bool isStaleData);
52 protected:
53     ICommunicator *communicateHandle_;
54     VirtualCommunicatorAggregator *communicatorAggregator_;
55     ISyncInterface *storage_;
56     std::shared_ptr<Metadata> metadata_;
57     std::string deviceId_;
58     std::string remoteDeviceId_;
59     std::string targetUserId_;
60     SyncTaskContext *context_;
61     std::function<void(const std::string &)> onRemoteDataChanged_;
62 
63     std::shared_ptr<SubscribeManager> subManager_;
64     RemoteExecutor *executor_;
65 };
66 }
67 #endif // GENERIC_VIRTUAL_DEVICE_H
68