899be3cfbfcb3e85af9e64be5f80f8afd5d0fc4d
[platform/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 <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 private:
66     friend class DPL::Singleton<PluginsInstaller>;
67
68     PluginsInstaller();
69     virtual ~PluginsInstaller();
70
71     void registerObjects(const PluginObjectsPtr& libObj,
72                          const WrtPluginsApi::IObjectsListPtr& objects) const;
73
74     typedef DPL::Optional<WrtDB::PluginMetafileData> OptionalPluginMetafileData;
75     OptionalPluginMetafileData parseMetafile(const std::string& path) const;
76
77     std::string getLibraryName(const std::string& dirPath) const;
78     bool registerAndUpdateInstallation(const PluginHandle& pluginHandle,
79                                        const PluginObjectsPtr& libraries);
80     bool fillMappingInterfaces(WrtDB::PluginMetafileData& pluginData,
81                                const std::string& filename);
82     void registerPluginObjects(const PluginHandle& handle,
83                                const PluginObjectsPtr libObjects) const;
84     void checkDatabaseTablesExistance();
85     PluginObjectsPtr loadLibraryFromMetafile(const std::string& libName) const;
86
87     WrtPluginsApi::PluginRegistry m_registry;
88     bool m_initialized;
89     bool m_reinstall;
90 };
91
92 typedef DPL::Singleton<PluginsInstaller> PluginsInstallerSingleton;
93
94
95 #endif  /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H */
96