Add a reply handler
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 17 Feb 2025 06:57:04 +0000 (15:57 +0900)
committer장상윤/Tizen Platform Lab(SR)/삼성전자 <jeremy.jang@samsung.com>
Tue, 18 Feb 2025 00:02:54 +0000 (09:02 +0900)
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/action/app_control_executor.cc
src/action/app_control_executor.hh
src/action/app_control_sender.cc
src/action/app_control_sender.hh
src/common/action_executor.hh

index 4fc97adb197b5df400bcaa0a98b5ee9e7b9b3c57..81948214c1edf33b5ef6b56418f611afb4bb1a15 100644 (file)
@@ -49,7 +49,7 @@ int AppControlExecutor::Execute(const common::ActionModel& model) {
   app_control_h app_control = ConvertToAppControl(model);
 
   std::unique_ptr<AppControlSender> sender =
-      std::make_unique<AppControlSender>(app_control);
+      std::make_unique<AppControlSender>(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
index 47cdf51b0c5483b7c40a96e18c5527156add7bee..a58019980a5e7ea81ee085bdb67c92553e9e9242 100644 (file)
@@ -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<std::unique_ptr<AppControlSender>> senders_;
index 44af907640f424cedf22d7f6579a8e1f769161f7..e8e7a693303b16b6fcb21234d94b1e2f6cb79667 100644 (file)
@@ -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<common::IActionExecutor*>(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<void*>(executor_));
   if (ret != APP_CONTROL_ERROR_NONE) {
     LOG(ERROR) << "Failed to send launch request: " << ret;
     return false;
index 3b48d04d88d668cdf70c24b03bf6ad1934b3cb47..262cea651b54526fcce9663221e7e36fc8964e5b 100644 (file)
 
 #include <app_control.h>
 
+#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
index 28674b95937dbbdfd9e20fd20bea10ed64a22af5..8d30f487fc01dd6f890b17ae6892f9ea6dce474f 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef COMMON_ACTION_EXECUTOR_HH_
 #define COMMON_ACTION_EXECUTOR_HH_
 
+#include <string>
+
 #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