Some trivial update
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 2 May 2025 09:06:27 +0000 (18:06 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 12 May 2025 03:36:49 +0000 (12:36 +0900)
Changes:
 - Adds to print return value into get_action command.
 - Adds a description parameter to Result struct.
 - Removes a value parameter from ActionParameter.

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/action/action_request_handler.cc
src/common/action_parameter.cc
src/common/action_parameter.h
src/common/action_schema.cc
test/unit_tests/action_parameter_test.cc
tidl/tizen_action_datatype.tidl
tool/action_tool/tools/get_action.cc

index 70d7967a28bf0bf4093b1b9056ec2bf745e96a90..53e3b4e99da50e53086c6cca0dfb25680ded98ca 100644 (file)
@@ -46,8 +46,9 @@ std::string GetPkgId(pid_t pid, uid_t uid) {
   return std::string(buf);
 }
 
-bool CheckPrivileges(pid_t pid, uid_t uid,
-    const std::vector<std::string>& privileges) {
+bool CheckPrivileges(pid_t pid,
+                     uid_t uid,
+                     const std::vector<std::string>& privileges) {
   std::string pkgid = GetPkgId(pid, uid);
   if (pkgid.empty()) {
     // bypass
@@ -67,12 +68,14 @@ bool CheckPrivileges(pid_t pid, uid_t uid,
   }
 
   std::unordered_set<std::string> privs(privileges.begin(), privileges.end());
-  ret = pkgmgrinfo_pkginfo_foreach_privilege(handle,
+  ret = pkgmgrinfo_pkginfo_foreach_privilege(
+      handle,
       [](const char* priv, void* user_data) -> int {
         auto set = static_cast<std::unordered_set<std::string>*>(user_data);
         set->erase(priv);
         return 0;
-      }, &privs);
+      },
+      &privs);
   pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   if (ret != PMINFO_R_OK) {
     LOG(ERROR) << "Failed to get privileges";
@@ -181,6 +184,18 @@ rpc::ActionSchema ActionRequestHandler::OnGetAction(const std::string& id) {
     actionparams.push_back(param);
   }
   action.Setparameters(std::move(actionparams));
+
+  std::vector<rpc::Result> actionreturns;
+  auto returns = schema.GetReturns();
+  for (auto const& iter : returns) {
+    auto return_param = rpc::Result(
+        iter.GetName(), GetStringFromParameterType(iter.GetType()),
+        iter.GetDescription());
+
+    actionreturns.push_back(std::move(return_param));
+  }
+
+  action.Setresults(std::move(actionreturns));
   action.Setprivileges(schema.GetPrivileges());
 
   action.Setjson(schema.GetJsonString());
index eb76eb1defd6e74094d18f1490411d640166a92e..c2a3db6f6cc55252806495c0ea7f1450e3e069c6 100644 (file)
@@ -20,8 +20,8 @@ namespace common {
 
 ActionParameter::ActionParameter() : type_(ParameterType::InvalidType), is_required_(false) {}
 
-ActionParameter::ActionParameter(std::string name, ParameterType type, std::string value, std::string description, bool is_required)
-  : name_(std::move(name)), type_(type), value_(std::move(value)), description_(std::move(description)), is_required_(is_required) {
+ActionParameter::ActionParameter(std::string name, ParameterType type, std::string description, bool is_required)
+  : name_(std::move(name)), type_(type), description_(std::move(description)), is_required_(is_required) {
 }
 
 const std::string& ActionParameter::GetName() const {
@@ -40,14 +40,6 @@ void ActionParameter::SetType(ParameterType type) {
   type_ = type;
 }
 
-const std::string& ActionParameter::GetValue() const {
-  return value_;
-}
-
-void ActionParameter::SetValue(std::string value) {
-  value_ = std::move(value);
-}
-
 const std::string& ActionParameter::GetDescription() const {
   return description_;
 }
index 1d0a9ca43fda705098a4f7a58fc931a0f1576d41..751fe4b616a9a5ded6ffc112d9e9d0b89e785381 100644 (file)
@@ -34,7 +34,7 @@ enum class ParameterType {
 class ActionParameter {
  public:
   ActionParameter();
-  ActionParameter(std::string name, ParameterType type, std::string value, std::string description, bool is_required);
+  ActionParameter(std::string name, ParameterType type, std::string description, bool is_required);
 
   const std::string& GetName() const;
   void SetName(std::string name);
@@ -42,9 +42,6 @@ class ActionParameter {
   const ParameterType GetType() const;
   void SetType(ParameterType type);
 
-  const std::string& GetValue() const;
-  void SetValue(std::string value);
-
   const std::string& GetDescription() const;
   void SetDescription(std::string description);
 
@@ -54,7 +51,6 @@ class ActionParameter {
  private:
   std::string name_;
   ParameterType type_;
-  std::string value_;
   std::string description_;
   bool is_required_;
 };
index ece2f3b8d8274b40c44ffe82295f5b9e5adc7a00..cb3915931fcf5040a5083735c9962313c535768e 100644 (file)
@@ -79,7 +79,7 @@ ActionSchema::ActionSchema(std::string json_str)
         is_required = false;
       }
 
-      parameters_.emplace_back(name, type, "", description, is_required);
+      parameters_.emplace_back(name, type, description, is_required);
     }
 
     // returns
@@ -88,7 +88,7 @@ ActionSchema::ActionSchema(std::string json_str)
           SafeJson::get<std::string>(*value, "type"));
       std::string description = SafeJson::get<std::string>(*value, "desc");
       // ActionParameterType -> another class???
-      returns_.emplace_back(name, type, "", description, false);
+      returns_.emplace_back(name, type, description, false);
     }
 
     try {
index 27a8c3711111d1f7c38f40b95d5d65085c9eb736..00838f57b4f48fdd96e19e2320b60099c3b516df 100644 (file)
@@ -6,7 +6,7 @@ namespace common {
 class ActionParameterTest : public ::testing::Test {
 protected:
     void SetUp() override {
-        param_ = new ActionParameter("test_name", ParameterType::StringType, "test_value", "test_description", true);
+        param_ = new ActionParameter("test_name", ParameterType::StringType, "test_description", true);
     }
 
     void TearDown() override {
@@ -34,15 +34,6 @@ TEST_F(ActionParameterTest, SetTypeTest) {
     EXPECT_EQ(param_->GetType(), ParameterType::IntType);
 }
 
-TEST_F(ActionParameterTest, GetValueTest) {
-    EXPECT_EQ(param_->GetValue(), "test_value");
-}
-
-TEST_F(ActionParameterTest, SetValueTest) {
-    param_->SetValue("new_value");
-    EXPECT_EQ(param_->GetValue(), "new_value");
-}
-
 TEST_F(ActionParameterTest, GetDescriptionTest) {
     EXPECT_EQ(param_->GetDescription(), "test_description");
 }
index fbe76f86664f6359aaa5fe6d5caea7d4b119b8d9..a28318a3817842349b91906a1401653ce518584e 100644 (file)
@@ -10,6 +10,7 @@ struct Parameter {
 struct Result {
     string key;
     string type;
+    string description;
 }
 
 struct ActionSchema {
index 89d2d655751c0a60035ee88452ed2368ac82e270..f03d5b2774cb6707a7a3e478ba69a6d40a7521b6 100644 (file)
@@ -90,6 +90,15 @@ class GetAction : public ActionTool,
           _D("- required: %s\n", parameter.Getis_requied() ? "true" : "false");
         }
       }
+
+      if (!action.Getresults().empty()) {
+        _D("results:");
+        for (const auto& result : action.Getresults()) {
+          _D("- key: %s", result.Getkey().c_str());
+          _D("- type: %s", result.Gettype().c_str());
+          _D("- description: %s", result.Getdescription().c_str());
+        }
+      }
     } catch (...) {
       _E("GetAction Failed");
       return -1;