1 /*
2 * Copyright (c) 2025 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 "process_memory_state.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "parcel_macro_base.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
23
ReadFromParcel(Parcel & parcel)24 bool ProcessMemoryState::ReadFromParcel(Parcel &parcel)
25 {
26 int32_t pidData;
27 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pidData);
28 pid = static_cast<int32_t>(pidData);
29 int32_t rssValueData;
30 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rssValueData);
31 rssValue = static_cast<int32_t>(rssValueData);
32 int32_t pssValueData;
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pssValueData);
34 pssValue = static_cast<int32_t>(pssValueData);
35 return true;
36 }
37
Unmarshalling(Parcel & parcel)38 ProcessMemoryState *ProcessMemoryState::Unmarshalling(Parcel &parcel)
39 {
40 ProcessMemoryState *state = new (std::nothrow) ProcessMemoryState();
41 if (state && !state->ReadFromParcel(parcel)) {
42 TAG_LOGW(AAFwkTag::APPMGR, "read from parcel failed");
43 delete state;
44 state = nullptr;
45 }
46 return state;
47 }
48
Marshalling(Parcel & parcel) const49 bool ProcessMemoryState::Marshalling(Parcel &parcel) const
50 {
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pid));
52 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(rssValue));
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pssValue));
54 return true;
55 }
56 } // namespace AppExecFwk
57 } // namespace OHOS
58