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_DELEGATE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PLUGIN_RESOURCE_PLUGIN_MANAGER_DELEGATE_H 18 19 #include <list> 20 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/plugin/resource/plugin_manager_resource.h" 23 #include "core/components/plugin/resource/plugin_request_data.h" 24 25 #ifdef OHOS_STANDARD_SYSTEM 26 #include "want.h" 27 #endif 28 29 namespace OHOS::Ace { 30 class PluginManagerDelegate : public PluginManagerResource { 31 DECLARE_ACE_TYPE(PluginManagerDelegate, PluginManagerResource); 32 33 public: 34 using OnPluginCompleteCallback = std::function<void()>; 35 using OnPluginUpdateCallback = std::function<void(int64_t, const std::string&)>; 36 using OnPluginErrorCallback = std::function<void(const std::string&, const std::string&)>; 37 38 enum class State : char { 39 WAITINGFORSIZE, 40 CREATING, 41 CREATED, 42 CREATEFAILED, 43 RELEASED, 44 }; 45 46 PluginManagerDelegate() = delete; 47 ~PluginManagerDelegate() override; PluginManagerDelegate(const WeakPtr<PipelineBase> & context)48 explicit PluginManagerDelegate(const WeakPtr<PipelineBase>& context) 49 : PluginManagerResource("pluginAdaptor", context), state_(State::WAITINGFORSIZE) 50 {} 51 52 void AddPlugin(const WeakPtr<PipelineBase>& context, const RequestPluginInfo& info); 53 void AddPluginCompleteCallback(const OnPluginCompleteCallback& layoutChangeCallback); 54 void AddPluginUpdateCallback(const OnPluginUpdateCallback& layoutChangeCallback); 55 void AddPluginErrorCallback(const OnPluginErrorCallback& layoutChangeCallback); 56 57 void OnActionEvent(const std::string& action); 58 void OnPluginComplete(const std::string& param); 59 void OnPluginUpdate(const std::string& param); 60 void OnPluginError(const std::string& param); 61 62 #ifdef OHOS_STANDARD_SYSTEM 63 void ProcessPluginUninstall(const int64_t PluginId); OnDeathReceived()64 void OnDeathReceived() {} 65 #endif 66 67 private: 68 void CreatePlatformResource(const WeakPtr<PipelineBase>& context, const RequestPluginInfo& info); 69 void RegisterEvent(); 70 void UnregisterEvent(); 71 72 OnPluginCompleteCallback onPluginCompleteCallback_; 73 OnPluginUpdateCallback onPluginUpdateCallback_; 74 OnPluginErrorCallback onPluginErrorCallback_; 75 76 State state_ { State::WAITINGFORSIZE }; 77 }; 78 } // namespace OHOS::Ace 79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PLUGIN_RESOURCE_PLUGIN_MANAGER_DELEGATE_H 80