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_PLUGIN_RESOURCE_PLUGIN_MANAGER_RESOURCE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PLUGIN_RESOURCE_PLUGIN_MANAGER_RESOURCE_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "core/pipeline/pipeline_base.h" 23 #include "core/pipeline/pipeline_context.h" 24 25 namespace OHOS::Ace { 26 constexpr int64_t INVALID_ID = -1; 27 constexpr int64_t CREATING_ID = -2; 28 29 extern const char PLUGIN_MANAGER_PARAM_NONE[1]; 30 extern const char PLUGIN_MANAGER_PARAM_AND[10]; 31 extern const char PLUGIN_MANAGER_PARAM_VALUE[6]; 32 extern const char PLUGIN_MANAGER_PARAM_EQUALS[10]; 33 extern const char PLUGIN_MANAGER_PARAM_BEGIN[10]; 34 extern const char PLUGIN_MANAGER_METHOD[7]; 35 extern const char PLUGIN_MANAGER_EVENT[6]; 36 extern const char PLUGIN_MANAGER_RESULT_FAIL[5]; 37 38 class PluginManagerResource : public virtual AceType { 39 DECLARE_ACE_TYPE(PluginManagerResource, AceType); 40 41 public: 42 using ErrorCallback = std::function<void(const std::string&, const std::string&)>; 43 using Method = std::string; 44 PluginManagerResource(const std::string & type,const WeakPtr<PipelineBase> & context)45 PluginManagerResource(const std::string& type, const WeakPtr<PipelineBase>& context) 46 : type_(type), context_(context) 47 {} 48 virtual ~PluginManagerResource() = default; 49 50 void Release(const std::function<void(bool)>& onRelease = nullptr); 51 52 void CallResRegisterMethod( 53 const Method& method, const std::string& param, const std::function<void(std::string&)>& callback = nullptr); 54 GetId()55 int64_t GetId() const 56 { 57 return id_; 58 } 59 GetHashCode()60 const std::string& GetHashCode() const 61 { 62 return hash_; 63 } 64 65 protected: 66 int32_t GetIntParam(const std::string& param, const std::string& name) const; 67 std::string GetStringParam(const std::string& param, const std::string& name) const; 68 std::map<std::string, std::string> ParseMapFromString(const std::string& param); 69 std::string MakeResourceHash() const; 70 std::string MakeEventHash(const std::string& event) const; 71 std::string MakeMethodHash(const std::string& method) const; 72 Reset()73 void Reset() 74 { 75 id_ = INVALID_ID; 76 hash_.clear(); 77 } 78 79 int64_t id_ = INVALID_ID; 80 std::string hash_; 81 std::string type_; 82 WeakPtr<PipelineBase> context_; 83 }; 84 } // namespace OHOS::Ace 85 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PLUGIN_RESOURCE_PLUGIN_MANAGER_RESOURCE_H 86