10e5f9e8e13bd3b8a59c72045fbbefae4e32678a
[platform/core/appfw/wgt-backend.git] / src / wgt / step / configuration / step_parse.h
1 // Copyright (c) 2015 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.
4 #ifndef WGT_STEP_CONFIGURATION_STEP_PARSE_H_
5 #define WGT_STEP_CONFIGURATION_STEP_PARSE_H_
6
7 #include <boost/filesystem.hpp>
8
9 #include <common/app_installer.h>
10 #include <common/installer_context.h>
11 #include <common/step/step.h>
12
13 #include <manifest_parser/utils/logging.h>
14 #include <wgt_manifest_handlers/permissions_handler.h>
15 #include <wgt_manifest_handlers/widget_config_parser.h>
16
17 #include <type_traits>
18 #include <cassert>
19 #include <memory>
20 #include <set>
21 #include <string>
22
23 namespace wgt {
24 namespace configuration {
25
26 /**
27  * \brief This step parse config.xml configuration file of widget
28  */
29 class StepParse : public common_installer::Step {
30  public:
31   enum class ConfigLocation {
32     PACKAGE,      // parse config file from unpacking diretory
33     INSTALLED,    // parse config file from current package installation
34     RECOVERY,     // parse config file from backup location or package location
35     RESOURCE_WGT  // parse config file from unpacking subdiretory "res/wgt"
36   };
37
38   explicit StepParse(common_installer::InstallerContext* context,
39       ConfigLocation config_location, bool check_start_file);
40
41   Status process() override;
42   Status clean() override { return Status::OK; }
43   Status undo() override { return Status::OK; }
44   Status precheck() override { return Status::OK; }
45
46  protected:
47   virtual bool LocateConfigFile();
48   bool Check(const boost::filesystem::path& widget_path);
49
50   boost::filesystem::path widget_path_;
51
52  private:
53   std::set<std::string> ExtractPrivileges(
54       std::shared_ptr<const wgt::parse::PermissionsInfo> perm_info) const;
55
56   std::string GetPackageVersion(const std::string& manifest_version);
57
58   bool FillInstallationInfo(manifest_x* manifest);
59   bool FillIconPaths(manifest_x* manifest);
60   bool FillWidgetInfo(manifest_x* manifest);
61   bool FillMainApplicationInfo(manifest_x* manifest);
62   bool FillServiceApplicationInfo(manifest_x* manifest);
63   bool FillWidgetApplicationInfo(manifest_x* manifest);
64   bool FillAppControl(manifest_x* manifest);
65   bool FillPrivileges(manifest_x* manifest);
66   bool FillAppDefinedPrivileges(manifest_x* manifest);
67   bool FillProvidesAppDefinedPrivileges(manifest_x* manifest);
68   bool FillCategories(manifest_x* manifest);
69   bool FillMetadata(manifest_x* manifest);
70   bool FillExtraManifestInfo(manifest_x* manifest);
71   bool FillAccounts(manifest_x* manifest);
72   bool FillImeInfo();
73   bool FillAppWidget();
74   bool FillBackgroundCategoryInfo(manifest_x* manifest);
75   bool FillAdditionalApplications(manifest_x* manifest);
76   bool FillManifestX(manifest_x* manifest);
77
78   std::unique_ptr<wgt::parse::WidgetConfigParser> parser_;
79   ConfigLocation config_location_;
80   bool check_start_file_;
81
82   template<typename T>
83   std::shared_ptr<const T> GetManifestDataForKey(const std::string& key) {
84       assert(!key.empty());
85       static_assert(std::is_base_of<parser::ManifestData, T>::value,
86               "Type is not base of parser::ManifestData");
87       return std::static_pointer_cast<const T>(parser_->GetManifestData(key));
88   }
89
90   STEP_NAME(Parse)
91 };
92
93 }  // namespace configuration
94 }  // namespace wgt
95
96 #endif  // WGT_STEP_CONFIGURATION_STEP_PARSE_H_