• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_MATCHING_SKILLS_H
17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_MATCHING_SKILLS_H
18 
19 #include "parcel.h"
20 #include "want.h"
21 
22 namespace OHOS {
23 namespace EventFwk {
24 using Want = OHOS::AAFwk::Want;
25 
26 class MatchingSkills : public Parcelable {
27 public:
28     MatchingSkills();
29 
30     /**
31      * A constructor used to create a MatchingSkills object instance by using the parameters of an existing
32      * MatchingSkills object.
33      */
34     MatchingSkills(const MatchingSkills &matchingSkills);
35 
36     ~MatchingSkills();
37 
38     /**
39      * Obtains an entity.
40      *
41      * @param index Indicates the entity index.
42      * @return Returns entity.
43      */
44     std::string GetEntity(size_t index) const;
45 
46     /**
47      * Adds an entity to this MatchingSkills object.
48      *
49      * @param entity Indicates the entity.
50      */
51     void AddEntity(const std::string &entity);
52 
53     /**
54      * Checks whether the entity is in this MatchingSkills object.
55      *
56      * @param event Indicates specified entity in MatchingSkills object.
57      * @return Returns whether the entity is in MatchingSkills object or not.
58      */
59     bool HasEntity(const std::string &entity) const;
60 
61     /**
62      * Removes entity.
63      *
64      * @param event Indicates specified entity in MatchingSkills object.
65      */
66     void RemoveEntity(const std::string &entity);
67 
68     /**
69      * Gets entity count.
70      *
71      * @return Returns entity count.
72      */
73     size_t CountEntities() const;
74 
75     /**
76      * Adds an event to this MatchingSkills object.
77      *
78      * @param event Indicates the event.
79      */
80     void AddEvent(const std::string &event);
81 
82     /**
83      * Gets event count.
84      *
85      * @return Indicates the event count in MatchingSkills object.
86      */
87     size_t CountEvent() const;
88 
89     /**
90      * Gets event.
91      *
92      * @param index Indicates the scheme index.
93      * @return Returns the event in MatchingSkills object.
94      */
95     std::string GetEvent(size_t index) const;
96 
97     /**
98      * Gets events.
99      *
100      * @return Returns the events in MatchingSkills object.
101      */
102     std::vector<std::string> GetEvents() const;
103 
104     /**
105      * Removes events.
106      *
107      * @return Indicates the event in MatchingSkills object.
108      */
109     void RemoveEvent(const std::string &event);
110 
111     /**
112      * Checks whether the event is in this MatchingSkills object.
113      *
114      * @param event Indicates specified event in MatchingSkills object
115      * @return Returns whether the event in MatchingSkills object or not.
116      */
117     bool HasEvent(const std::string &event) const;
118 
119     /**
120      * Obtains an Scheme.
121      *
122      * @param index Indicates the scheme index.
123      * @return Returns scheme.
124      */
125     std::string GetScheme(size_t index) const;
126 
127     /**
128      * Adds scheme to this MatchingSkills object.
129      *
130      * @param scheme Indicates the scheme.
131      */
132     void AddScheme(const std::string &scheme);
133 
134     /**
135      * Checks whether the scheme is in this MatchingSkills object.
136      *
137      * @param scheme Indicates specified scheme in MatchingSkills object.
138      * @return Returns whether the scheme in MatchingSkills object or not.
139      */
140     bool HasScheme(const std::string &scheme) const;
141 
142     /**
143      * Removes entity.
144      *
145      * @param event Indicates the entity in MatchingSkills object.
146      */
147     void RemoveScheme(const std::string &scheme);
148 
149     /**
150      * Gets scheme count.
151      *
152      * @return Returns scheme count.
153      */
154     size_t CountSchemes() const;
155 
156     /**
157      * Matches want.
158      *
159      * @param want Indicates the want in MatchingSkills object.
160      * @return Returns the match want result.
161      */
162     bool Match(const Want &want) const;
163 
164     /**
165      * Marshals this MatchingSkills object into a Parcel.
166      *
167      * @param parcel Indicates specified Parcel object.
168      * @return Returns the marshalling result.
169      */
170     virtual bool Marshalling(Parcel &parcel) const override;
171 
172     /**
173      * Unmarshals this MatchingSkills object from a Parcel.
174      *
175      * @param parcel Indicates the parcel.
176      * @return Returns the MatchingSkills.
177      */
178     static MatchingSkills *Unmarshalling(Parcel &parcel);
179 
180     bool WriteVectorInfo(Parcel &parcel, std::vector<std::u16string>vectorInfo) const;
181 
182 private:
183     /**
184      * Reads MatchingSkills object from a Parcel.
185      *
186      * @param parcel Indicates specified Parcel object.
187      * @return Returns read from parcel success or fail.
188      */
189     bool ReadFromParcel(Parcel &parcel);
190 
191     /**
192      * Matches event.
193      *
194      * @param parcel Indicates the event in want.
195      * @return Returns match event success or fail.
196      */
197     bool MatchEvent(const std::string &event) const;
198 
199     /**
200      * Matches entity.
201      *
202      * @param parcel Indicates the entity in want.
203      * @return Returns match entity success or fail.
204      */
205     bool MatchEntity(const std::vector<std::string> &entities) const;
206 
207     /**
208      * Matches scheme.
209      *
210      * @param parcel Indicates the scheme in want.
211      * @return Returns match scheme success or fail.
212      */
213     bool MatchScheme(const std::string &scheme) const;
214 
215 private:
216     std::vector<std::string> entities_;
217     std::vector<std::string> events_;
218     std::vector<std::string> schemes_;
219     static constexpr int32_t VALUE_NULL = -1;
220     static constexpr int32_t VALUE_OBJECT = 1;
221 };
222 }  // namespace EventFwk
223 }  // namespace OHOS
224 
225 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_MATCHING_SKILLS_H