1 /* 2 * Copyright (c) 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 DATASHARE_OBSERVER_H 17 #define DATASHARE_OBSERVER_H 18 19 #include <list> 20 #include <map> 21 #include <string> 22 23 #include "uri.h" 24 25 namespace OHOS::DataShare { 26 class DataShareObserver { 27 public: 28 DataShareObserver() = default; 29 virtual ~DataShareObserver() = default; 30 enum SubscriptionType : uint32_t { 31 SUBSCRIPTION_TYPE_EXACT_URI = 0, 32 }; 33 enum ChangeType : uint32_t { 34 INSERT = 0, 35 DELETE, 36 UPDATE, 37 OTHER, 38 INVAILD, 39 }; 40 41 struct ChangeInfo { 42 using Value = std::variant<std::monostate, int64_t, double, std::string, bool, std::vector<uint8_t>>; 43 using VBucket = std::map<std::string, Value>; 44 using VBuckets = std::vector<VBucket>; 45 ChangeType changeType_ = INVAILD; 46 std::list<Uri> uris_ = {}; 47 const void* data_ = nullptr; 48 uint32_t size_ = 0; 49 VBuckets valueBuckets_ = {}; 50 }; 51 52 virtual void OnChange(const ChangeInfo& changeInfo) = 0; 53 }; 54 } 55 #endif // DATASHARE_OBSERVER_H 56