1 /* 2 * Copyright (c) 2023-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 OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_WATCHER_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_WATCHER_H 18 #include <cstdint> 19 20 #include "store/general_value.h" 21 #include "visibility.h" 22 namespace OHOS::DistributedData { 23 class GeneralWatcher { 24 public: 25 struct Origin { 26 enum OriginType : int32_t { 27 ORIGIN_LOCAL, 28 ORIGIN_NEARBY, 29 ORIGIN_CLOUD, 30 ORIGIN_ALL, 31 ORIGIN_BUTT, 32 }; 33 enum DataType : int32_t { 34 BASIC_DATA, 35 ASSET_DATA, 36 TYPE_BUTT, 37 }; 38 int32_t origin = ORIGIN_BUTT; 39 int32_t dataType = BASIC_DATA; 40 // origin is ORIGIN_LOCAL, the id is empty 41 // origin is ORIGIN_NEARBY, the id is networkId; 42 // origin is ORIGIN_CLOUD, the id is the cloud account id 43 std::vector<std::string> id; 44 std::string store; 45 }; 46 enum ChangeOp : int32_t { 47 OP_INSERT, 48 OP_UPDATE, 49 OP_DELETE, 50 OP_BUTT, 51 }; 52 // PK primary key 53 using PRIValue = std::variant<std::monostate, std::string, int64_t, double>; 54 using PRIFields = std::map<std::string, std::string>; 55 using Fields = std::map<std::string, std::vector<std::string>>; 56 using ChangeInfo = std::map<std::string, std::vector<PRIValue>[OP_BUTT]>; 57 using ChangeData = std::map<std::string, std::vector<Values>[OP_BUTT]>; 58 virtual ~GeneralWatcher() = default; 59 virtual int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) = 0; 60 virtual int32_t OnChange(const Origin &origin, const Fields &fields, ChangeData &&datas) = 0; 61 }; 62 } // namespace OHOS::DistributedData 63 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_WATCHER_H 64