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_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_RESOURCE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_RESOURCE_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "core/pipeline/pipeline_context.h" 23 24 namespace OHOS::Ace { 25 26 constexpr int64_t INVALID_ID = -1; 27 constexpr int64_t CREATING_ID = -2; 28 29 extern const char ABILITY_COMPONENT_PARAM_AND[]; 30 extern const char ABILITY_COMPONENT_PARAM_EQUALS[]; 31 extern const char ABILITY_COMPONENT_PARAM_BEGIN[]; 32 extern const char ABILITY_COMPONENT_METHOD[]; 33 extern const char ABILITY_COMPONENT_EVENT[]; 34 35 class AbilityComponentResource : public virtual AceType { 36 DECLARE_ACE_TYPE(AbilityComponentResource, AceType); 37 38 public: 39 using Method = std::string; 40 AbilityComponentResource(const std::string & type,const WeakPtr<PipelineContext> & context)41 AbilityComponentResource(const std::string& type, const WeakPtr<PipelineContext>& context) 42 : type_(type), context_(context) 43 {} 44 virtual ~AbilityComponentResource() = default; 45 46 void Release(const std::function<void(bool)>& onRelease = nullptr); 47 std::string CallResRegisterMethod(const Method& method, const std::string& param, bool useSyncTask); 48 GetId()49 int64_t GetId() const 50 { 51 return id_; 52 } 53 GetHashCode()54 const std::string& GetHashCode() const 55 { 56 return hash_; 57 } 58 59 protected: 60 std::string MakeResourceHash() const; 61 std::string MakeEventHash(const std::string& event) const; 62 std::string MakeMethodHash(const std::string& method) const; 63 Reset()64 void Reset() 65 { 66 id_ = INVALID_ID; 67 hash_.clear(); 68 } 69 70 int64_t id_ = INVALID_ID; 71 std::string hash_; 72 std::string type_; 73 WeakPtr<PipelineContext> context_; 74 }; 75 76 } // namespace OHOS::Ace 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_RESOURCE_H 79