1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #ifndef COMMON_PLUGINS_PLUGIN_H_
6 #define COMMON_PLUGINS_PLUGIN_H_
9 #include <manifest_parser/utils/logging.h>
10 #include <libxml2/libxml/tree.h>
11 #include <pkgmgrinfo_basic.h>
16 #include "common/plugins/plugin_list_parser.h"
18 namespace common_installer {
21 * @brief The Plugin class
22 * Represents pkgmgr plugin object handling internally managing loading
23 * of .so shared object from file system. Run() function is being
24 * overloaded in subclasses to accommodate plugin differences.
28 enum class ActionType {
40 enum class ProcessType { Pre, Main, Post };
44 template <typename Ret, typename... Args>
45 bool Exec(const std::string& name, Ret* result, Args... args) {
46 using PluginFunctionPtr = Ret (*)(Args...);
47 PluginFunctionPtr function =
48 reinterpret_cast<PluginFunctionPtr>(GetSymbol(name));
51 LOG(WARNING) << "Skip to execute symbol: " << name << " (" << dlerror()
56 LOG(DEBUG) << "Execute plugin function: " << name << " of "
57 << plugin_info_.path() << "...";
58 *result = function(args...);
62 const PluginInfo& plugin_info() const { return plugin_info_; }
64 virtual bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
65 ActionType action_type) = 0;
67 Plugin(Plugin&&) = default;
68 Plugin& operator=(Plugin&&) = default;
71 explicit Plugin(const PluginInfo& plugin_info);
74 PluginInfo plugin_info_;
77 void* GetSymbol(const std::string& name) const;
85 * @brief ActionTypeToPkgmgrActionType
86 * Helper function to convert app-installer ActionType to pkgmgr action
87 * type for 'category' and 'metadata' plugins.
89 * @param action input action type
90 * @return pkgmgr action type or -1 if error
92 int ActionTypeToPkgmgrActionType(common_installer::Plugin::ActionType action);
94 } // namespace common_installer
96 #endif // COMMON_PLUGINS_PLUGIN_H_