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