* 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"
}
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
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_;
int Execute(Action action);
void ActionReplyCb(string result) delegate;
int RegisterActionReplyCb(ActionReplyCb cb);
- void UnregisterActionReplyCb() async;
+ bool UnregisterActionReplyCb(int id);
}
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) {
}
void TearDown() override {
- if (connected)
+ if (connected) {
+ if (cb_id_ > 0)
+ proxy_.UnregisterActionReplyCb(cb_id_);
proxy_.Disconnect();
+ }
}
int Run(int argc, char** argv) override {
private:
rpc_port::tizen_action_service_proxy::proxy::ActionService proxy_;
bool connected = false;
+ int cb_id_ = -1;
};
ACTION_FW_TOOL_REGISTER(Execute, execute);