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 OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H
17 #define OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H
18 
19 #include <vector>
20 #include <map>
21 
22 #include "parcel.h"
23 
24 namespace OHOS {
25 namespace DeviceProfile {
26 enum class ProfileChangeType : uint8_t {
27     UNKNOWN_CHANGE_TYPE = 0,
28     INSERTED = 1,
29     UPDATED = 2,
30     DELETED = 3
31 };
32 
33 using Service2Index = std::map<std::string, uint32_t>;
34 
35 struct ProfileEntry {
36     template<typename T>
ProfileEntryProfileEntry37     ProfileEntry(T&& k, T&& val, ProfileChangeType type)
38         : key(std::forward<T>(k)), value(std::forward<T>(val)), changeType(type) {}
ProfileEntryProfileEntry39     ProfileEntry() {}
40     ~ProfileEntry() = default;
41 
42     bool Marshalling(Parcel& parcel) const;
43     bool Unmarshalling(Parcel& parcel);
44 
45     std::string key;
46     std::string value;
47     ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE};
48 };
49 
50 class ProfileChangeNotification : public Parcelable {
51 public:
ProfileChangeNotification(std::vector<ProfileEntry> & profileEntries,std::string & networkId,bool isLocal)52     ProfileChangeNotification(std::vector<ProfileEntry>& profileEntries,
53         std::string& networkId, bool isLocal)
54         : profileEntries_(std::move(profileEntries)),
55           deviceId_(std::move(networkId)), isLocal_(isLocal) {}
ProfileChangeNotification()56     ProfileChangeNotification() {}
57     ~ProfileChangeNotification() = default;
58 
59     const std::vector<ProfileEntry>& GetProfileEntries() const;
60     const std::string& GetDeviceId() const;
61     bool IsLocal() const;
62 
63     bool Marshalling(Parcel& parcel) const override;
64     bool Unmarshalling(Parcel& parcel);
65 
66 private:
67     std::vector<ProfileEntry> profileEntries_;
68     std::string deviceId_;
69     bool isLocal_ {false};
70 };
71 }  // namespace DeviceProfile
72 }  // namespace OHOS
73 #endif  // OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H
74