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 CHANGE_NOTIFICATION_H 17 #define CHANGE_NOTIFICATION_H 18 19 #include <list> 20 #include "types.h" 21 #include "parcel.h" 22 23 namespace OHOS { 24 namespace DistributedKv { 25 class ChangeNotification final : public virtual Parcelable { 26 public: 27 // Constructor of ChangeNotification. 28 ChangeNotification(std::vector<Entry> &&insertEntries, 29 std::vector<Entry> &&updateEntries, 30 std::vector<Entry> &&deleteEntries, 31 const std::string &deviceId, 32 bool isClear); 33 34 KVSTORE_API ~ChangeNotification(); 35 36 // Get all inserted entries in this change. 37 KVSTORE_API const std::vector<Entry> &GetInsertEntries() const; 38 39 // Get all updated entries in this changing. 40 KVSTORE_API const std::vector<Entry> &GetUpdateEntries() const; 41 42 // Get all deleted entries in this changing. 43 KVSTORE_API const std::vector<Entry> &GetDeleteEntries() const; 44 45 // Get the device ID. 46 KVSTORE_API const std::string &GetDeviceId() const; 47 48 // Check if this change is made by calling the Clear function. 49 KVSTORE_API bool IsClear() const; 50 51 // Write a parcelable object to the given parcel. 52 // The object position is saved into Parcel if asRemote_ is set to 53 // true, and this intends to use in kernel data transaction. 54 // Returns true if the writing is successful; returns false otherwise. 55 KVSTORE_API bool Marshalling(Parcel &parcel) const override; 56 57 // Unmarshall the given parcel from this parcelable object. 58 KVSTORE_API static ChangeNotification *Unmarshalling(Parcel &parcel); 59 private: 60 std::vector<Entry> insertEntries_; 61 62 std::vector<Entry> updateEntries_; 63 64 std::vector<Entry> deleteEntries_; 65 66 std::string deviceId_; 67 68 bool isClear_ = false; 69 }; 70 } // namespace DistributedKv 71 } // namespace OHOS 72 #endif // CHANGE_NOTIFICATION_H 73