Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src / plugins-installer / plugin_installer.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    plugin_installer.h
18  * @author  Andrzej Surdej(a.surdej@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
24 #define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
25
26 #include <string>
27 #include <utility>
28 #include <boost/optional.hpp>
29 #include <plugin_installer_types.h>
30 #include <plugin_objects.h>
31 #include <IObject.h>
32 #include <PluginRegistry.h>
33
34 #include <dpl/wrt-dao-rw/plugin_dao.h>
35 #include <dpl/singleton.h>
36
37 class PluginsInstaller
38 {
39   public:
40     static const int INSTALLATION_ERROR;
41     enum class ReturnStatus
42     {
43         Success,                    ///< Success
44
45         NotInitialized,             ///< Singleton not initialized
46         WrongPluginPath,            ///< ?
47         MetafileError,              ///< ?
48         AlreadyInstalled,           ///< ?
49         LoadingLibraryError,        ///< Loading library by dlopen failed.
50                                     /// It may be caused by missing symbols
51         InstallationWaiting,        /// Installation failed due to dependencies
52         DatabaseError,              /// Unable to update database
53         Unknown                     ///< Temporary error. Try to not use this.
54     };
55
56     bool initialize();
57     int installAllPlugins();
58     void deinitialize();
59
60     ReturnStatus installPlugin(const std::string& libPath);
61     ReturnStatus installPluginFromMetafile(const std::string& libPath,
62                                            const std::string& metaFilePath);
63
64     int installWaitingPlugins();
65     bool resolvePluginDependencies(PluginHandle handle);
66
67     bool isInitialized();
68
69     int uninstallMissingAndChangedPlugins();
70     void uninstallPlugin(WrtDB::DbPluginHandle handle, const WrtDB::PluginDAOReadOnly& dao);
71
72   private:
73     friend class DPL::Singleton<PluginsInstaller>;
74
75     PluginsInstaller();
76     virtual ~PluginsInstaller();
77
78     void registerObjects(const PluginObjectsPtr& libObj,
79                          const WrtPluginsApi::IObjectsListPtr& objects) const;
80
81     typedef boost::optional<WrtDB::PluginMetafileData> OptionalPluginMetafileData;
82     OptionalPluginMetafileData parseMetafile(const std::string& path) const;
83
84     std::string getLibraryName(const std::string& dirPath) const;
85     bool registerAndUpdateInstallation(const PluginHandle& pluginHandle,
86                                        const PluginObjectsPtr& libraries);
87     bool fillMappingInterfaces(WrtDB::PluginMetafileData& pluginData,
88                                const std::string& filename);
89     void registerPluginObjects(const PluginHandle& handle,
90                                const PluginObjectsPtr libObjects) const;
91     void checkDatabaseTablesExistance();
92     PluginObjectsPtr loadLibraryFromMetafile(const std::string& libName) const;
93
94     WrtPluginsApi::PluginRegistry m_registry;
95     bool m_initialized;
96     bool m_reinstall;
97 };
98
99 typedef DPL::Singleton<PluginsInstaller> PluginsInstallerSingleton;
100
101 #endif  /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H */
102