• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void AddPlugin(const WeakPtr<PipelineBase>& context, const RequestPluginInfo& info);
52     void AddPluginCompleteCallback(const OnPluginCompleteCallback& layoutChangeCallback);
53     void AddPluginUpdateCallback(const OnPluginUpdateCallback& layoutChangeCallback);
54     void AddPluginErrorCallback(const OnPluginErrorCallback& layoutChangeCallback);
55 
56     void OnActionEvent(const std::string& action);
57     void OnPluginComplete(const std::string& param);
58     void OnPluginUpdate(const std::string& param);
59     void OnPluginError(const std::string& param);
60 
61 #ifdef OHOS_STANDARD_SYSTEM
62     void ProcessPluginUninstall(const int64_t PluginId);
OnDeathReceived()63     void OnDeathReceived() {}
64 #endif
65 
66 private:
67     void CreatePlatformResource(const WeakPtr<PipelineBase>& context, const RequestPluginInfo& info);
68     void RegisterEvent();
69     void UnregisterEvent();
70 
71     OnPluginCompleteCallback onPluginCompleteCallback_;
72     OnPluginUpdateCallback onPluginUpdateCallback_;
73     OnPluginErrorCallback onPluginErrorCallback_;
74 
75     State state_ { State::WAITINGFORSIZE };
76 };
77 } // namespace OHOS::Ace
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PLUGIN_RESOURCE_PLUGIN_MANAGER_DELEGATE_H
79