1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "os/handler.h" 18 19 #include <bluetooth/log.h> 20 21 #include <chrono> 22 23 #include "os/thread.h" 24 #include "test/headless/handler.h" 25 #include "test/headless/log.h" 26 27 namespace bluetooth { 28 namespace test { 29 Handler()30headless::Handler::Handler() { 31 thread_ = new os::Thread("headless_thread", os::Thread::Priority::NORMAL); 32 handler_ = new os::Handler(thread_); 33 } 34 ~Handler()35headless::Handler::~Handler() { 36 handler_->Clear(); 37 handler_->WaitUntilStopped(std::chrono::milliseconds(2000)); 38 delete handler_; 39 delete thread_; 40 } 41 Post(common::OnceClosure closure)42void headless::Handler::Post(common::OnceClosure closure) { 43 log::assert_that(handler_ != nullptr, "Handler is not valid"); 44 handler_->Post(std::move(closure)); 45 } 46 47 } // namespace test 48 } // namespace bluetooth 49