Generate execution id on execute action
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 12 May 2025 05:06:52 +0000 (14:06 +0900)
committer장상윤/Tizen Platform Lab(SR)/삼성전자 <jeremy.jang@samsung.com>
Mon, 12 May 2025 07:03:40 +0000 (16:03 +0900)
- ActionExecutorFactory generates execution id on each executors.
- Execute() of TIDL interface returns execution id.
- The execution id passed on ActionReplyCb.

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
16 files changed:
src/action/action_executor_factory.cc
src/action/action_executor_factory.hh
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/plugin_executor.cc
src/action/plugin_executor.hh
src/action/request_reply_handler.hh
src/action/service.cc
src/action/service.hh
src/api/api_stub.cc
src/common/action_executor.hh
src/common/action_result_handler.hh
tidl/tizen_actions.tidl
tool/action_tool/tools/execute.cc

index 9d34f9b65cb5e21ee5ff73702d46ce2e980908c2..d1327499256236c31dbdd844850c3148df1aeb5f 100644 (file)
@@ -8,7 +8,7 @@ namespace action {
 
 class DefaultActionExecutor : public common::AbstractActionExecutor {
  public:
-  explicit DefaultActionExecutor() : AbstractActionExecutor("") {}
+  explicit DefaultActionExecutor() : AbstractActionExecutor("", -1) {}
   ~DefaultActionExecutor() = default;
 
   int Execute(const common::ActionModel& model) override {
@@ -23,12 +23,19 @@ ActionExecutorFactory::CreateExecutor(std::string instance,
   switch (model.GetType()) {
     case common::ActionType::AppControl:
       return std::make_unique<action::AppControlExecutor>(std::move(instance),
+                                                          GenerateExecutionId(),
                                                           model);
     case common::ActionType::Plugin:
-      return std::make_unique<action::PluginExecutor>(std::move(instance));
+      return std::make_unique<action::PluginExecutor>(std::move(instance),
+                                                      GenerateExecutionId());
     default:
       return std::make_unique<DefaultActionExecutor>();
   }
 }
 
+int ActionExecutorFactory::GenerateExecutionId() {
+  static int id = 0;
+  return ++id;
+}
+
 }  // namespace action
index 572e31173284c7ba3db78d40129fb1e38e6bc506..c0dd1c3c01b2472ed0e6aa0e6cb44227e375cca5 100644 (file)
@@ -29,6 +29,9 @@ class ActionExecutorFactory {
   static std::unique_ptr<common::AbstractActionExecutor> CreateExecutor(
       std::string instance,
       const common::ActionModel& model);
+
+ private:
+  static int GenerateExecutionId();
 };
 
 }  // namespace action
index b5034453d034bc85717b5b30917d893268f980f3..2ea598e7d859f3596357ce403d4966dfd6af8078 100644 (file)
@@ -232,9 +232,9 @@ int ActionRequestHandler::OnExecute(const std::string& instance, pid_t pid,
 
     auto executor = ActionExecutorFactory::CreateExecutor(instance, model);
     executor->SetResultHandler(this);
-    int ret = executor->Execute(model);
+    int execution_id = executor->Execute(model);
     executors_.emplace_back(std::move(executor));
-    return ret;
+    return execution_id;
   } catch (const std::runtime_error& e) {
     LOG(ERROR) << "Failed to execute action : " << e.what();
     return -1;
@@ -260,14 +260,16 @@ void ActionRequestHandler::UnregisterRequestReplyHandler(
 }
 
 void ActionRequestHandler::OnResult(const std::string& requester,
+                                    int execution_id,
                                     const std::string& result) {
-  LOG(DEBUG) << "OnResult : " << result << ", from : " << requester;
+  LOG(DEBUG) << "OnResult : " << result << ", from : " << requester
+      << ", execution_id : " << execution_id;
   auto it = std::find_if(reply_handlers_.begin(), reply_handlers_.end(),
                          [requester](const auto& iterator) {
                            return iterator.first == requester;
                          });
   if (it != reply_handlers_.end())
-    it->second->SendRequestReply(result);
+    it->second->SendRequestReply(execution_id, result);
   else
     LOG(WARNING) << "No handler found for requester :" << requester;
 }
index df6e25a2305008470113fca40fb9aeee887eab3e..a92992a8d494172f4992e7eaa7b991c3ba13b74d 100644 (file)
@@ -49,6 +49,7 @@ class ActionRequestHandler : public IRequestHandler,
   void UnregisterRequestReplyHandler(const std::string& requester) override;
 
   void OnResult(const std::string& requester,
+                int execution_id,
                 const std::string& result) override;
 
  private:
index cf643189877d6c95e16057432cfd6a3c8e804d1c..269ae146bdc4e10669ebc65a8bd885797acb2922 100644 (file)
@@ -127,9 +127,9 @@ void ReplyCb(app_control_h request,
 
 namespace action {
 
-AppControlExecutor::AppControlExecutor(std::string id,
+AppControlExecutor::AppControlExecutor(std::string id, int execution_id,
     const common::ActionModel& model)
-    : common::AbstractActionExecutor(std::move(id)) {
+    : common::AbstractActionExecutor(std::move(id), execution_id) {
   model_ = model;
   app_control_ = ConvertToAppControl(model);
 }
@@ -150,12 +150,12 @@ int AppControlExecutor::Execute(const common::ActionModel& model) {
     return -1;
   }
 
-  return 0;
+  return GetExecutionId();
 }
 
 void AppControlExecutor::OnAppControlReply(const std::string& reply) {
-  // TODO: Handle reply
-  LOG(DEBUG) << "reply from instance: " << GetId() << ", reply: " << reply;
+  LOG(DEBUG) << "reply from instance: " << GetRequesterId()
+      << ", reply: " << reply;
   NotifyResult(reply);
 }
 
index 5c4f75d7ea281642e69fd948499ef606606fb81f..3a9626c6dff6e845c78f2e7f37c754be86253029 100644 (file)
@@ -26,7 +26,8 @@ namespace action {
 
 class AppControlExecutor : public common::AbstractActionExecutor {
  public:
-  explicit AppControlExecutor(std::string id, const common::ActionModel& model);
+  explicit AppControlExecutor(std::string id, int execution_id,
+      const common::ActionModel& model);
   ~AppControlExecutor();
   int Execute(const common::ActionModel& model) override;
 
index 1ac810f1cce02861a5f04856c0aac5a4e4023959..45a3495d9517611c6999de19cb41e4815b5f58a5 100644 (file)
@@ -44,8 +44,8 @@ class ResultHandler : public rpc_port::plugin_manager_proxy::proxy::
   PluginExecutor* executor_ = nullptr;
 };
 
-PluginExecutor::PluginExecutor(std::string id)
-    : AbstractActionExecutor(std::move(id)),
+PluginExecutor::PluginExecutor(std::string id, int execution_id)
+    : AbstractActionExecutor(std::move(id), execution_id),
       plugin_manager_(
           this,
           "d::org.tizen.appfw.service.tizen_action_plugin_manager") {}
@@ -75,11 +75,12 @@ int PluginExecutor::Execute(const common::ActionModel& model) {
     return -1;
   }
 
-  return 0;
+  return GetExecutionId();
 }
 
 void PluginExecutor::OnResultReceived(const std::string& result) {
-  LOG(DEBUG) << "result from instance: " << GetId() << ", result: " << result;
+  LOG(DEBUG) << "result from instance: " << GetRequesterId()
+      << ", result: " << result;
   NotifyResult(result);
 }
 
index 84cdb246ddf7fa2f0b656394721206ba5f6da30b..3d16e4851d6514e6f85e099da766ba4995d65768 100644 (file)
@@ -28,7 +28,7 @@ class PluginExecutor : public common::AbstractActionExecutor,
                        public rpc_port::plugin_manager_proxy::proxy::
                            PluginManager::IEventListener {
  public:
-  explicit PluginExecutor(std::string instance);
+  explicit PluginExecutor(std::string instance, int execution_id);
   ~PluginExecutor();
   int Execute(const common::ActionModel& model) override;
   void OnResultReceived(const std::string& result);
index 307a3853dd3b70ab3cdb1ae84b379f51079503d6..5ab09dda1b6744f917b7786d31b32c306ada7512 100644 (file)
@@ -24,7 +24,7 @@ namespace action {
 class IRequestReplyHandler {
  public:
   virtual ~IRequestReplyHandler() = default;
-  virtual void SendRequestReply(const std::string& reply) = 0;
+  virtual void SendRequestReply(int execution_id, const std::string& reply) = 0;
 };
 
 }  // namespace action
index 015c1845ee7925911a05d963c29d0827c0bee393..9b2c63e7389ce62d89f7e558888bb21d87373afe 100644 (file)
@@ -86,9 +86,9 @@ bool Service::UnregisterActionReplyCb(int id) {
   }
 }
 
-void Service::SendRequestReply(const std::string& reply) {
+void Service::SendRequestReply(int execution_id, const std::string& reply) {
   for (const auto& cb : reply_cbs_)
-    cb->Invoke(reply);
+    cb->Invoke(execution_id, reply);
 }
 
 }  // namespace action
index 4ce8234db34e71615f6c1c92c7e9563429c3fda1..1ceaf83bf383f9f79b7b9eb4d5aaf2f6efd4287c 100644 (file)
@@ -60,7 +60,7 @@ class Service : public rpc::stub::ActionService::ServiceBase,
   int Execute(rpc::ActionModel action) override;
   int RegisterActionReplyCb(std::unique_ptr<ActionReplyCb> cb) override;
   bool UnregisterActionReplyCb(int id) override;
-  void SendRequestReply(const std::string& reply) override;
+  void SendRequestReply(int execution_id, const std::string& reply) override;
 
  private:
   IRequestHandler& handler_;
index 2ef80342830f28de7bd64fc740590a4fe712c451..0dafbd17a73628b11ec1933c3abf5b28fb99cc5b 100644 (file)
@@ -34,7 +34,7 @@ class Reply : public api::rpc::proxy::ActionService::ActionReplyCb {
   Reply(action_result_cb cb, void* user_data)
     : cb_(cb), user_data_(user_data) {}
 
-  void OnReceived(std::string result) {
+  void OnReceived(int execution_id, std::string result) {
     LOG(WARNING) << "@@@ reply OnReceived : " << result;
 
     cb_(100, result.c_str(), user_data_);
index a3b7e2645992bb517cbd5c30667ddde22810b6cb..5f83b41db7a80e00714a514eb4b343c22c3ddb5d 100644 (file)
@@ -27,17 +27,20 @@ namespace common {
 
 class AbstractActionExecutor {
  public:
-  explicit AbstractActionExecutor(std::string id) : id_(std::move(id)) {}
+  explicit AbstractActionExecutor(std::string requester_id, int execution_id)
+      : requester_id_(std::move(requester_id)), execution_id_(execution_id) {}
   virtual ~AbstractActionExecutor() = default;
   virtual int Execute(const ActionModel& model) = 0;
-  std::string GetId() { return id_; }
+  std::string GetRequesterId() { return requester_id_; }
   void SetResultHandler(IActionResultHandler* handler) { handler_ = handler; }
   void NotifyResult(const std::string& result) {
-    handler_->OnResult(id_, result);
+    handler_->OnResult(requester_id_, execution_id_, result);
   }
+  int GetExecutionId() { return execution_id_; }
 
  private:
-  std::string id_;
+  std::string requester_id_;
+  int execution_id_;
   IActionResultHandler* handler_ = nullptr;
 };
 
index d5a939f397705edaaa30470dfc556f61f65c14e5..f7dcd7e7ccb31af140066e91dd88854d6c1900c5 100644 (file)
@@ -24,7 +24,7 @@ namespace common {
 class IActionResultHandler {
  public:
   virtual ~IActionResultHandler() = default;
-  virtual void OnResult(const std::string& executor_id,
+  virtual void OnResult(const std::string& executor_id, int execution_id,
       const std::string& result) = 0;
 };
 
index 481c0a3ca0a772e97ba45d781a4a6c74028c29c3..fd01ac079376ab312f5bcaf936669ef40fd3029a 100644 (file)
@@ -6,7 +6,7 @@ interface ActionService {
     ActionSchema GetAction(string action_id);
     array<VectorDbResult> GetActionId(string user_description, int top_k, float search_threshold);
     int Execute(ActionModel action);
-    void ActionReplyCb(string result) delegate;
+    void ActionReplyCb(int execution_id, string result) delegate;
     int RegisterActionReplyCb(ActionReplyCb cb);
     bool UnregisterActionReplyCb(int id);
 }
index fbf1e076864c31c5713a9adb98652114376e9e88..b3c53247214991d2e2b35bc35b6b2a7a9e07f393 100644 (file)
@@ -36,8 +36,8 @@ namespace rpc = rpc_port::tizen_action_service_proxy;
 using ActionReplyCb = rpc::proxy::ActionService::ActionReplyCb;
 class Reply : public ActionReplyCb {
  public:
-  void OnReceived(std::string result) {
-    _I("result : %s", result.c_str());
+  void OnReceived(int execution_id, std::string result) {
+    _I("execution_id: %d, result : %s", execution_id, result.c_str());
     g_main_loop_quit(mainloop);
   }
 };