1 /*
2 * Copyright (c) 2024 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 "render_state_data.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "parcel_macro_base.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
Marshalling(Parcel & parcel) const23 bool RenderStateData::Marshalling(Parcel &parcel) const
24 {
25 return (parcel.WriteInt32(pid) && parcel.WriteInt32(uid) && parcel.WriteInt32(hostPid) &&
26 parcel.WriteInt32(hostUid) && parcel.WriteInt32(state));
27 }
28
ReadFromParcel(Parcel & parcel)29 bool RenderStateData::ReadFromParcel(Parcel &parcel)
30 {
31 if (!parcel.ReadInt32(pid)) {
32 TAG_LOGE(AAFwkTag::APPMGR, "pid read failed.");
33 return false;
34 }
35 if (!parcel.ReadInt32(uid)) {
36 TAG_LOGE(AAFwkTag::APPMGR, "uid read failed.");
37 return false;
38 }
39 if (!parcel.ReadInt32(hostPid)) {
40 TAG_LOGE(AAFwkTag::APPMGR, "hostPid read failed.");
41 return false;
42 }
43 if (!parcel.ReadInt32(hostUid)) {
44 TAG_LOGE(AAFwkTag::APPMGR, "hostUid read failed.");
45 return false;
46 }
47 if (!parcel.ReadInt32(state)) {
48 TAG_LOGE(AAFwkTag::APPMGR, "state read failed.");
49 return false;
50 }
51 return true;
52 };
53
Unmarshalling(Parcel & parcel)54 RenderStateData *RenderStateData::Unmarshalling(Parcel &parcel)
55 {
56 RenderStateData *renderStateData = new (std::nothrow) RenderStateData();
57 if (renderStateData && !renderStateData->ReadFromParcel(parcel)) {
58 TAG_LOGW(AAFwkTag::APPMGR, "renderStateData failed, because ReadFromParcel failed");
59 delete renderStateData;
60 renderStateData = nullptr;
61 }
62 return renderStateData;
63 }
64 }
65 }