Add ActionModel and execute sequence
authorSukhyungKang <shine.kang@samsung.com>
Tue, 25 Feb 2025 04:54:22 +0000 (13:54 +0900)
committerSukhyungKang <shine.kang@samsung.com>
Tue, 25 Feb 2025 07:27:21 +0000 (16:27 +0900)
- [usage] execute <action id> <app_control/plugin> <parameter1:value> ...

- ex) # action_fw_tool execute show-toast app_control text:test timeout:300 type:toast

Signed-off-by: SukhyungKang <shine.kang@samsung.com>
16 files changed:
src/action/action_request_handler.cc
src/action/action_request_handler.hh
src/action/app_control_executor.cc
src/action/app_control_executor.hh
src/action/request_handler.hh
src/action/service.cc
src/action/service.hh
src/common/action_model.cc
src/common/action_model.h
src/common/action_parameter.cc
src/common/action_parameter.h
src/service/tizen-manifest.xml
tidl/prebuild.sh [changed mode: 0644->0755]
tidl/tizen_actions.tidl
tool/action_fw_tool/tools/execute.cc
tool/action_fw_tool/tools/get_action.cc

index 235af50c42e18ae33679578ab3f7b9011c51e284..12dbb4b41de000407cbd507a0442f12b5c90c73c 100644 (file)
 #include <string>
 
 #include "action/action_request_handler.hh"
+#include "action/app_control_executor.hh"
 #include "action/service.hh"
 #include "action/sqlite_db.hh"
+#include "common/utils/logging.hh"
 
 namespace action {
 
@@ -47,8 +49,17 @@ void ActionRequestHandler::OnGetActionId(std::string user_description, int top_k
     float search_threshold) {
 }
 
-void ActionRequestHandler::OnExecute(std::string launch_req) {
+void ActionRequestHandler::OnExecute(common::ActionModel& model) {
+  LOG(DEBUG) << "OnExecute action : " << model.GetActionId() << ", appid : " << model.GetAppId();
 
+  if (model.GetType() == common::ActionType::AppControl) {
+    LOG(DEBUG) << "execute appcontrol";
+
+    AppControlExecutor executor;
+    executor.Execute(model);
+  } else if (model.GetType() == common::ActionType::Plugin) {
+    LOG(DEBUG) << "execute plugin";
+  }
 }
 
 }  // namespace action
index 3b84fc1f084e7956236970298007db7d031a5f0a..5ec8d12d5f38e0d1a3d4ab07c8c3bcebeb4c1e30 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "action/request_handler.hh"
 #include "action/tizen_action_service_stub.h"
+#include "common/action_model.h"
 
 using Action = rpc_port::tizen_action_service_stub::Action;
 
@@ -36,7 +37,7 @@ class ActionRequestHandler : public IRequestHandler {
   void OnGetAction(std::string id) override;
   void OnGetActionId(std::string user_description, int top_k,
       float search_threshold) override;
-  void OnExecute(std::string request) override;
+  void OnExecute(common::ActionModel& model) override;
 
  private:
   rpc_port::tizen_action_service_stub::stub::ActionService service_;
index 81948214c1edf33b5ef6b56418f611afb4bb1a15..d8365102948f1bbac121d7386377820387630902 100644 (file)
@@ -37,6 +37,12 @@ app_control_h ConvertToAppControl(const common::ActionModel& action_model) {
   }
 
   // TODO: Convert to app_control handle from action model
+  app_control_set_app_id(handle, action_model.GetAppId().c_str());
+
+  auto params = action_model.GetParameters();
+
+  for (auto const& iter : params)
+    LOG(DEBUG) << "param name : " << iter.GetName() << ", val : " << iter.GetValue() << ", type : " << static_cast<int>(iter.GetType());
 
   return handle;
 }
@@ -46,6 +52,8 @@ app_control_h ConvertToAppControl(const common::ActionModel& action_model) {
 namespace action {
 
 int AppControlExecutor::Execute(const common::ActionModel& model) {
+  LOG(ERROR) << "AppControl Execute : " << model.GetAppId();
+
   app_control_h app_control = ConvertToAppControl(model);
 
   std::unique_ptr<AppControlSender> sender =
index a58019980a5e7ea81ee085bdb67c92553e9e9242..d33083ee4f6d8e3b850baee611281e1b976ac807 100644 (file)
@@ -27,8 +27,8 @@ namespace action {
 
 class AppControlExecutor : public common::IActionExecutor {
  public:
-  AppControlExecutor();
-  ~AppControlExecutor();
+  AppControlExecutor() = default;
+  ~AppControlExecutor() = default;
   int Execute(const common::ActionModel& model) override;
   void OnReply(const std::string& reply) override;
 
index 5c3c25af1e17ca0436aa4d5ae926716c627bfee6..d271133dac397e9ff91732d54f80069c736f5f69 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <string>
 
+#include "common/action_model.h"
+
 namespace action {
 
 class IRequestHandler {
@@ -28,7 +30,7 @@ class IRequestHandler {
   virtual void OnGetAction(std::string id) = 0;
   virtual void OnGetActionId(std::string user_description, int top_k,
       float search_threshold) = 0;
-  virtual void OnExecute(std::string launch_req) = 0;
+  virtual void OnExecute(common::ActionModel& model) = 0;
 };
 
 }  // namespace action
index 48d27b5b7ec93b0130f385e52ca7bfb0ee55e07e..53ab4cdde1ae6fbda236b9862d144e017f37648d 100644 (file)
 #include "action/sqlite_db.hh"
 #include "action/utils/json_parser.hh"
 #include "common/utils/logging.hh"
+#include "common/action_model.h"
+
+namespace {
+
+common::ActionType GetActionType(std::string type) {
+  if (type.compare("app_control") == 0)
+    return common::ActionType::AppControl;
+  else if (type.compare("plugin") == 0)
+    return common::ActionType::Plugin;
+
+  return common::ActionType::InvalidType;
+}
+
+common::ParameterType GetParameterType(std::string type) {
+  LOG(DEBUG) << "GetParmameterType : " << type;
+
+  if (type.compare("integer") == 0)
+    return common::ParameterType::IntType;
+  else if (type.compare("string") == 0)
+    return common::ParameterType::StringType;
+  else if (type.compare("double") == 0)
+    return common::ParameterType::DoubleType;
+  else if (type.compare("bool") == 0)
+    return common::ParameterType::BoolType;
+
+  return common::ParameterType::InvalidType;
+}
+
+}
 
 namespace action {
 
@@ -39,7 +68,8 @@ std::vector<rs::Action> Service::ListActions() {
 
 rs::Action Service::GetAction(std::string action_id) {
   // return action by id
-  // handler_->GetAction(action_id);
+  // ActionModel action = handler_.OnGetAction(action_id);
+
   LOG(DEBUG) << "GetAction : " << action_id;
 
   action::SqliteDb sqlite_db;
@@ -63,7 +93,7 @@ rs::Action Service::GetAction(std::string action_id) {
   for (auto const& iter : params) {
     auto param_value = iter.second;
 
-    auto param = rs::Parameter(iter.first, param_value["type"], param_value["desc"],
+    auto param = rs::Parameter(iter.first, param_value["type"], "", param_value["desc"],
                               param_value["isMandatory"].compare("true") == 0 ? true : false);
 
     actionparams.push_back(param);
@@ -85,9 +115,46 @@ std::vector<rs::VectorDbResult> Service::GetActionId(
   return {};
 }
 
-int Service::Execute(std::string launch_req) {
-  // return action exetution result
-  // handler_->Execute(std::move(launch_req));
+int Service::Execute(rs::Action action) {
+  LOG(DEBUG) << "Execute : " << action.Getaction_id() << ", type : " << action.Gettype();
+
+  std::string action_id = action.Getaction_id();
+  action::SqliteDb sqlite_db;
+
+  std::string result = sqlite_db.Select(action_id);
+  if (result.empty()) {
+    LOG(DEBUG) << "Not exsit action";
+    return -1;
+  }
+
+  common::ActionModel model;
+  std::vector<common::ActionParameter> actionparams;
+  auto ps = new utils::JsonParser(result);
+
+  auto params = ps->GetParameters();
+  auto param_values = action.Getparameters();
+
+  model.SetActionId(action.Getaction_id());
+  model.SetAppId(ps->GetAppId());
+  model.SetType(GetActionType(action.Gettype()));
+
+  for (auto const& iter : param_values) {
+    std::string param_name = iter.Getkey();
+    auto param_schema = params[param_name];
+
+    common::ParameterType param_type = GetParameterType(param_schema["type"]);
+
+    LOG(DEBUG) << "param key : " << param_name << ", val : " << iter.Getvalue() << ", type : " << param_schema["type"];
+
+    auto param = common::ActionParameter(param_name, param_type, iter.Getvalue(),
+                  iter.Getdescription(), iter.Getis_requied());
+
+    actionparams.push_back(param);
+  }
+  model.SetParameters(actionparams);
+
+  handler_.OnExecute(model);
+
   return 0;
 }
 
index a027b1c38218caf4b251f542456e0d95681e07d1..2bf1dac6b0b4d4012eb82d96e231a3e6fc45f347 100644 (file)
@@ -52,7 +52,7 @@ class Service : public rs::stub::ActionService::ServiceBase {
   rs::Action GetAction(std::string action_id) override;
   std::vector<rs::VectorDbResult> GetActionId(std::string user_description,
       int top_k, float search_threshold) override;
-  int Execute(std::string launch_req) override;
+  int Execute(rs::Action action) override;
 
  private:
   IRequestHandler& handler_;
index f89ceee9f3d413dc9e6763a5666837bfa2c85f8c..01ac715377a0b7d1a28e1b8da3df288a125effe7 100644 (file)
 
 namespace common {
 
+ActionModel::ActionModel() {}
+
+ActionModel::ActionModel(std::string action_id, std::string app_id,
+      std::string label, std::string description, std::string uri,
+      std::string mime, std::string operation, std::vector<ActionParameter> parameters,
+      std::vector<std::string> privileges)
+    : action_id_(std::move(action_id)), app_id_(std::move(app_id)), label_(std::move(label)),
+      description_(std::move(description)), uri_(std::move(uri)), mime_(std::move(mime)),
+      operation_(std::move(operation)), parameters_(std::move(parameters)), privileges_(std::move(privileges)) {
+}
+
+const std::string& ActionModel::GetActionId() const {
+  return action_id_;
+}
+
+void ActionModel::SetActionId(std::string action_id) {
+  action_id_ = std::move(action_id);
+}
+
+const std::string& ActionModel::GetAppId() const {
+  return app_id_;
+}
+
+void ActionModel::SetAppId(std::string app_id) {
+  app_id_ = std::move(app_id);
+}
+
+const ActionType ActionModel::GetType() const {
+  return type_;
+}
+
+void ActionModel::SetType(ActionType type) {
+  type_ = type;
+}
+
+const std::string& ActionModel::GetLabel() const {
+  return label_;
+}
+
+void ActionModel::SetLabel(std::string label) {
+  label_ = std::move(label);
+}
+
+const std::string& ActionModel::GetDescription() const {
+  return description_;
+}
+
+void ActionModel::SetDescription(std::string description) {
+  description_ = std::move(description);
+}
+
+const std::string& ActionModel::GetUri() const {
+  return uri_;
+}
+
+void ActionModel::SetUri(std::string uri) {
+  uri_ = std::move(uri);
+}
+
+const std::string& ActionModel::GetMime() const {
+  return mime_;
+}
+
+void ActionModel::SetMime(std::string mime) {
+  mime_ = std::move(mime);
+}
+
+const std::string& ActionModel::GetOperation() const {
+  return operation_;
+}
+
+void ActionModel::SetOperation(std::string operation) {
+  operation_ = std::move(operation);
+}
+
+const std::vector<ActionParameter>& ActionModel::GetParameters() const {
+  return parameters_;
+}
+
+void ActionModel::SetParameters(std::vector<ActionParameter> parameters) {
+  parameters_ = std::move(parameters);
+}
+
+const std::vector<std::string>& ActionModel::GetPrivileges() const {
+  return privileges_;
+}
+
+void ActionModel::SetPrivileges(std::vector<std::string> privileges) {
+  privileges_ = std::move(privileges);
+}
+
 }  // namespace common
index 2e2bf397caebab9b239703be9331f26e3e83f9fb..eb1074526a0fb8489093d49747863dfec4b319c0 100644 (file)
@@ -24,16 +24,63 @@ namespace common {
 
 enum class ActionType {
   AppControl = 0,
-  Plugin = 1
+  Plugin = 1,
+  InvalidType = 100
 };
 
 class ActionModel {
  public:
-  ActionModel() = default;
-  ~ActionModel() = default;
+  ActionModel();
+  ActionModel(std::string action_id, std::string app_id,
+      std::string label, std::string description, std::string uri,
+      std::string mime, std::string operation, std::vector<ActionParameter> parameters,
+      std::vector<std::string> privileges);
+
+  const std::string& GetActionId() const;
+  void SetActionId(std::string action_id);
+
+  const std::string& GetAppId() const;
+  void SetAppId(std::string app_id);
+
+  const ActionType GetType() const;
+  void SetType(ActionType type);
+
+  const std::string& GetLabel() const;
+  void SetLabel(std::string label);
+
+  const std::string& GetDescription() const;
+  void SetDescription(std::string description);
+
+  const std::string& GetUri() const;
+  void SetUri(std::string uri);
+
+  const std::string& GetMime() const;
+  void SetMime(std::string mime);
+
+  const std::string& GetOperation() const;
+  void SetOperation(std::string operation);
+
+  const std::vector<ActionParameter>& GetParameters() const;
+  void SetParameters(std::vector<ActionParameter> parameters);
+
+  const std::vector<std::string>& GetPrivileges() const;
+  void SetPrivileges(std::vector<std::string> privileges);
 
  private:
-  std::vector<ActionParameter> params_;
+  std::string action_id_;
+  std::string app_id_;
+  ActionType type_;
+  std::string label_;
+  std::string description_;
+  std::string uri_;
+  std::string mime_;
+  std::string operation_;
+
+  //is std::map better?
+  std::vector<ActionParameter> parameters_;
+
+  // std::vector<Result> results_;
+  std::vector<std::string> privileges_;
 };
 
 }   // namespace common
index 4714e57ba84a6474bc93527b25a1ee0b9a101ba0..46b289a3296b18672be8b33e18535aad95b4caf7 100644 (file)
 
 namespace common {
 
+ActionParameter::ActionParameter() {}
+
+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) {
+}
+
+const std::string& ActionParameter::GetName() const {
+  return name_;
+}
+
+void ActionParameter::SetName(std::string name) {
+  name_ = std::move(name);
+}
+
+const ParameterType ActionParameter::GetType() const {
+  return type_;
+}
+
+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_;
+}
+
+void ActionParameter::SetDescription(std::string description) {
+  description_ = std::move(description);
+}
+
+bool ActionParameter::GetIsRequired() const {
+  return is_required_;
+}
+
+void ActionParameter::SetIsRequired(bool is_required) {
+  is_required_ = is_required;
+}
+
 }  // namespace common
index 1b70b0ebd99de29a515e554ac37bfe511228c274..920c355739fb5d152aa7d5bec599e1c9744e9cdb 100644 (file)
 namespace common {
 
 enum class ParameterType {
-  IntType = 1,
-  StringType = 0
+  IntType = 0,
+  StringType = 1,
+  DoubleType = 2,
+  BoolType = 3,
+  InvalidType = 100
 };
 
 class ActionParameter {
  public:
-  ActionParameter() = default;
-  ~ActionParameter();
+  ActionParameter();
+  ActionParameter(std::string name, ParameterType type, std::string value, std::string description, bool is_required);
+
+  const std::string& GetName() const;
+  void SetName(std::string name);
+
+  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);
+
+  bool GetIsRequired() const;
+  void SetIsRequired(bool is_required);
 
  private:
-  ParameterType type_;
   std::string name_;
+  ParameterType type_;
+  std::string value_;
   std::string description_;
   bool is_required_;
 };
index 868e82ff8724eb48e9cb52b99573d356c4288deb..cc18e799699e09f9e98f1ecd8da09ca519164b63 100644 (file)
@@ -5,4 +5,7 @@
         <icon>TizenActionFrameworkService.png</icon>
         <label>TizenActionFrameworkService</label>
        </service-application>
+    <privileges>
+               <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+       </privileges>
 </manifest>
old mode 100644 (file)
new mode 100755 (executable)
index 58e01719a54811e38e1b3c5110b2c19dbfa144ae..7a7587bf25ed0eac051b49195cb28c924fa39ad7 100644 (file)
@@ -3,6 +3,7 @@ protocol 2
 struct Parameter {
     string key;
     string type;
+    string value;
     string description;
     bool is_requied;
 }
@@ -17,6 +18,7 @@ struct Action {
     string app_id;
     string label;
     string description;
+    string type;
     string uri;
     string mime;
     string operation;
@@ -34,5 +36,5 @@ interface ActionService {
     array<Action> ListActions();
     Action GetAction(string action_id);
     array<VectorDbResult> GetActionId(string user_description, int top_k, float search_threshold);
-    int Execute(string launch_req);
+    int Execute(Action action);
 }
index 5c1683bf2cb95fd53087f5609fb5d48a7900c20f..f74f795e19954e62a00e8ef88be62d27e5e5df53 100644 (file)
@@ -30,7 +30,7 @@ class Execute : public ActionFwTool,
                       IEventListener {
  public:
   Execute()
-      : ActionFwTool("execute", "Execute", "execute <launch_request(string)>"),
+      : ActionFwTool("execute", "Execute", "execute <action id> <app_control/plugin> <parameter1:value> ..."),
         proxy_(this, kStubAppId) {}
 
   virtual ~Execute() {}
@@ -61,19 +61,46 @@ class Execute : public ActionFwTool,
   }
 
   int Run(int argc, char** argv) override {
-    if (argc < 3) {
+    if (argc < 4) {
       Usage();
       return -1;
     }
 
-    std::string launch_req = std::string(argv[2]);
+    rpc_port::tizen_action_service_proxy::Action action;
+    std::vector<rpc_port::tizen_action_service_proxy::Parameter> actionparams;
+
+    std::string action_id = std::string(argv[2]);
+    std::string type = std::string(argv[3]);
+
+    action.Setaction_id(action_id);
+    action.Settype(type);
+
+    _E("id : %s, type : %s", action_id.c_str(), type.c_str());
+
+    for (int i = 4; i < argc; i++) {
+      std::string args = std::string(argv[i]);
+      std::size_t delim = args.find(":");
+
+      std::string key_ = args.substr(0, delim);
+      std::string value_ = args.substr(delim + 1);
+
+      _E("key : %s, value : %s", key_.c_str(), value_.c_str());
+
+      auto param = rpc_port::tizen_action_service_proxy::Parameter(key_, "", value_, "", true);
+
+      actionparams.push_back(param);
+    }
+    action.Setparameters(actionparams);
+
     try {
-      int ret = proxy_.Execute(std::move(launch_req));
+      int ret = proxy_.Execute(action);
       return ret;
     } catch (...) {
       _E("Execute Failed");
       return -1;
     }
+
+    return -1;
   }
 
   void OnConnected() override {
index dea62d4a1e28c9b5c4c5674edf488464b573b809..34af9077234e1e2b92beb608f07f397d37228677 100644 (file)
@@ -93,7 +93,7 @@ class GetAction : public ActionFwTool,
           _D("- key: %s", parameter.Getkey().c_str());
           _D("- type: %s", parameter.Gettype().c_str());
           _D("- description: %s", parameter.Getdescription().c_str());
-          _D("- required: %s", parameter.Getis_requied() ? "true" : "false");
+          _D("- required: %s\n", parameter.Getis_requied() ? "true" : "false");
         }
       }
     } catch (...) {