Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 836c24d3 authored by Zach Johnson's avatar Zach Johnson
Browse files

Remove module_start_up_callbacked_wrapper

It's no longer needed

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I0e74fc268a10302b120f1be53825643718af944b
parent 9013866c
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -57,13 +57,3 @@ void module_shut_down(const module_t* module);
// Clean up the provided module. |module| may not be NULL.
// If not initialized, does nothing.
void module_clean_up(const module_t* module);

// Temporary callbacked wrapper for module start up, so real modules can be
// spliced into the current janky startup sequence. Runs on a separate thread,
// which terminates when the module start up has finished. When module startup
// has finished, |callback| is called within the context of |callback_thread|
// with |FUTURE_SUCCESS| or |FUTURE_FAIL| depending on whether startup succeeded
// or not.
void module_start_up_callbacked_wrapper(
    const module_t* module,
    bluetooth::common::MessageLoopThread* callback_thread, thread_fn callback);
+0 −47
Original line number Diff line number Diff line
@@ -153,50 +153,3 @@ static void set_module_state(const module_t* module, module_state_t state) {
  std::lock_guard<std::mutex> lock(metadata_mutex);
  metadata[module] = state;
}

// TODO(zachoverflow): remove when everything modulized
// Temporary callback-wrapper-related code
class CallbackWrapper {
 public:
  explicit CallbackWrapper(const module_t* module,
                           MessageLoopThread* callback_thread,
                           thread_fn callback)
      : module(module),
        lifecycle_thread(std::string("bt_module_lifecycle_thread[") +
                         (module->name != nullptr ? module->name : "unknown") +
                         "]"),
        callback_thread(callback_thread),
        callback(callback),
        success(false) {}
  const module_t* module;
  MessageLoopThread lifecycle_thread;
  // we don't own this thread
  MessageLoopThread* callback_thread;
  thread_fn callback;
  bool success;
};

static void post_result_to_callback(std::shared_ptr<CallbackWrapper> wrapper) {
  CHECK(wrapper);
  wrapper->lifecycle_thread.ShutDown();
  wrapper->callback(wrapper->success ? FUTURE_SUCCESS : FUTURE_FAIL);
}

static void run_wrapped_start_up(std::shared_ptr<CallbackWrapper> wrapper) {
  CHECK(wrapper);
  wrapper->success = module_start_up(wrapper->module);
  // Post the result back to the callback
  wrapper->callback_thread->DoInThread(
      FROM_HERE, base::BindOnce(post_result_to_callback, wrapper));
}

void module_start_up_callbacked_wrapper(const module_t* module,
                                        MessageLoopThread* callback_thread,
                                        thread_fn callback) {
  std::shared_ptr<CallbackWrapper> wrapper =
      std::make_shared<CallbackWrapper>(module, callback_thread, callback);
  wrapper->lifecycle_thread.StartUp();
  // Run the actual module start up
  wrapper->lifecycle_thread.DoInThread(
      FROM_HERE, base::BindOnce(run_wrapped_start_up, wrapper));
}