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 16 #ifndef KV_DB_PRAGMA_H 17 #define KV_DB_PRAGMA_H 18 19 #include <vector> 20 #include <string> 21 #include <functional> 22 23 #include "store_types.h" 24 #include "query_sync_object.h" 25 26 namespace DistributedDB { 27 enum : int { 28 PRAGMA_AUTO_SYNC = 1, 29 PRAGMA_SYNC_DEVICES, 30 PRAGMA_RM_DEVICE_DATA, // remove the device data synced from remote by device name 31 PRAGMA_PERFORMANCE_ANALYSIS_GET_REPORT, 32 PRAGMA_PERFORMANCE_ANALYSIS_OPEN, 33 PRAGMA_PERFORMANCE_ANALYSIS_CLOSE, 34 PRAGMA_PERFORMANCE_ANALYSIS_SET_REPORTFILENAME, 35 PRAGMA_GET_IDENTIFIER_OF_DEVICE, 36 PRAGMA_GET_DEVICE_IDENTIFIER_OF_ENTRY, 37 PRAGMA_GET_QUEUED_SYNC_SIZE, 38 PRAGMA_SET_QUEUED_SYNC_LIMIT, 39 PRAGMA_GET_QUEUED_SYNC_LIMIT, 40 PRAGMA_SET_WIPE_POLICY, 41 PRAGMA_PUBLISH_LOCAL, 42 PRAGMA_UNPUBLISH_SYNC, 43 PRAGMA_SET_AUTO_LIFE_CYCLE, 44 PRAGMA_RESULT_SET_CACHE_MODE, 45 PRAGMA_RESULT_SET_CACHE_MAX_SIZE, 46 PRAGMA_TRIGGER_TO_MIGRATE_DATA, 47 PRAGMA_REMOTE_PUSH_FINISHED_NOTIFY, 48 PRAGMA_SET_SYNC_RETRY, 49 PRAGMA_ADD_EQUAL_IDENTIFIER, 50 PRAGMA_INTERCEPT_SYNC_DATA, 51 PRAGMA_SUBSCRIBE_QUERY, 52 PRAGMA_SET_MAX_LOG_LIMIT, 53 PRAGMA_EXEC_CHECKPOINT, 54 PRAGMA_CANCEL_SYNC_DEVICES, 55 PRAGMA_SET_MAX_VALUE_SIZE, 56 }; 57 58 struct PragmaSync { 59 PragmaSync(const std::vector<std::string> &devices, int mode, const QuerySyncObject &query, 60 const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, 61 bool wait = false) devices_PragmaSync62 : devices_(devices), 63 mode_(mode), 64 onComplete_(onComplete), 65 wait_(wait), 66 isQuerySync_(true), 67 query_(query) 68 { 69 } 70 71 PragmaSync(const std::vector<std::string> &devices, int mode, 72 const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, 73 bool wait = false) devices_PragmaSync74 : devices_(devices), 75 mode_(mode), 76 onComplete_(onComplete), 77 wait_(wait), 78 isQuerySync_(false), 79 query_(Query::Select()) 80 { 81 } 82 PragmaSyncPragmaSync83 PragmaSync(const DeviceSyncOption &option, const QuerySyncObject &query, const DeviceSyncProcessCallback &onProcess) 84 : devices_(option.devices), 85 mode_(option.mode), 86 wait_(option.isWait), 87 isQuerySync_(option.isQuery), 88 onSyncProcess_(onProcess) 89 { 90 if (!isQuerySync_) { 91 return; 92 } 93 query_ = query; 94 } 95 PragmaSyncPragmaSync96 PragmaSync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess) 97 :devices_(option.devices), 98 mode_(option.mode), 99 wait_(option.isWait), 100 isQuerySync_(false), 101 query_(Query::Select()), 102 onSyncProcess_(onProcess) 103 { 104 } 105 106 std::vector<std::string> devices_; 107 int mode_; 108 std::function<void(const std::map<std::string, int> &devicesMap)> onComplete_; 109 bool wait_; 110 bool isQuerySync_; 111 QuerySyncObject query_; 112 DeviceSyncProcessCallback onSyncProcess_; 113 }; 114 115 struct PragmaRemotePushNotify { PragmaRemotePushNotifyPragmaRemotePushNotify116 explicit PragmaRemotePushNotify(RemotePushFinishedNotifier notifier) : notifier_(notifier) {} 117 118 RemotePushFinishedNotifier notifier_; 119 }; 120 121 struct PragmaSetEqualIdentifier { PragmaSetEqualIdentifierPragmaSetEqualIdentifier122 PragmaSetEqualIdentifier(const std::string &identifier, const std::vector<std::string> &targets) 123 : identifier_(identifier), 124 targets_(targets) {} 125 126 std::string identifier_; 127 std::vector<std::string> targets_; 128 }; 129 } // namespace DistributedDB 130 131 #endif // KV_DB_PRAGMA_H 132