• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_DISTRIBUTEDWANT_OPERATION_H
17 #define OHOS_DISTRIBUTEDWANT_OPERATION_H
18 
19 #include <string>
20 #include "parcel.h"
21 #include "string_ex.h"
22 #include "uri.h"
23 
24 namespace OHOS {
25 namespace DistributedSchedule {
26 class DistributedOperationBuilder;
27 class DistributedOperation : public Parcelable {
28     friend class DistributedOperationBuilder;
29     friend class DistributedWant;
30 
31 public:
32     DistributedOperation();
33     ~DistributedOperation();
34     DistributedOperation(const DistributedOperation& other);
35     /**
36      * @description: Obtains the value of the abilityName attribute included in this DistributedOperation.
37      * @return Returns the ability name included in this DistributedOperation.
38      */
39     std::string GetAbilityName() const;
40 
41     /**
42      * @description: Obtains the value of the action attribute included in this DistributedOperation.
43      * @return Returns the action included in this DistributedOperation.
44      */
45     std::string GetAction() const;
46 
47     /**
48      * @description: Obtains the value of the bundleName attribute included in this DistributedOperation.
49      * @return Returns the bundle name included in this DistributedOperation.
50      */
51     std::string GetBundleName() const;
52 
53     /**
54      * @description: Obtains the value of the deviceId attribute included in this DistributedOperation.
55      * @return Returns the device ID included in this DistributedOperation.
56      */
57     std::string GetDeviceId() const;
58 
59     /**
60      * @description: Obtains the value of the entities attribute included in this DistributedOperation.
61      * @return Returns the entities included in this DistributedOperation.
62      */
63     const std::vector<std::string>& GetEntities() const;
64 
65     /**
66      * @description: Obtains the value of the flags attribute included in this DistributedOperation.
67      * @return Returns the flags included in this DistributedOperation.
68      */
69     unsigned int GetFlags() const;
70 
71     /**
72      * @description: Obtains the value of the uri attribute included in this DistributedOperation.
73      * @return Returns the URI included in this DistributedOperation.
74      */
75     OHOS::Uri GetUri() const;
76 
77     /**
78      * @description: Obtains the description of the ModuleName object in the DistributedOperation.
79      * @return Returns the ModuleName description in the DistributedOperation.
80      */
81     std::string GetModuleName() const;
82 
83     bool operator==(const DistributedOperation& other) const;
84     DistributedOperation& operator=(const DistributedOperation& other);
85 
86     bool Marshalling(Parcel& parcel) const;
87     static DistributedOperation* Unmarshalling(Parcel& parcel);
88 
89 private:
90     /**
91      * @description: Sets a flag in a DistributedWant.
92      * @param flags Indicates the flag to set.
93      * @return Returns this DistributedWant object containing the flag.
94      */
95     void SetFlags(unsigned int flags);
96     /**
97      * @description: Adds a flag to a DistributedWant.
98      * @param flags Indicates the flag to add.
99      * @return Returns the DistributedWant object with the added flag.
100      */
101     void AddFlags(unsigned int flags);
102     /**
103      * @description: Removes the description of a flag from a DistributedWant.
104      * @param flags Indicates the flag to remove.
105      * @return Removes the description of a flag from a DistributedWant.
106      */
107     void RemoveFlags(unsigned int flags);
108 
109     /**
110      * @description: Adds the description of an entity to a DistributedWant
111      * @param entity Indicates the entity description to add
112      * @return Returns this DistributedWant object containing the entity.
113      */
114     void AddEntity(const std::string& entity);
115 
116     /**
117      * @description: Removes the description of an entity from a DistributedWant
118      * @param entity Indicates the entity description to remove.
119      * @return void
120      */
121     void RemoveEntity(const std::string& entity);
122 
123     /**
124      * @description: Checks whether a DistributedWant contains the given entity
125      * @param entity Indicates the entity to check
126      * @return Returns true if the given entity is contained; returns false otherwise
127      */
128     bool HasEntity(const std::string& entity) const;
129 
130     /**
131      * @description: Obtains the number of entities in a DistributedWant
132      * @return Returns the entity quantity
133      */
134     int CountEntities() const;
135 
136     /**
137      * @description: Sets a bundle name in this DistributedWant.
138      * If a bundle name is specified in a DistributedWant, the DistributedWant will match only
139      * the abilities in the specified bundle. You cannot use this method and
140      * setPicker(ohos.aafwk.content.DistributedWant) on the same DistributedWant.
141      * @param bundleName Indicates the bundle name to set.
142      * @return Returns a DistributedWant object containing the specified bundle name.
143      */
144     void SetBundleName(const std::string& bundleName);
145 
146     /**
147      * @description: Sets a uri in this DistributedOperation.
148      * @param uri Indicates uri object to set.
149      * @return -
150      */
151     void SetUri(const OHOS::Uri& uri);
152 
153     /**
154      * @description: Gets a uri in this DistributedOperation.
155      * @param uri Indicates uri object to set.
156      * @return Returns a uri in this DistributedOperation.
157      */
158     OHOS::Uri& GetUri(const OHOS::Uri& uri);
159 
160     /**
161      * @description: Sets the value of the abilityName attribute included in this DistributedOperation.
162      * @return Returns the ability name included in this DistributedOperation.
163      */
164     void SetAbilityName(const std::string& abilityname);
165 
166     /**
167      * @description: Sets the value of the deviceId attribute included in this DistributedOperation.
168      * @param deviceid Indicates deviceid object to set.
169      * @return -
170      */
171     void SetDeviceId(const std::string& deviceid);
172 
173     /**
174      * @description: Sets the value of the action attribute included in this DistributedOperation.
175      * @param deviceid Indicates deviceid object to set.
176      * @return -
177      */
178     void SetAction(const std::string& action);
179 
180     /**
181      * @description: Sets the entities of this DistributedOperation.
182      * @param entities Indicates entities to set.
183      * @return -
184      */
185     void SetEntities(const std::vector<std::string>& entities);
186 
187     /**
188      * @description: Sets an ModuleName object in the DistributedOperation.
189      * @param moduleName Indicates the ModuleName description.
190      * @return Returns this DistributedOperation object containing the ModuleName.
191      */
192     void SetModuleName(const std::string& moduleName);
193 
194 private:
195     std::string abilityName_;
196     std::string action_;
197     std::string bundleName_;
198     std::string deviceId_;
199     std::string moduleName_;
200     std::vector<std::string> entities_;
201     unsigned int flags_;
202     OHOS::Uri uri_;
203 
204     // no object in parcel
205     static constexpr int VALUE_NULL = -1;
206     // object exist in parcel
207     static constexpr int VALUE_OBJECT = 1;
208 
209     bool ReadFromParcel(Parcel& parcel);
210 };
211 } // namespace DistributedSchedule
212 } // namespace OHOS
213 #endif // OHOS_DISTRIBUTEDWANT_OPERATION_H