Implements ApplicationData
authorYongseop Kim <yons.kim@samsung.com>
Thu, 9 Apr 2015 07:26:14 +0000 (16:26 +0900)
committerYongseop Kim <yons.kim@samsung.com>
Thu, 16 Apr 2015 01:20:33 +0000 (10:20 +0900)
Change-Id: If3675851c6cd4d6daf7cce86db2ed7fb47d93c78

packaging/wrt.spec
src/runtime/CMakeLists.txt
src/runtime/application_data.cc [new file with mode: 0644]
src/runtime/application_data.h [new file with mode: 0644]

index 46cd16a..a709ff7 100755 (executable)
@@ -17,9 +17,14 @@ BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(manifest-parser)
+BuildRequires: pkgconfig(manifest-handlers)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
 BuildRequires: pkgconfig(efl-assist)
 BuildRequires: pkgconfig(deviced)
 BuildRequires: pkgconfig(capi-system-runtime-info)
+BuildRequires: pkgconfig(cert-svc)
+BuildRequires: boost-devel
 %if %{with x}
 BuildRequires: pkgconfig(ecore-x)
 %endif
index 665c9a5..e32d301 100755 (executable)
@@ -18,12 +18,17 @@ PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS
   elementary
   capi-appfw-application
   chromium-efl
+  manifest-parser
+  manifest-handlers
+  capi-appfw-package-manager
   efl-assist
   deviced
   capi-system-runtime-info
   REQUIRED
 )
 
+FIND_PACKAGE(Boost REQUIRED system filesystem)
+
 # Include Directories
 SET(TARGET_RUNTIME_INCS
   ${BASE_SRCDIR}
@@ -33,6 +38,7 @@ SET(TARGET_RUNTIME_INCS
 # Libraries
 SET(TARGET_RUNTIME_LIBS
   ${TARGET_RUNTIME_DEPS_LIBRARIES}
+  ${Boost_LIBRARIES}
 )
 
 # Source Files
diff --git a/src/runtime/application_data.cc b/src/runtime/application_data.cc
new file mode 100644 (file)
index 0000000..f3cd14e
--- /dev/null
@@ -0,0 +1,209 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "runtime/application_data.h"
+
+#include <package_manager.h>
+#include <parser/manifest_parser.h>
+#include <parser/manifest_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/app_control_handler.h>
+#include <manifest_handlers/category_handler.h>
+#include <manifest_handlers/ime_handler.h>
+#include <manifest_handlers/metadata_handler.h>
+#include <manifest_handlers/navigation_handler.h>
+#include <manifest_handlers/permissions_handler.h>
+#include <manifest_handlers/service_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>
+
+#include <vector>
+
+namespace wrt {
+
+namespace {
+
+const char* kPathSeparator = "/";
+const char* kConfigXml = "config.xml";
+
+static std::string GetPackageIdByAppId(const std::string& appid) {
+  char* pkgid = NULL;
+  package_manager_get_package_id_by_app_id(appid.c_str(), &pkgid);
+
+  std::unique_ptr<char, decltype(std::free)*>
+    pkgid_ptr {pkgid, std::free};
+
+  if (pkgid != NULL) {
+    return std::string(pkgid_ptr.get());
+  } else {
+    return std::string();
+  }
+}
+
+static std::string GetPackageRootPath(const std::string& pkgid) {
+  package_info_h pkg_info = NULL;
+  if (package_manager_get_package_info(
+        pkgid.c_str(), &pkg_info) != PACKAGE_MANAGER_ERROR_NONE) {
+    return std::string();
+  }
+
+  char* pkg_root_path = NULL;
+  package_info_get_root_path(pkg_info, &pkg_root_path);
+
+  std::unique_ptr<char, decltype(std::free)*>
+    path_ptr {pkg_root_path, std::free};
+
+  package_info_destroy(pkg_info);
+
+  if (pkg_root_path != NULL) {
+    return std::string(path_ptr.get());
+  } else {
+    return std::string();
+  }
+}
+
+}  // namespace
+
+ApplicationData::ApplicationData(const std::string& appid) : app_id_(appid) {
+  pkg_id_ = GetPackageIdByAppId(appid);
+
+  if (!pkg_id_.empty()) {
+    pkg_root_path_ = GetPackageRootPath(pkg_id_);
+  }
+
+  if (!pkg_root_path_.empty()) {
+    config_xml_path_ = pkg_root_path_ + kPathSeparator +
+                       app_id_ + kPathSeparator + kConfigXml;
+  }
+
+  LoadManifestData();
+}
+
+ApplicationData::~ApplicationData() {}
+
+bool ApplicationData::LoadManifestData() {
+  if (config_xml_path_.empty()) {
+    return false;
+  }
+
+  enum ManifestHandlerType {
+    APPLICATION_ICONS_HANDLER = 0,
+    APP_WIDGET_HANDLER,
+    APP_CONTROL_HANDLER,
+    CATEGORY_HANDLER,
+    IME_HANDLER,
+    META_DATA_HANDLER,
+    NAVIGATION_HANDLER,
+    PERMISSIONS_HANDLER,
+    SERVICE_HANDLER,
+    SETTING_HANDLER,
+    SPLASH_SCREEN_HANDLER,
+    TIZEN_APPLICATION_HANDLER,
+    WIDGET_HANDLER
+  };
+
+  std::vector<parser::ManifestHandler*> handlers = {
+    new wgt::parse::ApplicationIconsHandler,  // APPLICATION_ICONS_HANDLER
+    new wgt::parse::AppWidgetHandler,         // APP_WIDGET_HANDLER
+    new wgt::parse::AppControlHandler,        // APP_CONTROL_HANDLER
+    new wgt::parse::CategoryHandler,          // CATEGORY_HANDLER
+    new wgt::parse::ImeHandler,               // IME_HANDLER
+    new wgt::parse::MetaDataHandler,          // META_DATA_HANDLER
+    new wgt::parse::NavigationHandler,        // NAVIGATION_HANDLER
+    new wgt::parse::PermissionsHandler,       // PERMISSIONS_HANDLER
+    new wgt::parse::ServiceHandler,           // SERVICE_HANDLER
+    new wgt::parse::SettingHandler,           // SETTING_HANDLER
+    new wgt::parse::SplashScreenHandler,      // SPLASH_SCREEN_HANDLER
+    new wgt::parse::TizenApplicationHandler,  // TIZEN_APPLICATION_HANDLER
+    new wgt::parse::WidgetHandler             // WIDGET_HANDLER
+  };
+
+  std::unique_ptr<parser::ManifestHandlerRegistry> registry;
+  registry.reset(new parser::ManifestHandlerRegistry(handlers));
+
+  parser::ManifestParser manifest_parser(std::move(registry));
+  if (!manifest_parser.ParseManifest(config_xml_path_)) {
+    for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
+      delete *iter;
+    }
+    return false;
+  }
+
+  application_icons_info_ =
+    std::static_pointer_cast<const wgt::parse::ApplicationIconsInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::APPLICATION_ICONS_HANDLER]->Key()));
+
+  app_widget_info_ =
+    std::static_pointer_cast<const wgt::parse::AppWidgetInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::APP_WIDGET_HANDLER]->Key()));
+
+  app_control_info_list_ =
+    std::static_pointer_cast<const wgt::parse::AppControlInfoList>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::APP_CONTROL_HANDLER]->Key()));
+
+  category_info_list_ =
+    std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::CATEGORY_HANDLER]->Key()));
+
+  ime_info_ =
+    std::static_pointer_cast<const wgt::parse::ImeInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::IME_HANDLER]->Key()));
+
+  meta_data_info_ =
+    std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::META_DATA_HANDLER]->Key()));
+
+  navigation_info_ =
+    std::static_pointer_cast<const wgt::parse::NavigationInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::NAVIGATION_HANDLER]->Key()));
+
+  permissions_info_ =
+    std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::PERMISSIONS_HANDLER]->Key()));
+
+  service_list_ =
+    std::static_pointer_cast<const wgt::parse::ServiceList>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::SERVICE_HANDLER]->Key()));
+
+  setting_info_ =
+    std::static_pointer_cast<const wgt::parse::SettingInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::SETTING_HANDLER]->Key()));
+
+  splash_screen_info_ =
+    std::static_pointer_cast<const wgt::parse::SplashScreenInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::SPLASH_SCREEN_HANDLER]->Key()));
+
+  tizen_application_info_ =
+    std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::TIZEN_APPLICATION_HANDLER]->Key()));
+
+  widget_info_ =
+    std::static_pointer_cast<const wgt::parse::WidgetInfo>(
+      manifest_parser.GetManifestData(
+        handlers[ManifestHandlerType::WIDGET_HANDLER]->Key()));
+
+  for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
+    delete *iter;
+  }
+
+  return true;
+}
+
+}  // namespace wrt
diff --git a/src/runtime/application_data.h b/src/runtime/application_data.h
new file mode 100644 (file)
index 0000000..eaaf02a
--- /dev/null
@@ -0,0 +1,131 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_RUNTIME_APPLICATION_DATA_H_
+#define WRT_RUNTIME_APPLICATION_DATA_H_
+
+#include <memory>
+#include <string>
+
+namespace wgt {
+
+namespace parse {
+
+class ApplicationIconsInfo;
+class AppWidgetInfo;
+struct AppControlInfoList;
+struct CategoryInfoList;
+class ImeInfo;
+class MetaDataInfo;
+class NavigationInfo;
+class PermissionsInfo;
+struct ServiceList;
+class SettingInfo;
+class SplashScreenInfo;
+class TizenApplicationInfo;
+class WidgetInfo;
+
+}  // namespace parse
+
+}  // namespace wgt
+
+namespace wrt {
+
+class ApplicationData {
+ public:
+  explicit ApplicationData(const std::string& appid);
+  ~ApplicationData();
+
+  std::shared_ptr<const wgt::parse::ApplicationIconsInfo>
+  application_icons_info() const {
+    return application_icons_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::AppWidgetInfo> app_widget_info() const {
+    return app_widget_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::AppControlInfoList>
+  app_control_info() const {
+    return app_control_info_list_;
+  }
+
+  std::shared_ptr<const wgt::parse::CategoryInfoList>
+  category_info_list() const {
+    return category_info_list_;
+  }
+
+  std::shared_ptr<const wgt::parse::ImeInfo> ime_info() const {
+    return ime_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::MetaDataInfo> meta_data_info() const {
+    return meta_data_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::NavigationInfo> navigation_info() const {
+    return navigation_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::PermissionsInfo>
+  permissions_info() const {
+    return permissions_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::ServiceList> service_list() const {
+    return service_list_;
+  }
+
+  std::shared_ptr<const wgt::parse::SettingInfo> setting_info() const {
+    return setting_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::SplashScreenInfo>
+  splash_screen_info() const {
+    return splash_screen_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::TizenApplicationInfo>
+  tizen_application_info() const {
+    return tizen_application_info_;
+  }
+
+  std::shared_ptr<const wgt::parse::WidgetInfo> widget_info() const {
+    return widget_info_;
+  }
+
+  std::string config_xml_path() const { return config_xml_path_; }
+  const std::string pkg_root_path() const { return pkg_root_path_; }
+  const std::string pkg_id() const { return pkg_id_; }
+  const std::string app_id() const { return app_id_; }
+
+ private:
+  bool LoadManifestData();
+
+  std::shared_ptr<const wgt::parse::ApplicationIconsInfo>
+    application_icons_info_;
+  std::shared_ptr<const wgt::parse::AppWidgetInfo> app_widget_info_;
+  std::shared_ptr<const wgt::parse::AppControlInfoList>
+    app_control_info_list_;
+  std::shared_ptr<const wgt::parse::CategoryInfoList> category_info_list_;
+  std::shared_ptr<const wgt::parse::ImeInfo> ime_info_;
+  std::shared_ptr<const wgt::parse::MetaDataInfo> meta_data_info_;
+  std::shared_ptr<const wgt::parse::NavigationInfo> navigation_info_;
+  std::shared_ptr<const wgt::parse::PermissionsInfo> permissions_info_;
+  std::shared_ptr<const wgt::parse::ServiceList> service_list_;
+  std::shared_ptr<const wgt::parse::SettingInfo> setting_info_;
+  std::shared_ptr<const wgt::parse::SplashScreenInfo> splash_screen_info_;
+  std::shared_ptr<const wgt::parse::TizenApplicationInfo>
+    tizen_application_info_;
+  std::shared_ptr<const wgt::parse::WidgetInfo> widget_info_;
+
+  std::string config_xml_path_;
+  std::string pkg_root_path_;
+  std::string pkg_id_;
+  std::string app_id_;
+};
+
+}  // namespace wrt
+
+#endif  // WRT_RUNTIME_APPLICATION_DATA_H_