Add category attribute to action
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 14 Apr 2025 05:43:15 +0000 (14:43 +0900)
committer장상윤/Tizen Platform Lab(SR)/삼성전자 <jeremy.jang@samsung.com>
Mon, 14 Apr 2025 07:56:52 +0000 (16:56 +0900)
category is for enhancing efficiency of getting actions.

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/action/action_request_handler.cc
src/action/sqlite_db.cc
src/action/utils/action_model_converter.cc
src/common/action_model.cc
src/common/action_model.h
src/pkgmgr_plugin_parser/action_schema.hh
src/pkgmgr_plugin_parser/json_action_schema_parser.cc
src/pkgmgr_plugin_parser/sqlite_db.cc
tidl/tizen_action_datatype.tidl
tool/action_tool/tools/get_action.cc
tool/action_tool/tools/list_actions.cc

index 394108b979f33981adb4da99a1204cc3dcbcc3c2..a0d34d473b12ae0430fb0c8b5038f114040791cf 100644 (file)
@@ -64,6 +64,7 @@ std::vector<rpc::Action> ActionRequestHandler::OnListActions() {
     rpc::Action action;
     action.Setaction_id(model.GetActionId());
     action.Setapp_id(model.GetAppId());
+    action.Setcategory(model.GetCategory());
     action.Setdescription(model.GetDescription());
     action.Settype("app_control");  // TODO
     // action.Setparameters();
@@ -81,6 +82,7 @@ rpc::Action ActionRequestHandler::OnGetAction(const std::string& id) {
   rpc::Action action;
   action.Setaction_id(model.GetActionId());
   action.Setapp_id(model.GetAppId());
+  action.Setcategory(model.GetCategory());
   action.Setdescription(model.GetDescription());
   action.Settype("app_control");  // TODO
   // action.Seturi();
index 5617d95056a97a2c0695531f275f2a9b7f686933..52533175cdb6e17eae2fc0936096cfcaa6267f03 100644 (file)
@@ -24,7 +24,8 @@ namespace {
 
 constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
 constexpr char kGetActionQuery[] =
-    "SELECT pkgid, action_name, json_str FROM action WHERE action_name = ?";
+    "SELECT pkgid, action_name, category, json_str "
+    "FROM action WHERE action_name = ?";
 constexpr char kListActionQuery[] =
     "SELECT json_str FROM action;";
 
@@ -67,10 +68,11 @@ std::string SqliteDb::Select(const std::string& name) {
     return {};
   }
 
-  auto [pkgid, action_name, json_str] =
-      (*rec).Get<tizen_base::_, tizen_base::_, tizen_base::_>();
+  auto [pkgid, action_name, category, json_str] =
+      (*rec).Get<tizen_base::_, tizen_base::_, tizen_base::_, tizen_base::_>();
   LOG(DEBUG) << "pkgid: " << static_cast<std::string>(pkgid)
       << ", name: " << static_cast<std::string>(action_name)
+      << ", category: " << static_cast<std::string>(category)
       << ", json_str: " << static_cast<std::string>(json_str);
 
   // TODO: tmp fix
index 529ebc17dd12ccfc2d597b94b198b8076e799f6a..c7791fc3cc1ad2f76b7eb54dd507c45d06acc7ed 100644 (file)
@@ -10,6 +10,7 @@ plugin_proxy::Action ActionModelConverter::ConvertToAction(
   plugin_proxy::Action action;
   action.Setaction_id(model.GetActionId());
   action.Setapp_id(model.GetAppId());
+  action.Setcategory(model.GetCategory());
   action.Setdescription(model.GetDescription());
   auto parameters = std::vector<plugin_proxy::Parameter>();
   for (auto const& param : model.GetParameters()) {
index f46c3b69c672fca9bec6effd8dd12fe79a54b269..e50c71e87faeb59aeba49076d2f51522e89aa0ca 100644 (file)
@@ -74,8 +74,9 @@ ActionModel::ActionModel(const std::string& json_str) {
 
     action_id_ = root["name"].asString();
     app_id_ = root["appId"].asString();
-    type_ = GetActionTypeFromString(root["type"].asString());
+    category_ = root["category"].asString();
     description_ = root["desc"].asString();
+    type_ = GetActionTypeFromString(root["type"].asString());
 
     // params
     for (auto const& it : root["params"].getMemberNames()) {
@@ -103,11 +104,12 @@ ActionModel::ActionModel(const std::string& json_str) {
 }
 
 ActionModel::ActionModel(std::string action_id, std::string app_id,
-    std::string description, std::vector<ActionParameter> parameters,
+    std::string category, std::string description,
+    std::vector<ActionParameter> parameters,
     std::vector<std::string> privileges)
     : action_id_(std::move(action_id)), app_id_(std::move(app_id)),
-      description_(std::move(description)), parameters_(std::move(parameters)),
-      privileges_(std::move(privileges)) {
+      category_(std::move(category)), description_(std::move(description)),
+      parameters_(std::move(parameters)), privileges_(std::move(privileges)) {
 }
 
 const std::string& ActionModel::GetActionId() const {
@@ -126,6 +128,14 @@ void ActionModel::SetAppId(std::string app_id) {
   app_id_ = std::move(app_id);
 }
 
+const std::string& ActionModel::GetCategory() const {
+  return category_;
+}
+
+void ActionModel::SetCategory(std::string category) {
+  category_ = std::move(category);
+}
+
 const ActionType ActionModel::GetType() const {
   return type_;
 }
index cbc3b81b19f27f931ef968ff48abe20e6c2e0760..6d388fbb2187b1693e2f1c7e4a2224125dac897d 100644 (file)
@@ -33,7 +33,8 @@ class ActionModel {
   ActionModel();
   explicit ActionModel(const std::string& json_str);
   explicit ActionModel(std::string action_id, std::string app_id,
-      std::string description, std::vector<ActionParameter> parameters,
+      std::string category, std::string description,
+      std::vector<ActionParameter> parameters,
       std::vector<std::string> privileges);
 
   const std::string& GetActionId() const;
@@ -42,6 +43,9 @@ class ActionModel {
   const std::string& GetAppId() const;
   void SetAppId(std::string app_id);
 
+  const std::string& GetCategory() const;
+  void SetCategory(std::string category);
+
   const ActionType GetType() const;
   void SetType(ActionType type);
 
@@ -60,6 +64,7 @@ class ActionModel {
  private:
   std::string action_id_;
   std::string app_id_;
+  std::string category_;
   ActionType type_ = ActionType::InvalidType;
   std::string description_;
 
index 16710a52d919aabd6439a0ac4be8f057ff142ff0..a1c0af52ce3932684d1c3fd21142753cc3bd542f 100644 (file)
@@ -24,19 +24,22 @@ namespace parser {
 
 class ActionSchema {
  public:
-  explicit ActionSchema(std::string pkgid, std::string name, std::string json_str)
+  explicit ActionSchema(std::string pkgid, std::string name,
+      std::string category, std::string json_str)
       : pkgid_(std::move(pkgid)), name_(std::move(name)),
-        json_str_(std::move(json_str)) {}
+        category_(std::move(category)), json_str_(std::move(json_str)) {}
   ActionSchema() = default;
   ~ActionSchema() = default;
 
   std::string GetPkgId() const { return pkgid_; }
   std::string GetName() const { return name_; }
+  std::string GetCategory() const { return category_; }
   std::string GetJsonStr() const { return json_str_; }
 
  private:
   std::string pkgid_;
   std::string name_;
+  std::string category_;
   std::string json_str_;
 };
 
index b0c4a2af00f6f108a91a1e62a13033b2582ae168..d24c980e3d267e9adea94c8b2640fd5088fe31d1 100644 (file)
@@ -52,12 +52,13 @@ ActionSchema JsonActionSchemaParser::Parse(const std::string& pkgid,
 
   // TODO
   std::string name = root["name"].asString();
+  std::string category = root["category"].asString();
   std::string json_str = JsonToString(root);
 
   LOG(DEBUG) << "Parased action for pkgid[ " << pkgid << " ] : " << name;
   LOG(DEBUG) << json_str;
 
-  return ActionSchema(pkgid, name, json_str);
+  return ActionSchema(pkgid, name, category, json_str);
 }
 
 }  // namespace parser
index 645fa9a234c604a5b0e3620097f6436656b0ff63..9b688c9a2e8e861f3de24dec6ca34e5abf442b34 100644 (file)
@@ -27,11 +27,12 @@ constexpr char kCreateActionTableQuery[] =
     "CREATE TABLE IF NOT EXISTS action (\n"
     "  pkgid       TEXT,\n"
     "  action_name TEXT,\n"
+    "  category    TEXT,\n"
     "  json_str    TEXT,\n"
     "  PRIMARY KEY (pkgid, action_name))";
 constexpr char kInsertQuery[] =
-    "INSERT INTO action (pkgid, action_name, json_str) "
-    "VALUES (?, ?, ?)";
+    "INSERT INTO action (pkgid, action_name, category, json_str) "
+    "VALUES (?, ?, ?, ?)";
 constexpr char kDeleteQuery[] =
     "DELETE FROM action WHERE pkgid = ?";
 constexpr char kSelectQuery[] =
@@ -54,6 +55,7 @@ bool SqliteDb::Install(const std::string& pkgid, const std::vector<ActionSchema>
       sql.Reset()
         .Bind(pkgid)
         .Bind(schema.GetName())
+        .Bind(schema.GetCategory())
         .Bind(schema.GetJsonStr());
       auto result = conn_.Exec(sql);
       if (!static_cast<bool>(result)) {
@@ -87,6 +89,7 @@ bool SqliteDb::Update(const std::string& pkgid, const std::vector<ActionSchema>&
       sql.Reset()
         .Bind(pkgid)
         .Bind(schema.GetName())
+        .Bind(schema.GetCategory())
         .Bind(schema.GetJsonStr());
       result = conn_.Exec(sql);
       if (!result) {
index a92874d5217c7a9b8ad1ea8394c35937b106496a..566e3053dbed02a33d49ad600605668453bb7fad 100644 (file)
@@ -16,6 +16,7 @@ struct Result {
 struct Action {
     string action_id;
     string app_id;
+    string category;
     string description;
     string type;
     array<Parameter> parameters;
index 878aa5f050d15952fe4c5ab496c968ab4b997b9a..d99393bdea4cce7e201dc898a677b94582c1bf4a 100644 (file)
@@ -72,6 +72,7 @@ class GetAction : public ActionTool,
       auto action = proxy_.GetAction(std::move(action_id));
       _D("id: %s --------------------", action.Getaction_id().c_str());
       _D("appid: %s", action.Getapp_id().c_str());
+      _D("category: %s", action.Getcategory().c_str());
       _D("description: %s", action.Getdescription().c_str());
 
       if (!action.Getprivileges().empty()) {
index 7656540de8dc0c0be93c5d15b06bacd2b419d322..f96235886436e3cddc99401c336bfc74b8300761 100644 (file)
@@ -65,6 +65,7 @@ class ListActions : public ActionTool,
       for (auto action : actions) {
         _D("id: %s --------------------", action.Getaction_id().c_str());
         _D("appid: %s", action.Getapp_id().c_str());
+        _D("category: %s", action.Getcategory().c_str());
         _D("description: %s", action.Getdescription().c_str());
 
         if (!action.Getprivileges().empty()) {