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 #include "profile_change_notification.h"
17
18 #include "parcel_helper.h"
19
20 namespace OHOS {
21 namespace DeviceProfile {
22 namespace {
23 const std::string TAG = "ProfileChangeNotification";
24 }
25
GetProfileEntries() const26 const std::vector<ProfileEntry>& ProfileChangeNotification::GetProfileEntries() const
27 {
28 return profileEntries_;
29 }
30
GetDeviceId() const31 const std::string& ProfileChangeNotification::GetDeviceId() const
32 {
33 return deviceId_;
34 }
35
IsLocal() const36 bool ProfileChangeNotification::IsLocal() const
37 {
38 return isLocal_;
39 }
40
Marshalling(Parcel & parcel) const41 bool ProfileChangeNotification::Marshalling(Parcel& parcel) const
42 {
43 int32_t entrySize = static_cast<int32_t>(profileEntries_.size());
44 PARCEL_WRITE_HELPER_RET(parcel, Int32, entrySize, false);
45 for (const auto& profileEntry : profileEntries_) {
46 if (!profileEntry.Marshalling(parcel)) {
47 return false;
48 }
49 }
50 PARCEL_WRITE_HELPER_RET(parcel, String, deviceId_, false);
51
52 return true;
53 }
54
Unmarshalling(Parcel & parcel)55 bool ProfileChangeNotification::Unmarshalling(Parcel& parcel)
56 {
57 int32_t entrySize = parcel.ReadInt32();
58 if (entrySize < 0) {
59 HILOGE("invalid entrySize = %{public}d", entrySize);
60 return false;
61 }
62 profileEntries_.reserve(entrySize);
63 for (int32_t i = 0; i < entrySize; i++) {
64 ProfileEntry profileEntry;
65 if (!profileEntry.Unmarshalling(parcel)) {
66 return false;
67 }
68 profileEntries_.emplace_back(std::move(profileEntry));
69 }
70 PARCEL_READ_HELPER_RET(parcel, String, deviceId_, false);
71 return true;
72 }
73
Marshalling(Parcel & parcel) const74 bool ProfileEntry::Marshalling(Parcel& parcel) const
75 {
76 PARCEL_WRITE_HELPER_RET(parcel, String, key, false);
77 PARCEL_WRITE_HELPER_RET(parcel, String, value, false);
78 PARCEL_WRITE_HELPER_RET(parcel, Uint8, changeType, false);
79 return true;
80 }
81
Unmarshalling(Parcel & parcel)82 bool ProfileEntry::Unmarshalling(Parcel& parcel)
83 {
84 PARCEL_READ_HELPER_RET(parcel, String, key, false);
85 PARCEL_READ_HELPER_RET(parcel, String, value, false);
86 uint8_t type = 0;
87 PARCEL_READ_HELPER_RET(parcel, Uint8, type, false);
88 changeType = static_cast<ProfileChangeType>(type);
89 return true;
90 }
91 } // namespace DeviceProfile
92 } // namespace OHOS
93