- [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>
#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 {
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
#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;
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_;
}
// 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;
}
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 =
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;
#include <string>
+#include "common/action_model.h"
+
namespace action {
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
#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 {
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;
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);
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;
}
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_;
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
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
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
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_;
};
<icon>TizenActionFrameworkService.png</icon>
<label>TizenActionFrameworkService</label>
</service-application>
+ <privileges>
+ <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ </privileges>
</manifest>
struct Parameter {
string key;
string type;
+ string value;
string description;
bool is_requied;
}
string app_id;
string label;
string description;
+ string type;
string uri;
string mime;
string operation;
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);
}
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() {}
}
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 {
_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 (...) {