1e0857b17Sopenharmony_ci/* 2e0857b17Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e0857b17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0857b17Sopenharmony_ci * you may not use this file except in compliance with the License. 5e0857b17Sopenharmony_ci * You may obtain a copy of the License at 6e0857b17Sopenharmony_ci * 7e0857b17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0857b17Sopenharmony_ci * 9e0857b17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0857b17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0857b17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0857b17Sopenharmony_ci * See the License for the specific language governing permissions and 13e0857b17Sopenharmony_ci * limitations under the License. 14e0857b17Sopenharmony_ci */ 15e0857b17Sopenharmony_ci 16e0857b17Sopenharmony_ci#ifndef OHOS_ABILITY_BASE_OPERATION_H 17e0857b17Sopenharmony_ci#define OHOS_ABILITY_BASE_OPERATION_H 18e0857b17Sopenharmony_ci 19e0857b17Sopenharmony_ci#include <string> 20e0857b17Sopenharmony_ci#include "uri.h" 21e0857b17Sopenharmony_ci#include "parcel.h" 22e0857b17Sopenharmony_ci#include "string_ex.h" 23e0857b17Sopenharmony_ci 24e0857b17Sopenharmony_cinamespace OHOS { 25e0857b17Sopenharmony_cinamespace AAFwk { 26e0857b17Sopenharmony_ciclass OperationBuilder; 27e0857b17Sopenharmony_ci 28e0857b17Sopenharmony_ciclass Operation : public Parcelable { 29e0857b17Sopenharmony_ci friend class OperationBuilder; 30e0857b17Sopenharmony_ci friend class Want; 31e0857b17Sopenharmony_ci 32e0857b17Sopenharmony_cipublic: 33e0857b17Sopenharmony_ci Operation(); 34e0857b17Sopenharmony_ci ~Operation(); 35e0857b17Sopenharmony_ci Operation(const Operation &other); 36e0857b17Sopenharmony_ci /** 37e0857b17Sopenharmony_ci * @description: Obtains the value of the abilityName attribute included in this Operation. 38e0857b17Sopenharmony_ci * @return Returns the ability name included in this Operation. 39e0857b17Sopenharmony_ci */ 40e0857b17Sopenharmony_ci std::string GetAbilityName() const; 41e0857b17Sopenharmony_ci 42e0857b17Sopenharmony_ci /** 43e0857b17Sopenharmony_ci * @description: Obtains the value of the action attribute included in this Operation. 44e0857b17Sopenharmony_ci * @return Returns the action included in this Operation. 45e0857b17Sopenharmony_ci */ 46e0857b17Sopenharmony_ci std::string GetAction() const; 47e0857b17Sopenharmony_ci 48e0857b17Sopenharmony_ci /** 49e0857b17Sopenharmony_ci * @description: Obtains the value of the bundleName attribute included in this Operation. 50e0857b17Sopenharmony_ci * @return Returns the bundle name included in this Operation. 51e0857b17Sopenharmony_ci */ 52e0857b17Sopenharmony_ci std::string GetBundleName() const; 53e0857b17Sopenharmony_ci 54e0857b17Sopenharmony_ci /** 55e0857b17Sopenharmony_ci * @description: Obtains the value of the deviceId attribute included in this Operation. 56e0857b17Sopenharmony_ci * @return Returns the device ID included in this Operation. 57e0857b17Sopenharmony_ci */ 58e0857b17Sopenharmony_ci std::string GetDeviceId() const; 59e0857b17Sopenharmony_ci 60e0857b17Sopenharmony_ci /** 61e0857b17Sopenharmony_ci * @description: Obtains the value of the entities attribute included in this Operation. 62e0857b17Sopenharmony_ci * @return Returns the entities included in this Operation. 63e0857b17Sopenharmony_ci */ 64e0857b17Sopenharmony_ci const std::vector<std::string> &GetEntities() const; 65e0857b17Sopenharmony_ci 66e0857b17Sopenharmony_ci /** 67e0857b17Sopenharmony_ci * @description: Obtains the value of the flags attribute included in this Operation. 68e0857b17Sopenharmony_ci * @return Returns the flags included in this Operation. 69e0857b17Sopenharmony_ci */ 70e0857b17Sopenharmony_ci unsigned int GetFlags() const; 71e0857b17Sopenharmony_ci 72e0857b17Sopenharmony_ci /** 73e0857b17Sopenharmony_ci * @description: Obtains the value of the uri attribute included in this Operation. 74e0857b17Sopenharmony_ci * @return Returns the URI included in this Operation. 75e0857b17Sopenharmony_ci */ 76e0857b17Sopenharmony_ci OHOS::Uri GetUri() const; 77e0857b17Sopenharmony_ci 78e0857b17Sopenharmony_ci /** 79e0857b17Sopenharmony_ci * @description: Obtains the description of the ModuleName object in the Operation. 80e0857b17Sopenharmony_ci * @return Returns the ModuleName description in the Operation. 81e0857b17Sopenharmony_ci */ 82e0857b17Sopenharmony_ci std::string GetModuleName() const; 83e0857b17Sopenharmony_ci 84e0857b17Sopenharmony_ci bool operator==(const Operation &other) const; 85e0857b17Sopenharmony_ci Operation &operator=(const Operation &other); 86e0857b17Sopenharmony_ci 87e0857b17Sopenharmony_ci bool Marshalling(Parcel &parcel) const; 88e0857b17Sopenharmony_ci static Operation *Unmarshalling(Parcel &parcel); 89e0857b17Sopenharmony_ci 90e0857b17Sopenharmony_ci void DumpInfo(int level) const; 91e0857b17Sopenharmony_ci 92e0857b17Sopenharmony_ciprivate: 93e0857b17Sopenharmony_ci /** 94e0857b17Sopenharmony_ci * @description: Sets a flag in a Want. 95e0857b17Sopenharmony_ci * @param flags Indicates the flag to set. 96e0857b17Sopenharmony_ci * @return Returns this Want object containing the flag. 97e0857b17Sopenharmony_ci */ 98e0857b17Sopenharmony_ci void SetFlags(unsigned int flags); 99e0857b17Sopenharmony_ci /** 100e0857b17Sopenharmony_ci * @description: Adds a flag to a Want. 101e0857b17Sopenharmony_ci * @param flags Indicates the flag to add. 102e0857b17Sopenharmony_ci * @return Returns the Want object with the added flag. 103e0857b17Sopenharmony_ci */ 104e0857b17Sopenharmony_ci void AddFlags(unsigned int flags); 105e0857b17Sopenharmony_ci /** 106e0857b17Sopenharmony_ci * @description: Removes the description of a flag from a Want. 107e0857b17Sopenharmony_ci * @param flags Indicates the flag to remove. 108e0857b17Sopenharmony_ci * @return Removes the description of a flag from a Want. 109e0857b17Sopenharmony_ci */ 110e0857b17Sopenharmony_ci void RemoveFlags(unsigned int flags); 111e0857b17Sopenharmony_ci 112e0857b17Sopenharmony_ci /** 113e0857b17Sopenharmony_ci * @description: Adds the description of an entity to a Want 114e0857b17Sopenharmony_ci * @param entity Indicates the entity description to add 115e0857b17Sopenharmony_ci * @return Returns this Want object containing the entity. 116e0857b17Sopenharmony_ci */ 117e0857b17Sopenharmony_ci void AddEntity(const std::string &entity); 118e0857b17Sopenharmony_ci 119e0857b17Sopenharmony_ci /** 120e0857b17Sopenharmony_ci * @description: Removes the description of an entity from a Want 121e0857b17Sopenharmony_ci * @param entity Indicates the entity description to remove. 122e0857b17Sopenharmony_ci * @return void 123e0857b17Sopenharmony_ci */ 124e0857b17Sopenharmony_ci void RemoveEntity(const std::string &entity); 125e0857b17Sopenharmony_ci 126e0857b17Sopenharmony_ci /** 127e0857b17Sopenharmony_ci * @description: Checks whether a Want contains the given entity 128e0857b17Sopenharmony_ci * @param entity Indicates the entity to check 129e0857b17Sopenharmony_ci * @return Returns true if the given entity is contained; returns false otherwise 130e0857b17Sopenharmony_ci */ 131e0857b17Sopenharmony_ci bool HasEntity(const std::string &entity) const; 132e0857b17Sopenharmony_ci 133e0857b17Sopenharmony_ci /** 134e0857b17Sopenharmony_ci * @description: Obtains the number of entities in a Want 135e0857b17Sopenharmony_ci * @return Returns the entity quantity 136e0857b17Sopenharmony_ci */ 137e0857b17Sopenharmony_ci int CountEntities() const; 138e0857b17Sopenharmony_ci 139e0857b17Sopenharmony_ci /** 140e0857b17Sopenharmony_ci * @description: Sets a bundle name in this Want. 141e0857b17Sopenharmony_ci * If a bundle name is specified in a Want, the Want will match only 142e0857b17Sopenharmony_ci * the abilities in the specified bundle. You cannot use this method and 143e0857b17Sopenharmony_ci * setPicker(ohos.aafwk.content.Want) on the same Want. 144e0857b17Sopenharmony_ci * @param bundleName Indicates the bundle name to set. 145e0857b17Sopenharmony_ci * @return Returns a Want object containing the specified bundle name. 146e0857b17Sopenharmony_ci */ 147e0857b17Sopenharmony_ci void SetBundleName(const std::string &bundleName); 148e0857b17Sopenharmony_ci 149e0857b17Sopenharmony_ci /** 150e0857b17Sopenharmony_ci * @description: Sets a uri in this operation. 151e0857b17Sopenharmony_ci * @param uri Indicates uri object to set. 152e0857b17Sopenharmony_ci * @return - 153e0857b17Sopenharmony_ci */ 154e0857b17Sopenharmony_ci void SetUri(const Uri &uri); 155e0857b17Sopenharmony_ci 156e0857b17Sopenharmony_ci /** 157e0857b17Sopenharmony_ci * @description: Gets a uri in this operation. 158e0857b17Sopenharmony_ci * @param uri Indicates uri object to set. 159e0857b17Sopenharmony_ci * @return Returns a uri in this operation. 160e0857b17Sopenharmony_ci */ 161e0857b17Sopenharmony_ci Uri &GetUri(const Uri &uri); 162e0857b17Sopenharmony_ci 163e0857b17Sopenharmony_ci /** 164e0857b17Sopenharmony_ci * @description: Sets the value of the abilityName attribute included in this Operation. 165e0857b17Sopenharmony_ci * @return Returns the ability name included in this Operation. 166e0857b17Sopenharmony_ci */ 167e0857b17Sopenharmony_ci void SetAbilityName(const std::string &abilityname); 168e0857b17Sopenharmony_ci 169e0857b17Sopenharmony_ci /** 170e0857b17Sopenharmony_ci * @description: Sets the value of the deviceId attribute included in this Operation. 171e0857b17Sopenharmony_ci * @param deviceid Indicates deviceid object to set. 172e0857b17Sopenharmony_ci * @return - 173e0857b17Sopenharmony_ci */ 174e0857b17Sopenharmony_ci void SetDeviceId(const std::string &deviceid); 175e0857b17Sopenharmony_ci 176e0857b17Sopenharmony_ci /** 177e0857b17Sopenharmony_ci * @description: Sets the value of the action attribute included in this Operation. 178e0857b17Sopenharmony_ci * @param deviceid Indicates deviceid object to set. 179e0857b17Sopenharmony_ci * @return - 180e0857b17Sopenharmony_ci */ 181e0857b17Sopenharmony_ci void SetAction(const std::string &action); 182e0857b17Sopenharmony_ci 183e0857b17Sopenharmony_ci /** 184e0857b17Sopenharmony_ci * @description: Sets the entities of this Operation. 185e0857b17Sopenharmony_ci * @param entities Indicates entities to set. 186e0857b17Sopenharmony_ci * @return - 187e0857b17Sopenharmony_ci */ 188e0857b17Sopenharmony_ci void SetEntities(const std::vector<std::string> &entities); 189e0857b17Sopenharmony_ci 190e0857b17Sopenharmony_ci /** 191e0857b17Sopenharmony_ci * @description: Sets an ModuleName object in the Operation. 192e0857b17Sopenharmony_ci * @param moduleName Indicates the ModuleName description. 193e0857b17Sopenharmony_ci * @return Returns this Operation object containing the ModuleName. 194e0857b17Sopenharmony_ci */ 195e0857b17Sopenharmony_ci void SetModuleName(const std::string &moduleName); 196e0857b17Sopenharmony_ci 197e0857b17Sopenharmony_ciprivate: 198e0857b17Sopenharmony_ci std::string abilityName_; 199e0857b17Sopenharmony_ci std::string action_; 200e0857b17Sopenharmony_ci std::string bundleName_; 201e0857b17Sopenharmony_ci std::string deviceId_; 202e0857b17Sopenharmony_ci std::string moduleName_; 203e0857b17Sopenharmony_ci std::vector<std::string> entities_; 204e0857b17Sopenharmony_ci unsigned int flags_; 205e0857b17Sopenharmony_ci Uri uri_; 206e0857b17Sopenharmony_ci friend class OperationBuilder; 207e0857b17Sopenharmony_ci 208e0857b17Sopenharmony_ci // no object in parcel 209e0857b17Sopenharmony_ci static constexpr int VALUE_NULL = -1; 210e0857b17Sopenharmony_ci // object exist in parcel 211e0857b17Sopenharmony_ci static constexpr int VALUE_OBJECT = 1; 212e0857b17Sopenharmony_ci 213e0857b17Sopenharmony_ci bool ReadFromParcel(Parcel &parcel); 214e0857b17Sopenharmony_ci}; 215e0857b17Sopenharmony_ci} // namespace AAFwk 216e0857b17Sopenharmony_ci} // namespace OHOS 217e0857b17Sopenharmony_ci 218e0857b17Sopenharmony_ci#endif // OHOS_ABILITY_BASE_OPERATION_H