• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "process_info.h"
17 
18 #include "hilog_wrapper.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
ProcessInfo(const std::string & name,const pid_t & pid)23 ProcessInfo::ProcessInfo(const std::string &name, const pid_t &pid) : processName_(name), pid_(pid)
24 {}
25 
26 /**
27  * @brief read this Sequenceable object from a Parcel.
28  *
29  * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled.
30  * @return Returns true if read successed; returns false otherwise.
31  */
ReadFromParcel(Parcel & parcel)32 bool ProcessInfo::ReadFromParcel(Parcel &parcel)
33 {
34     processName_ = Str16ToStr8(parcel.ReadString16());
35     pid_ = parcel.ReadInt32();
36     return true;
37 }
38 
39 /**
40  * @brief Unmarshals this Sequenceable object from a Parcel.
41  *
42  * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled.
43  */
Unmarshalling(Parcel & parcel)44 ProcessInfo *ProcessInfo::Unmarshalling(Parcel &parcel)
45 {
46     ProcessInfo *processInfo = new (std::nothrow) ProcessInfo();
47     if (processInfo && !processInfo->ReadFromParcel(parcel)) {
48         HILOG_ERROR("ProcessInfo::Unmarshalling ReadFromParcel failed");
49         delete processInfo;
50         processInfo = nullptr;
51     }
52     return processInfo;
53 }
54 
55 /**
56  * @brief Marshals this Sequenceable object into a Parcel.
57  *
58  * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled.
59  */
Marshalling(Parcel & parcel) const60 bool ProcessInfo::Marshalling(Parcel &parcel) const
61 {
62     return (parcel.WriteString16(Str8ToStr16(processName_)) && parcel.WriteInt32(pid_));
63 }
64 }  // namespace AppExecFwk
65 }  // namespace OHOS
66