Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 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_DEBUGLOG_H_ |
| 6 | #define LIB_ZX_DEBUGLOG_H_ |
| 7 | |
| 8 | #include <lib/zx/handle.h> |
| 9 | #include <lib/zx/object.h> |
| 10 | #include <lib/zx/resource.h> |
| 11 | |
| 12 | namespace zx { |
| 13 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 14 | class debuglog final : public object<debuglog> { |
| 15 | public: |
| 16 | static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_LOG; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 17 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 18 | constexpr debuglog() = default; |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 19 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 20 | explicit debuglog(zx_handle_t value) : object(value) {} |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 21 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 22 | explicit debuglog(handle&& h) : object(h.release()) {} |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 23 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 24 | debuglog(debuglog&& other) : object(other.release()) {} |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 25 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 26 | debuglog& operator=(debuglog&& other) { |
| 27 | reset(other.release()); |
| 28 | return *this; |
| 29 | } |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 30 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 31 | static zx_status_t create(const resource& resource, uint32_t options, debuglog* result); |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 32 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 33 | zx_status_t write(uint32_t options, const void* buffer, size_t buffer_size) const { |
| 34 | return zx_debuglog_write(get(), options, buffer, buffer_size); |
| 35 | } |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 36 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 37 | zx_status_t read(uint32_t options, void* buffer, size_t buffer_size) const { |
| 38 | return zx_debuglog_read(get(), options, buffer, buffer_size); |
| 39 | } |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | using unowned_debuglog = unowned<debuglog>; |
| 43 | |
Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame] | 44 | } // namespace zx |
Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 45 | |
| 46 | #endif // LIB_ZX_DEBUGLOG_H_ |