From: Sangyoon Jang Date: Thu, 6 Mar 2025 01:28:45 +0000 (+0900) Subject: Fix register, unregister action reply callback X-Git-Tag: accepted/tizen/unified/20250514.114137~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=317cfc390499202e068e449efdfcef95da672189;p=platform%2Fcore%2Fappfw%2Ftizen-action.git Fix register, unregister action reply callback Use sequence id of TIDL CallbackBase. Signed-off-by: Sangyoon Jang --- diff --git a/src/action/service.cc b/src/action/service.cc index 6b9bab8..a7eece2 100644 --- a/src/action/service.cc +++ b/src/action/service.cc @@ -14,8 +14,11 @@ * limitations under the License. */ + #include "action/service.hh" + +#include + #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 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 diff --git a/src/action/service.hh b/src/action/service.hh index 3190dea..fb62f41 100644 --- a/src/action/service.hh +++ b/src/action/service.hh @@ -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 cb) override; - void UnregisterActionReplyCb() override; + bool UnregisterActionReplyCb(int id) override; private: IRequestHandler& handler_; diff --git a/tidl/tizen_actions.tidl b/tidl/tizen_actions.tidl index 5df091b..2154c9e 100644 --- a/tidl/tizen_actions.tidl +++ b/tidl/tizen_actions.tidl @@ -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); } diff --git a/tool/action_fw_tool/tools/execute.cc b/tool/action_fw_tool/tools/execute.cc index b6110f7..5a642f9 100644 --- a/tool/action_fw_tool/tools/execute.cc +++ b/tool/action_fw_tool/tools/execute.cc @@ -49,7 +49,7 @@ class Execute : public ActionFwTool, try { proxy_.Connect(true); connected = true; - proxy_.RegisterActionReplyCb(std::make_unique()); + cb_id_ = proxy_.RegisterActionReplyCb(std::make_unique()); } 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);