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 #include "pending_want_key.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
SetType(const int32_t type)20 void PendingWantKey::SetType(const int32_t type)
21 {
22     type_ = type;
23 }
24 
SetBundleName(const std::string & bundleName)25 void PendingWantKey::SetBundleName(const std::string &bundleName)
26 {
27     bundleName_ = bundleName;
28 }
29 
SetRequestWho(const std::string & requestWho)30 void PendingWantKey::SetRequestWho(const std::string &requestWho)
31 {
32     requestWho_ = requestWho;
33 }
34 
SetRequestCode(int32_t requestCode)35 void PendingWantKey::SetRequestCode(int32_t requestCode)
36 {
37     requestCode_ = requestCode;
38 }
39 
SetRequestWant(const Want & requestWant)40 void PendingWantKey::SetRequestWant(const Want &requestWant)
41 {
42     std::lock_guard<std::mutex> lock(requestWantMutex_);
43     requestWant_ = requestWant;
44 }
45 
SetRequestResolvedType(const std::string & requestResolvedType)46 void PendingWantKey::SetRequestResolvedType(const std::string &requestResolvedType)
47 {
48     requestResolvedType_ = requestResolvedType;
49 }
50 
SetAllWantsInfos(const std::vector<WantsInfo> & allWantsInfos)51 void PendingWantKey::SetAllWantsInfos(const std::vector<WantsInfo> &allWantsInfos)
52 {
53     std::lock_guard<std::mutex> lock(wantsInfosMutex_);
54     allWantsInfos_ = allWantsInfos;
55 }
56 
SetFlags(int32_t flags)57 void PendingWantKey::SetFlags(int32_t flags)
58 {
59     flags_ = flags;
60 }
61 
SetCode(int32_t code)62 void PendingWantKey::SetCode(int32_t code)
63 {
64     code_ = code;
65 }
66 
SetUserId(int32_t userId)67 void PendingWantKey::SetUserId(int32_t userId)
68 {
69     userId_ = userId;
70 }
71 
SetAppIndex(int32_t appIndex)72 void PendingWantKey::SetAppIndex(int32_t appIndex)
73 {
74     appIndex_ = appIndex;
75 }
76 
GetType()77 int32_t PendingWantKey::GetType()
78 {
79     return type_;
80 }
81 
GetBundleName()82 std::string PendingWantKey::GetBundleName()
83 {
84     return bundleName_;
85 }
86 
GetRequestWho()87 std::string PendingWantKey::GetRequestWho()
88 {
89     return requestWho_;
90 }
91 
GetRequestCode()92 int32_t PendingWantKey::GetRequestCode()
93 {
94     return requestCode_;
95 }
96 
GetRequestWant()97 Want PendingWantKey::GetRequestWant()
98 {
99     std::lock_guard<std::mutex> lock(requestWantMutex_);
100     return requestWant_;
101 }
102 
GetRequestWantRef()103 Want& PendingWantKey::GetRequestWantRef()
104 {
105     std::lock_guard<std::mutex> lock(requestWantMutex_);
106     return requestWant_;
107 }
108 
GetRequestResolvedType()109 std::string PendingWantKey::GetRequestResolvedType()
110 {
111     return requestResolvedType_;
112 }
113 
GetAllWantsInfos()114 std::vector<WantsInfo> PendingWantKey::GetAllWantsInfos()
115 {
116     std::lock_guard<std::mutex> lock(wantsInfosMutex_);
117     return allWantsInfos_;
118 }
119 
GetFlags()120 int32_t PendingWantKey::GetFlags()
121 {
122     return flags_;
123 }
124 
GetCode()125 int32_t PendingWantKey::GetCode()
126 {
127     return code_;
128 }
129 
GetUserId()130 int32_t PendingWantKey::GetUserId()
131 {
132     return userId_;
133 }
134 
GetAppIndex()135 int32_t PendingWantKey::GetAppIndex()
136 {
137     return appIndex_;
138 }
139 
IsEqualsRequestWant(const Want & otherWant)140 bool PendingWantKey::IsEqualsRequestWant(const Want &otherWant)
141 {
142     std::lock_guard<std::mutex> lock(requestWantMutex_);
143     return requestWant_.IsEquals(otherWant);
144 }
145 
GetAllBundleNames(std::vector<std::string> & bundleNames)146 void PendingWantKey::GetAllBundleNames(std::vector<std::string> &bundleNames)
147 {
148     std::lock_guard<std::mutex> lock(wantsInfosMutex_);
149     for (const auto &wantInfo : allWantsInfos_) {
150         bundleNames.emplace_back(wantInfo.want.GetBundle());
151     }
152 }
153 }  // namespace AAFwk
154 }  // namespace OHOS
155