1// Copyright 2017 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <lib/async-testutils/dispatcher_stub.h> 6 7namespace async { 8 9namespace { 10 11zx_time_t stub_now(async_dispatcher_t* dispatcher) { 12 return (static_cast<DispatcherStub*>(dispatcher)->Now()).get(); 13} 14 15zx_status_t stub_begin_wait(async_dispatcher_t* dispatcher, async_wait_t* wait) { 16 return static_cast<DispatcherStub*>(dispatcher)->BeginWait(wait); 17} 18 19zx_status_t stub_cancel_wait(async_dispatcher_t* dispatcher, async_wait_t* wait) { 20 return static_cast<DispatcherStub*>(dispatcher)->CancelWait(wait); 21} 22 23zx_status_t stub_post_task(async_dispatcher_t* dispatcher, async_task_t* task) { 24 return static_cast<DispatcherStub*>(dispatcher)->PostTask(task); 25} 26 27zx_status_t stub_cancel_task(async_dispatcher_t* dispatcher, async_task_t* task) { 28 return static_cast<DispatcherStub*>(dispatcher)->CancelTask(task); 29} 30 31zx_status_t stub_queue_packet(async_dispatcher_t* dispatcher, async_receiver_t* receiver, 32 const zx_packet_user_t* data) { 33 return static_cast<DispatcherStub*>(dispatcher)->QueuePacket(receiver, data); 34} 35 36zx_status_t stub_set_guest_bell_trap(async_dispatcher_t* dispatcher, async_guest_bell_trap_t* trap, 37 zx_handle_t guest, zx_vaddr_t addr, size_t length) { 38 return static_cast<DispatcherStub*>(dispatcher)->SetGuestBellTrap( 39 trap, *zx::unowned_guest(guest), addr, length); 40} 41 42zx_status_t stub_bind_exception_port(async_dispatcher_t* dispatcher, 43 async_exception_t* exception) { 44 return static_cast<DispatcherStub*>(dispatcher)->BindExceptionPort(exception); 45} 46 47zx_status_t stub_unbind_exception_port(async_dispatcher_t* dispatcher, 48 async_exception_t* exception) { 49 return static_cast<DispatcherStub*>(dispatcher)->UnbindExceptionPort(exception); 50} 51 52const async_ops_t g_stub_ops = { 53 .version = ASYNC_OPS_V2, 54 .reserved = 0, 55 .v1 = { 56 .now = stub_now, 57 .begin_wait = stub_begin_wait, 58 .cancel_wait = stub_cancel_wait, 59 .post_task = stub_post_task, 60 .cancel_task = stub_cancel_task, 61 .queue_packet = stub_queue_packet, 62 .set_guest_bell_trap = stub_set_guest_bell_trap, 63 }, 64 .v2 = { 65 .bind_exception_port = stub_bind_exception_port, 66 .unbind_exception_port = stub_unbind_exception_port, 67 }, 68}; 69 70} // namespace 71 72DispatcherStub::DispatcherStub() 73 : async_dispatcher_t{&g_stub_ops} {} 74 75DispatcherStub::~DispatcherStub() {} 76 77zx::time DispatcherStub::Now() { 78 return zx::time(0); 79} 80 81zx_status_t DispatcherStub::BeginWait(async_wait_t* wait) { 82 return ZX_ERR_NOT_SUPPORTED; 83} 84 85zx_status_t DispatcherStub::CancelWait(async_wait_t* wait) { 86 return ZX_ERR_NOT_SUPPORTED; 87} 88 89zx_status_t DispatcherStub::PostTask(async_task_t* task) { 90 return ZX_ERR_NOT_SUPPORTED; 91} 92 93zx_status_t DispatcherStub::CancelTask(async_task_t* task) { 94 return ZX_ERR_NOT_SUPPORTED; 95} 96 97zx_status_t DispatcherStub::QueuePacket(async_receiver_t* receiver, 98 const zx_packet_user_t* data) { 99 return ZX_ERR_NOT_SUPPORTED; 100} 101 102zx_status_t DispatcherStub::SetGuestBellTrap(async_guest_bell_trap_t* trap, 103 const zx::guest& guest, 104 zx_vaddr_t addr, size_t length) { 105 return ZX_ERR_NOT_SUPPORTED; 106} 107 108zx_status_t DispatcherStub::BindExceptionPort(async_exception_t* exception) { 109 return ZX_ERR_NOT_SUPPORTED; 110} 111 112zx_status_t DispatcherStub::UnbindExceptionPort(async_exception_t* exception) { 113 return ZX_ERR_NOT_SUPPORTED; 114} 115 116} // namespace async 117