1 // Copyright 2018 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 #ifndef LIB_ZX_INTERRUPT_H_
6 #define LIB_ZX_INTERRUPT_H_
7 
8 #include <lib/zx/handle.h>
9 #include <lib/zx/object.h>
10 #include <lib/zx/port.h>
11 #include <lib/zx/resource.h>
12 #include <lib/zx/time.h>
13 #include <lib/zx/vcpu.h>
14 
15 namespace zx {
16 
17 class interrupt : public object<interrupt> {
18 public:
19     static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_INTERRUPT;
20 
21     constexpr interrupt() = default;
22 
interrupt(zx_handle_t value)23     explicit interrupt(zx_handle_t value) : object(value) {}
24 
interrupt(handle && h)25     explicit interrupt(handle&& h) : object(h.release()) {}
26 
interrupt(interrupt && other)27     interrupt(interrupt&& other) : object(other.release()) {}
28 
29     interrupt& operator=(interrupt&& other) {
30         reset(other.release());
31         return *this;
32     }
33 
34     static zx_status_t create(const resource& resource, uint32_t vector,
35                               uint32_t options, interrupt* result);
36 
wait(zx::time * timestamp)37     zx_status_t wait(zx::time* timestamp) const {
38         return zx_interrupt_wait(get(), timestamp->get_address());
39     }
40 
destroy()41     zx_status_t destroy() const {
42         return zx_interrupt_destroy(get());
43     }
44 
trigger(uint32_t options,zx::time timestamp)45     zx_status_t trigger(uint32_t options, zx::time timestamp) const {
46         return zx_interrupt_trigger(get(), options, timestamp.get());
47     }
48 
bind(const zx::port & port,uint64_t key,uint32_t options)49     zx_status_t bind(const zx::port& port, uint64_t key,
50                      uint32_t options) const {
51         return zx_interrupt_bind(get(), port.get(), key, options);
52     }
53 
bind_vcpu(const zx::vcpu & vcpu,uint32_t options)54     zx_status_t bind_vcpu(const zx::vcpu& vcpu, uint32_t options) const {
55         return zx_interrupt_bind_vcpu(get(), vcpu.get(), options);
56     }
57 
ack()58     zx_status_t ack() const {
59         return zx_interrupt_ack(get());
60     }
61 };
62 
63 using unowned_interrupt = unowned<interrupt>;
64 
65 } // namespace zx
66 
67 #endif  // LIB_ZX_INTERRUPT_H_
68