Add light user element parsing logic 03/274003/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 20 Apr 2022 02:29:29 +0000 (11:29 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 20 Apr 2022 02:29:29 +0000 (11:29 +0900)
Change-Id: I5082bb698bab04a501f8140bb4094c2b77c66ee4
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/tpk_manifest_handlers/light_user_handler.cc [new file with mode: 0644]
src/tpk_manifest_handlers/light_user_handler.h [new file with mode: 0644]
src/tpk_manifest_handlers/tpk_config_parser.cc

diff --git a/src/tpk_manifest_handlers/light_user_handler.cc b/src/tpk_manifest_handlers/light_user_handler.cc
new file mode 100644 (file)
index 0000000..ff8d7dd
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk_manifest_handlers/light_user_handler.h"
+
+#include "manifest_parser/values.h"
+
+namespace tpk {
+namespace parse {
+
+namespace {
+
+const char kLightUserKey[] = "manifest.light-user";
+const char kLightUserSwitchModeKey[] = "@switch-mode";
+
+void ParseLightUserAndStore(
+    const parser::DictionaryValue& light_user_dict,
+    LightUserInfo* light_user) {
+  std::string switch_mode;
+  light_user_dict.GetString(kLightUserSwitchModeKey, &switch_mode);
+  light_user->set_switch_mode(switch_mode);
+}
+
+}  // namespace
+
+bool LightUserHandler::Parse(
+    const parser::Manifest& manifest,
+    std::shared_ptr<parser::ManifestData>* output,
+    std::string* /*error*/) {
+  std::shared_ptr<LightUserInfo> light_user(new LightUserInfo());
+
+  auto items = parser::GetOneOrMany(manifest.value(), kLightUserKey, "");
+  if (items.empty())
+    return true;
+
+  ParseLightUserAndStore(*items[0], light_user.get());
+
+  *output = std::static_pointer_cast<parser::ManifestData>(light_user);
+  return true;
+}
+
+std::string LightUserInfo::Key() {
+  return kLightUserKey;
+}
+
+std::string LightUserHandler::Key() const {
+  return kLightUserKey;
+}
+
+}  // namespace parse
+}  // namespace tpk
diff --git a/src/tpk_manifest_handlers/light_user_handler.h b/src/tpk_manifest_handlers/light_user_handler.h
new file mode 100644 (file)
index 0000000..d2a3d20
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_MANIFEST_HANDLERS_LIGHT_USER_HANDLER_H_
+#define TPK_MANIFEST_HANDLERS_LIGHT_USER_HANDLER_H_
+
+#include <memory>
+#include <string>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace tpk {
+namespace parse {
+
+class LightUserInfo : public parser::ManifestData {
+ public:
+  /**
+   * @brief key
+   * @param key string
+   */
+  static std::string Key();
+  /**
+   * @brief set_switch_mode sets switch_mode
+   * @param switch_mode
+   */
+  void set_switch_mode(std::string switch_mode) {
+    switch_mode_ = std::move(switch_mode);
+  }
+  /**
+   * @brief switch_mode
+   * @return switch_mode string
+   */
+  const std::string& switch_mode() const {
+    return switch_mode_;
+  }
+
+ private:
+  std::string switch_mode_;
+};
+
+/**
+ * @brief The LightUserHandler class
+ *
+ * Handler of tizen-manifest.xml for xml elements:
+ *  <light-user>
+ */
+class LightUserHandler : public parser::ManifestHandler {
+ public:
+  bool Parse(
+      const parser::Manifest& manifest,
+      std::shared_ptr<parser::ManifestData>* output,
+      std::string* error) override;
+  std::string Key() const override;
+};
+
+}  // namespace parse
+}  // namespace tpk
+
+#endif  // TPK_MANIFEST_HANDLERS_LIGHT_USER_HANDLER_H_
index 096deede92fd64ed6a78829d61b1d7f92bab3226..9a2f5586bffafba43d45e9f030fe06db34242e26 100644 (file)
@@ -19,6 +19,7 @@
 #include "tpk_manifest_handlers/dependencies_handler.h"
 #include "tpk_manifest_handlers/description_handler.h"
 #include "tpk_manifest_handlers/feature_handler.h"
+#include "tpk_manifest_handlers/light_user_handler.h"
 #include "tpk_manifest_handlers/package_handler.h"
 #include "tpk_manifest_handlers/privileges_handler.h"
 #include "tpk_manifest_handlers/profile_handler.h"
@@ -60,6 +61,7 @@ TPKConfigParser::TPKConfigParser() {
     std::make_shared<TrustAnchorHandler>(),
     std::make_shared<DependenciesHandler>(),
     std::make_shared<ComponentBasedApplicationHandler>(),
+    std::make_shared<LightUserHandler>(),
   };
 
   std::unique_ptr<parser::ManifestHandlerRegistry> registry(