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 <chrono> 20 21 #include "os/thread.h" 22 #include "test/headless/handler.h" 23 #include "test/headless/log.h" 24 25 namespace bluetooth { 26 namespace test { 27 Handler()28headless::Handler::Handler() { 29 thread_ = new os::Thread("headless_thread", os::Thread::Priority::NORMAL); 30 handler_ = new os::Handler(thread_); 31 } 32 ~Handler()33headless::Handler::~Handler() { 34 handler_->Clear(); 35 handler_->WaitUntilStopped(std::chrono::milliseconds(2000)); 36 delete handler_; 37 delete thread_; 38 } 39 Post(common::OnceClosure closure)40void headless::Handler::Post(common::OnceClosure closure) { 41 ASSERT_LOG(handler_ != nullptr, "Handler is not valid"); 42 handler_->Post(std::move(closure)); 43 } 44 45 } // namespace test 46 } // namespace bluetooth 47