1 /* 2 * Copyright (c) 2022 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 "security_collector_subscribe_info.h" 17 18 #include "security_collector_define.h" 19 #include "security_collector_log.h" 20 21 namespace OHOS::Security::SecurityCollector { 22 namespace { 23 } 24 Marshalling(Parcel & parcel) const25bool SecurityCollectorSubscribeInfo::Marshalling(Parcel &parcel) const 26 { 27 if (!parcel.WriteInt64(duration_)) { 28 LOGE("failed to write duration_"); 29 return false; 30 } 31 if (!parcel.WriteBool(isNotify_)) { 32 LOGE("failed to write isNotify_"); 33 return false; 34 } 35 36 if (!parcel.WriteInt64(event_.eventId)) { 37 LOGE("failed to write eventId"); 38 return false; 39 } 40 if (!parcel.WriteString(event_.version)) { 41 LOGE("failed to write version"); 42 return false; 43 } 44 if (!parcel.WriteString(event_.content)) { 45 LOGE("failed to write content"); 46 return false; 47 } 48 if (!parcel.WriteString(event_.extra)) { 49 LOGE("failed to write extra"); 50 return false; 51 } 52 53 return true; 54 } 55 ReadFromParcel(Parcel & parcel)56bool SecurityCollectorSubscribeInfo::ReadFromParcel(Parcel &parcel) 57 { 58 if (!parcel.ReadInt64(duration_)) { 59 LOGE("failed to read duration_"); 60 return false; 61 } 62 if (!parcel.ReadBool(isNotify_)) { 63 LOGE("failed to read isNotify_"); 64 return false; 65 } 66 67 if (!parcel.ReadInt64(event_.eventId)) { 68 LOGE("failed to read .eventId"); 69 return false; 70 } 71 if (!parcel.ReadString(event_.version)) { 72 LOGE("failed to read version"); 73 return false; 74 } 75 if (!parcel.ReadString(event_.content)) { 76 LOGE("failed to read content"); 77 return false; 78 } 79 if (!parcel.ReadString(event_.extra)) { 80 LOGE("failed to read extra"); 81 return false; 82 } 83 84 return true; 85 } 86 Unmarshalling(Parcel & parcel)87SecurityCollectorSubscribeInfo *SecurityCollectorSubscribeInfo::Unmarshalling(Parcel &parcel) 88 { 89 SecurityCollectorSubscribeInfo *subscribeInfo = new (std::nothrow) SecurityCollectorSubscribeInfo(); 90 91 if (subscribeInfo && !subscribeInfo->ReadFromParcel(parcel)) { 92 LOGE("failed to read from parcel"); 93 delete subscribeInfo; 94 subscribeInfo = nullptr; 95 } 96 97 return subscribeInfo; 98 } 99 }