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 POWERMGR_WORKTRIGGER_H 17 #define POWERMGR_WORKTRIGGER_H 18 19 #include <string> 20 #include <list> 21 22 #include <parcel.h> 23 24 namespace OHOS { 25 namespace PowerMgr { 26 constexpr int32_t INVALID_PID = -1; 27 constexpr int32_t INVALID_UID = -1; 28 29 class WorkTrigger : public Parcelable { 30 public: 31 WorkTrigger() = default; 32 WorkTrigger(int32_t uid, const std::string& name = "", int32_t pid = 0) uid_(uid)33 : uid_(uid), name_(name), pid_(pid) {} 34 ~WorkTrigger() = default; 35 SetAbilityId(int32_t abilityId)36 void SetAbilityId(int32_t abilityId) 37 { 38 abilityId_ = abilityId; 39 } 40 SetPid(int32_t pid)41 void SetPid(int32_t pid) 42 { 43 pid_ = pid; 44 } 45 GetAbilityId()46 int32_t GetAbilityId() const 47 { 48 return abilityId_; 49 } 50 GetPid()51 int32_t GetPid() const 52 { 53 return pid_; 54 } 55 GetUid()56 int32_t GetUid() const 57 { 58 return uid_; 59 } 60 GetName()61 const std::string& GetName() const 62 { 63 return name_; 64 } 65 66 bool operator==(const WorkTrigger& other) const 67 { 68 return (uid_ == other.uid_) && (pid_ == other.pid_) && (abilityId_ == other.abilityId_) && 69 (name_.compare(other.name_) == 0); 70 } 71 72 bool ReadFromParcel(Parcel& parcel); 73 bool Marshalling(Parcel& parcel) const override; 74 static WorkTrigger* Unmarshalling(Parcel& parcel); 75 76 private: 77 int32_t uid_{INVALID_UID}; 78 std::string name_; 79 int32_t pid_{INVALID_PID}; 80 int32_t abilityId_ {0}; 81 }; 82 } // namespace PowerMgr 83 } // namespace OHOS 84 #endif // POWERMGR_WORKTRIGGER_H 85