1 /* 2 * Copyright (c) 2021 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 #ifndef OHOS_ABILITY_RUNTIME_PROCESS_INFO_H 17 #define OHOS_ABILITY_RUNTIME_PROCESS_INFO_H 18 19 #include <string> 20 #include <unistd.h> 21 22 #include "nocopyable.h" 23 #include "parcel.h" 24 #include "app_mgr_constants.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 class ProcessInfo : public Parcelable { 29 public: 30 ProcessInfo() = default; 31 explicit ProcessInfo(const std::string &name, const pid_t &pid); 32 virtual ~ProcessInfo() = default; 33 34 /** 35 * @brief Obtains the name of the current process. 36 * 37 * @return Returns the current process name. 38 */ GetProcessName()39 inline const std::string &GetProcessName() const 40 { 41 return processName_; 42 } 43 44 /** 45 * @brief Obtains the id of the current process. 46 * 47 * @return Returns the current process id. 48 */ GetPid()49 inline pid_t GetPid() const 50 { 51 return pid_; 52 } 53 54 /** 55 * @brief read this Sequenceable object from a Parcel. 56 * 57 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 58 * @return Returns true if read successed; returns false otherwise. 59 */ 60 bool ReadFromParcel(Parcel &parcel); 61 62 /** 63 * @brief Marshals this Sequenceable object into a Parcel. 64 * 65 * @param outParcel Indicates the Parcel object to which the Sequenceable object will be marshaled. 66 */ 67 virtual bool Marshalling(Parcel &parcel) const override; 68 69 /** 70 * @brief Unmarshals this Sequenceable object from a Parcel. 71 * 72 * @param inParcel Indicates the Parcel object into which the Sequenceable object has been marshaled. 73 */ 74 static ProcessInfo *Unmarshalling(Parcel &parcel); 75 76 /** 77 * @brief Set process type 78 * 79 * @param ProcessType process type. 80 */ 81 void SetProcessType(const ProcessType &processType); 82 83 /** 84 * @brief Obtains type of the process. 85 * 86 * @return Returns process type. 87 */ 88 ProcessType GetProcessType() const; 89 90 private: 91 std::string processName_; 92 pid_t pid_ = 0; 93 ProcessType processType_ = ProcessType::NORMAL; 94 }; 95 } // namespace AppExecFwk 96 } // namespace OHOS 97 #endif // OHOS_ABILITY_RUNTIME_PROCESS_INFO_H 98