• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "subscribe_info.h"
17 
18 #include "device_profile_log.h"
19 #include "parcel_helper.h"
20 
21 namespace OHOS {
22 namespace DeviceProfile {
23 namespace {
24 const std::string TAG = "SubscribeInfo";
25 }
26 
Marshalling(Parcel & parcel) const27 bool SubscribeInfo::Marshalling(Parcel& parcel) const
28 {
29     PARCEL_WRITE_HELPER_RET(parcel, Uint32, profileEvent, false);
30     PARCEL_WRITE_HELPER_RET(parcel, String, extraInfo.dump(), false);
31     return true;
32 }
33 
Unmarshalling(Parcel & parcel)34 bool SubscribeInfo::Unmarshalling(Parcel& parcel)
35 {
36     profileEvent = static_cast<ProfileEvent>(parcel.ReadUint32());
37     if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) {
38         HILOGE("invalid profile event, %{public}d", profileEvent);
39         return false;
40     }
41     std::string value = parcel.ReadString();
42     extraInfo = ExtraInfo::parse(value, nullptr, false);
43     if (extraInfo.is_discarded()) {
44         HILOGE("parse extra info failed, %{public}s", value.c_str());
45         return false;
46     }
47     return true;
48 }
49 
operator !=(const SubscribeInfo & rhs) const50 bool SubscribeInfo::operator!=(const SubscribeInfo& rhs) const
51 {
52     return ((profileEvent != rhs.profileEvent) || (extraInfo != rhs.extraInfo));
53 }
54 } // namespace DeviceProfile
55 } // namespace OHOS