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 #ifndef LIB_ZX_TIMER_H_
6 #define LIB_ZX_TIMER_H_
7 
8 #include <lib/zx/handle.h>
9 #include <lib/zx/object.h>
10 
11 #include <zircon/types.h>
12 
13 namespace zx {
14 
15 class timer : public object<timer> {
16 public:
17     static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_TIMER;
18 
19     constexpr timer() = default;
20 
timer(zx_handle_t value)21     explicit timer(zx_handle_t value) : object(value) {}
22 
timer(handle && h)23     explicit timer(handle&& h) : object(h.release()) {}
24 
timer(timer && other)25     timer(timer&& other) : object(other.release()) {}
26 
27     timer& operator=(timer&& other) {
28         reset(other.release());
29         return *this;
30     }
31 
32     static zx_status_t create(uint32_t options, zx_clock_t clock_id, timer* result);
33 
set(zx::time deadline,zx::duration slack)34     zx_status_t set(zx::time deadline, zx::duration slack) const {
35         return zx_timer_set(get(), deadline.get(), slack.get());
36     }
37 
cancel()38     zx_status_t cancel() const {
39         return zx_timer_cancel(get());
40     }
41 };
42 
43 using unowned_timer = unowned<timer>;
44 
45 } // namespace zx
46 
47 #endif  // LIB_ZX_TIMER_H_
48