1 /* 2 * Copyright (c) 2021-2022 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_ABILITY_BASE_ELEMENT_NAME_H 17 #define OHOS_ABILITY_BASE_ELEMENT_NAME_H 18 19 #include <string> 20 21 #include "parcel.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 class ElementName : public Parcelable { 26 /* 27 * How to locate unique Ability: deviceId/bundleName/abilityName 28 */ 29 public: 30 ElementName(const std::string &deviceId, const std::string &bundleName, 31 const std::string &abilityName, const std::string &moduleName = ""); 32 ElementName(); 33 ~ElementName(); 34 35 std::string GetURI() const; 36 37 bool ParseURI(const std::string &uri); 38 39 bool operator==(const ElementName &element) const; 40 SetDeviceID(const std::string & id)41 inline void SetDeviceID(const std::string &id) 42 { 43 deviceId_ = id; 44 } 45 GetDeviceID()46 inline std::string GetDeviceID() const 47 { 48 return deviceId_; 49 } 50 SetBundleName(const std::string & name)51 inline void SetBundleName(const std::string &name) 52 { 53 bundleName_ = name; 54 } 55 GetBundleName()56 inline std::string GetBundleName() const 57 { 58 return bundleName_; 59 } 60 SetAbilityName(const std::string & name)61 inline void SetAbilityName(const std::string &name) 62 { 63 abilityName_ = name; 64 } 65 GetAbilityName()66 inline std::string GetAbilityName() const 67 { 68 return abilityName_; 69 } 70 SetModuleName(const std::string & moduleName)71 inline void SetModuleName(const std::string &moduleName) 72 { 73 moduleName_ = moduleName; 74 } 75 GetModuleName()76 inline std::string GetModuleName() const 77 { 78 return moduleName_; 79 } 80 81 bool ReadFromParcel(Parcel &parcel); 82 virtual bool Marshalling(Parcel &parcel) const override; 83 static ElementName *Unmarshalling(Parcel &parcel); 84 85 void SetElementDeviceID(ElementName *element, const char *deviceId); 86 void SetElementBundleName(ElementName *element, const char *bundleName); 87 void SetElementAbilityName(ElementName *element, const char *abilityName); 88 void SetElementModuleName(ElementName *element, const char *moduleName); 89 void ClearElement(ElementName *element); 90 91 void Split(const std::string &str, const std::string &delim, std::vector<std::string> &vec); 92 93 private: 94 std::string deviceId_; 95 std::string bundleName_; 96 std::string abilityName_; 97 std::string moduleName_; 98 }; 99 } // namespace AppExecFwk 100 } // namespace OHOS 101 #endif // OHOS_ABILITY_BASE_ELEMENT_NAME_H 102