Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / 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 <plugin_installer_types.h>
28 #include <plugin_objects.h>
29 #include <IObject.h>
30 #include <PluginRegistry.h>
31
32 #include <dpl/singleton.h>
33
34 class PluginsInstaller
35 {
36   public:
37     static const int INSTALLATION_ERROR;
38     enum class ReturnStatus
39     {
40         Success,                    ///< Success
41
42         NotInitialized,             ///< Singleton not initialized
43         WrongPluginPath,            ///< ?
44         MetafileError,              ///< ?
45         AlreadyInstalled,           ///< ?
46         LoadingLibraryError,        ///< Loading library by dlopen failed.
47                                     /// It may be caused by missing symbols
48         InstallationWaiting,        /// Installation failed due to dependencies
49         DatabaseError,              /// Unable to update database
50         Unknown                     ///< Temporary error. Try to not use this.
51     };
52
53     bool initialize();
54     int installAllPlugins();
55     void deinitialize();
56
57     ReturnStatus installPlugin(const std::string& libPath);
58     ReturnStatus installPluginFromMetafile(const std::string& libPath,
59                                            const std::string& metaFilePath);
60
61     int installWaitingPlugins();
62     bool resolvePluginDependencies(PluginHandle handle);
63
64     bool isInitialized();
65
66   private:
67     friend class DPL::Singleton<PluginsInstaller>;
68
69     PluginsInstaller();
70     virtual ~PluginsInstaller();
71
72     void registerObjects(const PluginObjectsPtr& libObj,
73                          const WrtPluginsApi::IObjectsListPtr& objects) const;
74
75     typedef DPL::Optional<WrtDB::PluginMetafileData> OptionalPluginMetafileData;
76     OptionalPluginMetafileData parseMetafile(const std::string& path) const;
77
78     std::string getLibraryName(const std::string& dirPath) const;
79     bool registerAndUpdateInstallation(const PluginHandle& pluginHandle,
80                                        const PluginObjectsPtr& libraries);
81     bool fillMappingInterfaces(WrtDB::PluginMetafileData& pluginData,
82                                const std::string& filename);
83     void registerPluginObjects(const PluginHandle& handle,
84                                const PluginObjectsPtr libObjects) const;
85     void checkDatabaseTablesExistance();
86     PluginObjectsPtr loadLibraryFromMetafile(const std::string& libName) const;
87
88     WrtPluginsApi::PluginRegistry m_registry;
89     bool m_initialized;
90     bool m_reinstall;
91 };
92
93 typedef DPL::Singleton<PluginsInstaller> PluginsInstallerSingleton;
94
95 #endif  /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H */
96