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_FORM_RESOURCE_FORM_MANAGER_RESOURCE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_RESOURCE_FORM_MANAGER_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 FORM_MANAGER_PARAM_NONE[]; 30 extern const char FORM_MANAGER_PARAM_AND[]; 31 extern const char FORM_MANAGER_PARAM_VALUE[]; 32 extern const char FORM_MANAGER_PARAM_EQUALS[]; 33 extern const char FORM_MANAGER_PARAM_BEGIN[]; 34 extern const char FORM_MANAGER_METHOD[]; 35 extern const char FORM_MANAGER_EVENT[]; 36 extern const char FORM_MANAGER_RESULT_FAIL[]; 37 38 class FormManagerResource : public virtual AceType { 39 DECLARE_ACE_TYPE(FormManagerResource, AceType); 40 41 public: 42 using ErrorCallback = std::function<void(const std::string&, const std::string&)>; 43 using Method = std::string; 44 FormManagerResource(const std::string & type,const WeakPtr<PipelineBase> & context)45 FormManagerResource(const std::string& type, const WeakPtr<PipelineBase>& context) : type_(type), context_(context) 46 {} 47 virtual ~FormManagerResource() = default; 48 49 void Release(const std::function<void(bool)>& onRelease = nullptr); 50 51 void CallResRegisterMethod( 52 const Method& method, const std::string& param, const std::function<void(std::string&)>& callback = nullptr); 53 GetId()54 int64_t GetId() const 55 { 56 return id_; 57 } 58 GetHashCode()59 const std::string& GetHashCode() const 60 { 61 return hash_; 62 } 63 64 protected: 65 int32_t GetIntParam(const std::string& param, const std::string& name) const; 66 std::string GetStringParam(const std::string& param, const std::string& name) const; 67 std::map<std::string, std::string> ParseMapFromString(const std::string& param); 68 std::string MakeResourceHash() const; 69 std::string MakeEventHash(const std::string& event) const; 70 std::string MakeMethodHash(const std::string& method) const; 71 Reset()72 void Reset() 73 { 74 id_ = INVALID_ID; 75 hash_.clear(); 76 } 77 78 int64_t id_ = INVALID_ID; 79 std::string hash_; 80 std::string type_; 81 WeakPtr<PipelineBase> context_; 82 }; 83 84 } // namespace OHOS::Ace 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_RESOURCE_FORM_MANAGER_RESOURCE_H 87