• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) const25 bool 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     if (!parcel.WriteString(eventGroup_)) {
53         LOGE("failed to write event group");
54         return false;
55     }
56     return true;
57 }
58 
ReadFromParcel(Parcel & parcel)59 bool SecurityCollectorSubscribeInfo::ReadFromParcel(Parcel &parcel)
60 {
61     if (!parcel.ReadInt64(duration_)) {
62         LOGE("failed to read duration_");
63         return false;
64     }
65     if (!parcel.ReadBool(isNotify_)) {
66         LOGE("failed to read isNotify_");
67         return false;
68     }
69 
70     if (!parcel.ReadInt64(event_.eventId)) {
71         LOGE("failed to read .eventId");
72         return false;
73     }
74     if (!parcel.ReadString(event_.version)) {
75         LOGE("failed to read version");
76         return false;
77     }
78     if (!parcel.ReadString(event_.content)) {
79         LOGE("failed to read content");
80         return false;
81     }
82     if (!parcel.ReadString(event_.extra)) {
83         LOGE("failed to read extra");
84         return false;
85     }
86     if (!parcel.ReadString(eventGroup_)) {
87         LOGE("failed to read event group");
88         return false;
89     }
90     return true;
91 }
92 
Unmarshalling(Parcel & parcel)93 SecurityCollectorSubscribeInfo *SecurityCollectorSubscribeInfo::Unmarshalling(Parcel &parcel)
94 {
95     SecurityCollectorSubscribeInfo *subscribeInfo = new (std::nothrow) SecurityCollectorSubscribeInfo();
96 
97     if (subscribeInfo && !subscribeInfo->ReadFromParcel(parcel)) {
98         LOGE("failed to read from parcel");
99         delete subscribeInfo;
100         subscribeInfo = nullptr;
101     }
102 
103     return subscribeInfo;
104 }
105 }