Parse and generate service application element in wgt-backend 81/49881/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 20 Oct 2015 14:44:06 +0000 (16:44 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 27 Oct 2015 12:30:22 +0000 (13:30 +0100)
wgt::parse::StepParse should use ServiceInfo from manifest handler
to generate information for <service-application> tag in platform
manifest file.

Requires submit: https://review.tizen.org/gerrit/49880

Change-Id: I1e83ef5800c1b335e0845adb5a5d39b306cc3748

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

index 68ec2c5..909b1b9 100644 (file)
@@ -150,7 +150,7 @@ bool StepParse::FillDescription(manifest_x* manifest) {
 
   description_x* description = reinterpret_cast<description_x*>
       (calloc(1, sizeof(description_x)));
-  description->text = strdup(description_info->description().c_str());
+  description->name = strdup(description_info->description().c_str());
   description->lang = strdup(description_info->xml_lang().c_str());
   manifest->description = g_list_append(manifest->description, description);
   return true;
index d9752ca..fb188af 100755 (executable)
@@ -12,6 +12,7 @@
 #include <manifest_handlers/category_handler.h>
 #include <manifest_handlers/content_handler.h>
 #include <manifest_handlers/metadata_handler.h>
+#include <manifest_handlers/service_handler.h>
 #include <manifest_handlers/setting_handler.h>
 #include <manifest_handlers/tizen_application_handler.h>
 #include <manifest_handlers/widget_handler.h>
@@ -164,11 +165,11 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) {
   return true;
 }
 
-bool StepParse::FillApplicationInfo(manifest_x* manifest) {
+bool StepParse::FillUIApplicationInfo(manifest_x* manifest) {
   std::shared_ptr<const TizenApplicationInfo> app_info =
       std::static_pointer_cast<const TizenApplicationInfo>(
           parser_->GetManifestData(app_keys::kTizenApplicationKey));
-  if (!app_info.get()) {
+  if (!app_info) {
     LOG(ERROR) << "Application info manifest data has not been found.";
     return false;
   }
@@ -191,6 +192,58 @@ bool StepParse::FillApplicationInfo(manifest_x* manifest) {
   return true;
 }
 
+bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
+  std::shared_ptr<const ServiceList> service_list =
+      std::static_pointer_cast<const ServiceList>(
+          parser_->GetManifestData(app_keys::kTizenServiceKey));
+  if (!service_list)
+    return true;
+  for (auto& service_info : service_list->services) {
+    application_x* application = reinterpret_cast<application_x*>
+        (calloc(1, sizeof(application_x)));
+    application->component_type = strdup("svcapp");
+    application->appid = strdup(service_info.id().c_str());
+    application->type = strdup("webapp");
+    application->onboot =
+        service_info.on_boot() ? strdup("true") : strdup("false");
+    application->autorestart =
+        service_info.auto_restart() ? strdup("true") : strdup("false");
+
+    for (auto& pair : service_info.names()) {
+      label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+      if (!pair.first.empty())
+        label->lang = strdup(pair.first.c_str());
+      label->name = strdup(pair.second.c_str());
+      application->label = g_list_append(application->label, label);
+    }
+
+    if (!service_info.icon().empty()) {
+      icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+      icon->text = strdup(service_info.icon().c_str());
+      application->icon = g_list_append(application->icon, icon);
+    }
+
+    // TODO(t.iwanek): what about description, how is it different from name?
+
+    for (auto& category : service_info.categories()) {
+      application->category = g_list_append(application->category,
+                                            strdup(category.c_str()));
+    }
+
+    for (auto& pair : service_info.metadata_set()) {
+      metadata_x* item = reinterpret_cast<metadata_x*>(
+          calloc(1, sizeof(metadata_x)));
+      item->key = strdup(pair.first.c_str());
+      if (!pair.second.empty())
+        item->value = strdup(pair.second.c_str());
+      application->metadata = g_list_append(application->metadata, item);
+    }
+
+    manifest->application = g_list_append(manifest->application, application);
+  }
+  return true;
+}
+
 bool StepParse::FillAppControl(manifest_x* manifest) {
   std::shared_ptr<const AppControlInfoList> app_info_list =
       std::static_pointer_cast<const AppControlInfoList>(
@@ -283,7 +336,7 @@ bool StepParse::FillExtraManifestInfo(manifest_x* manifest) {
 bool StepParse::FillManifestX(manifest_x* manifest) {
   if (!FillIconPaths(manifest))
     return false;
-  if (!FillApplicationInfo(manifest))
+  if (!FillUIApplicationInfo(manifest))
     return false;
   if (!FillWidgetInfo(manifest))
     return false;
@@ -295,6 +348,12 @@ bool StepParse::FillManifestX(manifest_x* manifest) {
     return false;
   if (!FillMetadata(manifest))
     return false;
+  // TODO(t.iwanek): fix adding ui application element
+  // for now adding application service is added here because rest of code
+  // assumes that there is one application at manifest->application
+  // so this must execute last
+  if (!FillServiceApplicationInfo(manifest))
+    return false;
   if (!FillExtraManifestInfo(manifest))
     return false;
   return true;
@@ -317,7 +376,11 @@ common_installer::Step::Status StepParse::process() {
   }
   if (check_start_file_) {
     if (!parser_->HasValidStartFile()) {
-      LOG(ERROR) << "No valid start file" <<  parser_->GetErrorMessage();
+      LOG(ERROR) << parser_->GetErrorMessage();
+      return common_installer::Step::Status::ERROR;
+    }
+    if (!parser_->HasValidServicesStartFiles()) {
+      LOG(ERROR) << parser_->GetErrorMessage();
       return common_installer::Step::Status::ERROR;
     }
   }
index 19b5631..d204397 100644 (file)
@@ -45,7 +45,8 @@ class StepParse : public common_installer::Step {
 
   bool FillIconPaths(manifest_x* manifest);
   bool FillWidgetInfo(manifest_x* manifest);
-  bool FillApplicationInfo(manifest_x* manifest);
+  bool FillUIApplicationInfo(manifest_x* manifest);
+  bool FillServiceApplicationInfo(manifest_x* manifest);
   bool FillAppControl(manifest_x* manifest);
   bool FillPrivileges(manifest_x* manifest);
   bool FillCategories(manifest_x* manifest);