Fix register, unregister action reply callback
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 6 Mar 2025 01:28:45 +0000 (10:28 +0900)
committer장상윤/Tizen Platform Lab(SR)/삼성전자 <jeremy.jang@samsung.com>
Mon, 10 Mar 2025 05:52:24 +0000 (14:52 +0900)
Use sequence id of TIDL CallbackBase.

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/action/service.cc
src/action/service.hh
tidl/tizen_actions.tidl
tool/action_fw_tool/tools/execute.cc

index 6b9bab827e563699c1ce8a954a49cad2eac6dede..a7eece2672ba262bfdff0267014ef67d35fc24e9 100644 (file)
  * limitations under the License.
  */
 
+ #include "action/service.hh"
+
+#include <algorithm>
+
 #include "action/request_handler.hh"
-#include "action/service.hh"
 #include "action/sqlite_db.hh"
 #include "action/utils/json_parser.hh"
 #include "common/utils/logging.hh"
@@ -159,17 +162,24 @@ int Service::Execute(rs::Action action) {
 }
 
 int Service::RegisterActionReplyCb(std::unique_ptr<ActionReplyCb> cb) {
+  int id = cb->GetSeqId();
   reply_cbs_.emplace(GetInstance(), std::move(cb));
-  return 0;
+  return id;
 }
 
-void Service::UnregisterActionReplyCb() {
-  auto it = reply_cbs_.find(GetInstance());
-  if (it != reply_cbs_.end())
+bool Service::UnregisterActionReplyCb(int id) {
+  auto it = std::find_if(reply_cbs_.begin(), reply_cbs_.end(),
+      [id](const auto& iterator) {
+        return iterator.second->GetSeqId() == id;
+      });
+  if (it != reply_cbs_.end()) {
     reply_cbs_.erase(it);
-  else
+    return true;
+  } else {
     LOG(ERROR) << "Not found callback for unregistration for instance "
         << GetInstance();
+    return false;
+  }
 }
 
 }  // namespace action
index 3190dea4181434686aaa406d21ed298acf915f36..fb62f416c3586c83f3bd11578a77d451d7231f64 100644 (file)
@@ -57,7 +57,7 @@ class Service : public rs::stub::ActionService::ServiceBase {
       int top_k, float search_threshold) override;
   int Execute(rs::Action action) override;
   int RegisterActionReplyCb(std::unique_ptr<ActionReplyCb> cb) override;
-  void UnregisterActionReplyCb() override;
+  bool UnregisterActionReplyCb(int id) override;
 
  private:
   IRequestHandler& handler_;
index 5df091b633344b6c6edba68934f07fe83f1292cf..2154c9efd2e30df66c9ab05f3aaaf7ae47f56a15 100644 (file)
@@ -39,5 +39,5 @@ interface ActionService {
     int Execute(Action action);
     void ActionReplyCb(string result) delegate;
     int RegisterActionReplyCb(ActionReplyCb cb);
-    void UnregisterActionReplyCb() async;
+    bool UnregisterActionReplyCb(int id);
 }
index b6110f73f514a87f1d65ce93b4b79080922e37fa..5a642f9f5be0d727580b7b5c74f4982e921b36f6 100644 (file)
@@ -49,7 +49,7 @@ class Execute : public ActionFwTool,
     try {
       proxy_.Connect(true);
       connected = true;
-      proxy_.RegisterActionReplyCb(std::make_unique<Reply>());
+      cb_id_ = proxy_.RegisterActionReplyCb(std::make_unique<Reply>());
     } catch (
         const rpc_port::tizen_action_service_proxy::proxy::InvalidIDException&
             e) {
@@ -67,8 +67,11 @@ class Execute : public ActionFwTool,
   }
 
   void TearDown() override {
-    if (connected)
+    if (connected) {
+      if (cb_id_ > 0)
+        proxy_.UnregisterActionReplyCb(cb_id_);
       proxy_.Disconnect();
+    }
   }
 
   int Run(int argc, char** argv) override {
@@ -132,6 +135,7 @@ class Execute : public ActionFwTool,
  private:
   rpc_port::tizen_action_service_proxy::proxy::ActionService proxy_;
   bool connected = false;
+  int cb_id_ = -1;
 };
 
 ACTION_FW_TOOL_REGISTER(Execute, execute);