Replace std::function with base::Closure
std::function doesn't support non-copyable arguments. Use base::Closure
and base::OnceClosure from libchrome instead.
Test: atest --host bluetooth_test_gd
Change-Id: Ic18bbc000730e8b0d7acff0097870bd258ee6150
diff --git a/gd/stack_manager.cc b/gd/stack_manager.cc
index ad83674..7cfaade 100644
--- a/gd/stack_manager.cc
+++ b/gd/stack_manager.cc
@@ -20,11 +20,12 @@
#include <future>
#include <queue>
+#include "common/bind.h"
#include "hal/hci_hal.h"
-#include "os/thread.h"
+#include "module.h"
#include "os/handler.h"
#include "os/log.h"
-#include "module.h"
+#include "os/thread.h"
using ::bluetooth::os::Handler;
using ::bluetooth::os::Thread;
@@ -36,10 +37,8 @@
handler_ = new Handler(management_thread_);
std::promise<void>* promise = new std::promise<void>();
- handler_->Post([this, promise, modules, stack_thread]() {
- registry_.Start(modules, stack_thread);
- promise->set_value();
- });
+ handler_->Post(
+ common::BindOnce(&StackManager::handle_start_up, common::Unretained(this), modules, stack_thread, promise));
auto future = promise->get_future();
auto init_status = future.wait_for(std::chrono::seconds(3));
@@ -49,12 +48,14 @@
LOG_INFO("init complete");
}
+void StackManager::handle_start_up(ModuleList* modules, Thread* stack_thread, std::promise<void>* promise) {
+ registry_.Start(modules, stack_thread);
+ promise->set_value();
+}
+
void StackManager::ShutDown() {
std::promise<void>* promise = new std::promise<void>();
- handler_->Post([this, promise]() {
- registry_.StopAll();
- promise->set_value();
- });
+ handler_->Post(common::BindOnce(&StackManager::handle_shut_down, common::Unretained(this), promise));
auto future = promise->get_future();
auto stop_status = future.wait_for(std::chrono::seconds(3));
@@ -64,4 +65,10 @@
delete handler_;
delete management_thread_;
}
+
+void StackManager::handle_shut_down(std::promise<void>* promise) {
+ registry_.StopAll();
+ promise->set_value();
+}
+
} // namespace bluetooth