[Manifest parser] Separate filling manifest_x into few steps 89/37989/2
authorJakub Izydorczyk <j.izydorczyk@samsung.com>
Fri, 3 Apr 2015 12:44:39 +0000 (14:44 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Thu, 9 Apr 2015 08:23:26 +0000 (01:23 -0700)
Separate filling manifest_x structure into steps:
- filling widget info
- filling application info
- filling icon paths
- filling privileges
- filling app control

Change-Id: Ie4ea566bb797d2b7af196899663ff74342a1b493

src/wgt/step/step_parse.cc
src/wgt/step/step_parse.h

index 8c3f93b..0b0d720 100644 (file)
@@ -18,8 +18,6 @@
 
 #include "parser/manifest_handler.h"
 #include "parser/manifest_constants.h"
-#include "manifest_handlers/app_control_handler.h"
-#include "manifest_handlers/application_icons_handler.h"
 #include "manifest_handlers/application_manifest_constants.h"
 #include "manifest_handlers/appwidget_handler.h"
 #include "manifest_handlers/category_handler.h"
@@ -28,8 +26,7 @@
 #include "manifest_handlers/navigation_handler.h"
 #include "manifest_handlers/setting_handler.h"
 #include "manifest_handlers/splash_screen_handler.h"
-#include "manifest_handlers/tizen_application_handler.h"
-#include "manifest_handlers/widget_handler.h"
+
 
 namespace wgt {
 namespace parse {
@@ -42,16 +39,30 @@ std::set<std::string> StepParse::ExtractPrivileges(
   return perm_info->GetAPIPermissions();
 }
 
-bool StepParse::FillManifestX(manifest_x* manifest) {
-  std::string api_version, short_name, version;
-  std::shared_ptr<const TizenApplicationInfo> app_info =
-      std::static_pointer_cast<const TizenApplicationInfo>(
-          parser_->GetManifestData(app_keys::kTizenApplicationKey));
-  if (!app_info.get()) {
-    LOG(ERROR) << "Application info manifest data has not been found.";
-    return false;
+const std::string& StepParse::GetPackageVersion(
+     const std::string& manifest_version) {
+  if (!manifest_version.empty())
+    return manifest_version;
+  return "1.0.0";
+}
+
+bool StepParse::FillIconPaths(manifest_x* manifest) {
+  std::shared_ptr<const ApplicationIconsInfo> icons_info =
+      std::static_pointer_cast<const ApplicationIconsInfo>(
+          parser_->GetManifestData(manifest_keys::kIconsKey));
+  if (icons_info.get()) {
+    std::vector<std::string> icons = icons_info->get_icon_paths();
+    for (std::string icon_str : icons) {
+      icon_x* icon = reinterpret_cast<icon_x*> (calloc(1, sizeof(icon_x)));
+      icon->name = strdup(icon_str.c_str());
+      LISTADD(manifest->icon, icon);
+    }
   }
-  api_version = app_info->required_version();
+  return true;
+}
+
+bool StepParse::FillWidgetInfo(manifest_x* manifest) {
+  std::string short_name, version;
   std::shared_ptr<const WidgetInfo> wgt_info =
       std::static_pointer_cast<const WidgetInfo>(parser_->GetManifestData(
           parser::kWidgetKey));
@@ -62,74 +73,45 @@ bool StepParse::FillManifestX(manifest_x* manifest) {
   wgt_info->GetWidgetInfo()->GetString(app_keys::kShortNameKey, &short_name);
   wgt_info->GetWidgetInfo()->GetString(app_keys::kVersionKey, &version);
 
-  if (!version.empty())
-    manifest->version = strdup(version.c_str());
-  else
-    manifest->version = strdup("1.0.0");
-
-  // application data
-  manifest->serviceapplication = nullptr;
-  manifest->uiapplication = reinterpret_cast<uiapplication_x*>
-    (calloc (1, sizeof(uiapplication_x)));
-  manifest->uiapplication->label = reinterpret_cast<label_x*>
-    (calloc(1, sizeof(label_x)));
-  manifest->uiapplication->appcontrol = nullptr;
-
-  manifest->uiapplication->appid = strdup(app_info->id().c_str());
-  manifest->uiapplication->type = strdup("webapp");
-
-  // package data
-  manifest->package = strdup(app_info->package().c_str());
-  manifest->mainapp_id = strdup(app_info->id().c_str());
-
-  manifest->type = strdup("wgt");
-
+  manifest->version = strdup(GetPackageVersion(version).c_str());
   description_x* description = reinterpret_cast<description_x*>
       (calloc(1, sizeof(description_x)));
   std::string name;
   wgt_info->GetWidgetInfo()->GetString(manifest_keys::kNameKey, &name);
   description->name = strdup(name.c_str());
   manifest->description = description;
-  manifest->label =
-      reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
-  manifest->label->name = strdup(name.c_str());
 
-  // icons
-  std::shared_ptr<const ApplicationIconsInfo> icons_info =
-      std::static_pointer_cast<const ApplicationIconsInfo>(
-          parser_->GetManifestData(manifest_keys::kIconsKey));
-  if (icons_info.get()) {
-    std::vector<std::string> icons = icons_info->get_icon_paths();
-    for (std::string icon_str : icons) {
-      icon_x* icon = reinterpret_cast<icon_x*> (calloc(1, sizeof(icon_x)));
-      icon->name = strdup(icon_str.c_str());
-      LISTADD(manifest->icon, icon);
-    }
-  }
+  manifest->label->name = strdup(name.c_str());
 
-  // privileges
-  std::shared_ptr<const PermissionsInfo> perm_info =
-      std::static_pointer_cast<const PermissionsInfo>(parser_->GetManifestData(
-          app_keys::kTizenPermissionsKey));
-  std::set<std::string> privileges;
-  privileges.insert({"priv"});
-  privileges.clear();
-  if (perm_info)
-    privileges = ExtractPrivileges(perm_info);
+  // For wgt package use the long name if the short name is empty
+  if (!short_name.empty())
+    manifest->uiapplication->label->name = strdup(short_name.c_str());
+  else
+    manifest->uiapplication->label->name =
+        strdup(manifest->description->name);
+  return true;
+}
 
-  if (!privileges.empty()) {
-    privileges_x* privileges_x_list =
-        reinterpret_cast<privileges_x*> (calloc(1, sizeof(privileges_x)));\
-    manifest->privileges = privileges_x_list;
-    for (const std::string& p : privileges) {
-      privilege_x* privilege_x_node =
-          reinterpret_cast<privilege_x*> (calloc(1, sizeof(privilege_x)));
-      privilege_x_node->text = strdup(p.c_str());
-      LISTADD(manifest->privileges->privilege, privilege_x_node);
-    }
+bool StepParse::FillApplicationInfo(manifest_x* manifest) {
+  std::string api_version;
+  std::shared_ptr<const TizenApplicationInfo> app_info =
+      std::static_pointer_cast<const TizenApplicationInfo>(
+          parser_->GetManifestData(app_keys::kTizenApplicationKey));
+  if (!app_info.get()) {
+    LOG(ERROR) << "Application info manifest data has not been found.";
+    return false;
   }
+  api_version = app_info->required_version();
+  manifest->uiapplication->appid = strdup(app_info->id().c_str());
+  manifest->uiapplication->type = strdup("webapp");
+  manifest->package = strdup(app_info->package().c_str());
+  manifest->mainapp_id = strdup(app_info->id().c_str());
+  manifest->type = strdup("wgt");
 
-  // appcontrol
+  return true;
+}
+
+bool StepParse::FillAppControl(manifest_x* manifest) {
   std::shared_ptr<const AppControlInfoList> app_info_list =
       std::static_pointer_cast<const AppControlInfoList>(
           parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey));
@@ -150,16 +132,56 @@ bool StepParse::FillManifestX(manifest_x* manifest) {
       LISTADD(manifest->uiapplication->appcontrol, app_control);
     }
   }
+  return true;
+}
 
-  // For wgt package use the long name if the short name is empty
-  if (!short_name.empty())
-    manifest->uiapplication->label->name = strdup(short_name.c_str());
-  else
-    manifest->uiapplication->label->name =
-        strdup(manifest->description->name);
+bool StepParse::FillPrivileges(manifest_x* manifest) {
+  std::shared_ptr<const PermissionsInfo> perm_info =
+      std::static_pointer_cast<const PermissionsInfo>(parser_->GetManifestData(
+          app_keys::kTizenPermissionsKey));
+  std::set<std::string> privileges;
+  privileges.insert({"priv"});
+  privileges.clear();
+  if (perm_info)
+    privileges = ExtractPrivileges(perm_info);
 
+  if (!privileges.empty()) {
+    privileges_x* privileges_x_list =
+        reinterpret_cast<privileges_x*> (calloc(1, sizeof(privileges_x)));\
+    manifest->privileges = privileges_x_list;
+    for (const std::string& p : privileges) {
+      privilege_x* privilege_x_node =
+          reinterpret_cast<privilege_x*> (calloc(1, sizeof(privilege_x)));
+      privilege_x_node->text = strdup(p.c_str());
+      LISTADD(manifest->privileges->privilege, privilege_x_node);
+    }
+  }
+  return true;
+}
+
+bool StepParse::FillManifestX(manifest_x* manifest) {
+  // application data
+  manifest->serviceapplication = nullptr;
+  manifest->uiapplication = reinterpret_cast<uiapplication_x*>
+    (calloc (1, sizeof(uiapplication_x)));
+  manifest->uiapplication->label = reinterpret_cast<label_x*>
+    (calloc(1, sizeof(label_x)));
+  manifest->uiapplication->appcontrol = nullptr;
+  manifest->label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
   manifest->uiapplication->icon =
       reinterpret_cast<icon_x*> (calloc(1, sizeof(icon_x)));
+
+  if (!FillWidgetInfo(manifest))
+    return false;
+  if (!FillApplicationInfo(manifest))
+    return false;
+  if (!FillIconPaths(manifest))
+    return false;
+  if (!FillPrivileges(manifest))
+    return false;
+  if (!FillAppControl(manifest))
+    return false;
+
   if (manifest->icon)
     manifest->uiapplication->icon->name = strdup(manifest->icon->name);
   manifest->uiapplication->next = nullptr;
index 6e4b76b..d50636d 100644 (file)
 #include "common/app_installer.h"
 #include "common/context_installer.h"
 #include "common/step/step.h"
+#include "manifest_handlers/app_control_handler.h"
+#include "manifest_handlers/application_icons_handler.h"
+#include "manifest_handlers/permissions_handler.h"
+#include "manifest_handlers/tizen_application_handler.h"
+#include "manifest_handlers/widget_handler.h"
 #include "parser/manifest_parser.h"
 #include "utils/logging.h"
-#include "manifest_handlers/permissions_handler.h"
 
 namespace wgt {
 namespace parse {
@@ -30,6 +34,14 @@ class StepParse : public common_installer::Step {
  private:
   std::set<std::string> ExtractPrivileges(
       std::shared_ptr<const PermissionsInfo> perm_info) const;
+
+  const std::string& GetPackageVersion(const std::string& manifest_version);
+
+  bool FillIconPaths(manifest_x* manifest);
+  bool FillWidgetInfo(manifest_x* manifest);
+  bool FillApplicationInfo(manifest_x* manifest);
+  bool FillAppControl(manifest_x* manifest);
+  bool FillPrivileges(manifest_x* manifest);
   bool FillManifestX(manifest_x* manifest);
 
   std::unique_ptr<parser::ManifestParser> parser_;