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/cpp/trap.h>
6 
7 #include <utility>
8 
9 namespace async {
10 
GuestBellTrapBase(async_guest_bell_trap_handler_t * handler)11 GuestBellTrapBase::GuestBellTrapBase(async_guest_bell_trap_handler_t* handler)
12     : trap_{{ASYNC_STATE_INIT}, handler} {}
13 
14 GuestBellTrapBase::~GuestBellTrapBase() = default;
15 
SetTrap(async_dispatcher_t * dispatcher,const zx::guest & guest,zx_vaddr_t addr,size_t length)16 zx_status_t GuestBellTrapBase::SetTrap(
17     async_dispatcher_t* dispatcher, const zx::guest& guest, zx_vaddr_t addr, size_t length) {
18     return async_set_guest_bell_trap(dispatcher, &trap_, guest.get(), addr, length);
19 }
20 
GuestBellTrap(Handler handler)21 GuestBellTrap::GuestBellTrap(Handler handler)
22     : GuestBellTrapBase(&GuestBellTrap::CallHandler), handler_(std::move(handler)) {}
23 
24 GuestBellTrap::~GuestBellTrap() = default;
25 
CallHandler(async_dispatcher_t * dispatcher,async_guest_bell_trap_t * trap,zx_status_t status,const zx_packet_guest_bell_t * bell)26 void GuestBellTrap::CallHandler(async_dispatcher_t* dispatcher, async_guest_bell_trap_t* trap,
27                                 zx_status_t status, const zx_packet_guest_bell_t* bell) {
28     auto self = Dispatch<GuestBellTrap>(trap);
29     self->handler_(dispatcher, self, status, bell);
30 }
31 
32 } // namespace async
33