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

Commit 4b26fab7 authored by Chris Manton's avatar Chris Manton
Browse files

headless: Introduce headless handler

Bug: 257972065
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I03dc300810457fba8f31c5b72008d3009bc88d5d
parent 9613a87c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ cc_binary {
        ":TestHeadlessModules",
        "bt_property.cc",
        "get_options.cc",
        "handler.cc",
        "headless.cc",
        "log.cc",
        "main.cc",
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "os/handler.h"

#include <chrono>

#include "os/thread.h"
#include "test/headless/handler.h"
#include "test/headless/log.h"

namespace bluetooth {
namespace test {

headless::Handler::Handler() {
  thread_ = new os::Thread("headless_thread", os::Thread::Priority::NORMAL);
  handler_ = new os::Handler(thread_);
}

headless::Handler::~Handler() {
  handler_->Clear();
  handler_->WaitUntilStopped(std::chrono::milliseconds(2000));
  delete handler_;
  delete thread_;
}

void headless::Handler::Post(common::OnceClosure closure) {
  ASSERT_LOG(handler_ != nullptr, "Handler is not valid");
  handler_->Post(std::move(closure));
}

}  // namespace test
}  // namespace bluetooth
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "os/handler.h"
#include "os/thread.h"

namespace bluetooth {
namespace test {
namespace headless {

class Handler {
 public:
  Handler();
  ~Handler();
  Handler(const Handler& handler) = default;

  void Post(common::OnceClosure closure);

 private:
  os::Thread* thread_{nullptr};
  os::Handler* handler_{nullptr};
};

}  // namespace headless
}  // namespace test
}  // namespace bluetooth