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