From: Sangyoon Jang Date: Mon, 17 Feb 2025 06:57:04 +0000 (+0900) Subject: Add a reply handler X-Git-Tag: accepted/tizen/unified/20250514.114137~52 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f7c76fd8e6cbaf8e8a236e7da71031843c36747;p=platform%2Fcore%2Fappfw%2Ftizen-action.git Add a reply handler Signed-off-by: Sangyoon Jang --- diff --git a/src/action/app_control_executor.cc b/src/action/app_control_executor.cc index 4fc97ad..8194821 100644 --- a/src/action/app_control_executor.cc +++ b/src/action/app_control_executor.cc @@ -49,7 +49,7 @@ int AppControlExecutor::Execute(const common::ActionModel& model) { app_control_h app_control = ConvertToAppControl(model); std::unique_ptr sender = - std::make_unique(app_control); + std::make_unique(app_control, this); // TODO: handle result? sender->Send(); @@ -59,4 +59,9 @@ int AppControlExecutor::Execute(const common::ActionModel& model) { return 0; } +void AppControlExecutor::OnReply(const std::string& reply) { + // TODO: Handle reply + LOG(DEBUG) << reply; +} + } // namespace action diff --git a/src/action/app_control_executor.hh b/src/action/app_control_executor.hh index 47cdf51..a580199 100644 --- a/src/action/app_control_executor.hh +++ b/src/action/app_control_executor.hh @@ -30,6 +30,7 @@ class AppControlExecutor : public common::IActionExecutor { AppControlExecutor(); ~AppControlExecutor(); int Execute(const common::ActionModel& model) override; + void OnReply(const std::string& reply) override; private: std::vector> senders_; diff --git a/src/action/app_control_sender.cc b/src/action/app_control_sender.cc index 44af907..e8e7a69 100644 --- a/src/action/app_control_sender.cc +++ b/src/action/app_control_sender.cc @@ -30,14 +30,21 @@ void ResultCb(app_control_h request, app_control_error_e result, void ReplyCb(app_control_h request, app_control_h reply, app_control_result_e result, void* user_data) { // TODO: return reply to caller + common::IActionExecutor* on_reply = + static_cast(user_data); + + // TODO: return what + std::string result_str = "result"; + on_reply->OnReply(result_str); } } // namespace namespace action { -AppControlSender::AppControlSender(app_control_h app_control) - : app_control_(app_control) { +AppControlSender::AppControlSender(app_control_h app_control, + common::IActionExecutor* executor) + : app_control_(app_control), executor_(executor) { } AppControlSender::~AppControlSender() { @@ -48,7 +55,7 @@ AppControlSender::~AppControlSender() { bool AppControlSender::Send() { int ret = app_control_send_launch_request_async(app_control_, ResultCb, - ReplyCb, nullptr); + ReplyCb, static_cast(executor_)); if (ret != APP_CONTROL_ERROR_NONE) { LOG(ERROR) << "Failed to send launch request: " << ret; return false; diff --git a/src/action/app_control_sender.hh b/src/action/app_control_sender.hh index 3b48d04..262cea6 100644 --- a/src/action/app_control_sender.hh +++ b/src/action/app_control_sender.hh @@ -19,16 +19,20 @@ #include +#include "common/action_executor.hh" + namespace action { class AppControlSender { public: - AppControlSender(app_control_h app_control); + AppControlSender(app_control_h app_control, + common::IActionExecutor* executor); ~AppControlSender(); bool Send(); private: app_control_h app_control_; + common::IActionExecutor* executor_; }; } // action diff --git a/src/common/action_executor.hh b/src/common/action_executor.hh index 28674b9..8d30f48 100644 --- a/src/common/action_executor.hh +++ b/src/common/action_executor.hh @@ -17,6 +17,8 @@ #ifndef COMMON_ACTION_EXECUTOR_HH_ #define COMMON_ACTION_EXECUTOR_HH_ +#include + #include "common/action_model.h" namespace common { @@ -25,6 +27,7 @@ class IActionExecutor { public: virtual ~IActionExecutor() = default; virtual int Execute(const ActionModel& model) = 0; + virtual void OnReply(const std::string& result) = 0; }; } // namespace common