blob: 2e7cf4196b29b7e9a0750b73ad708e9328e8753d [file] [log] [blame]
Doug Horn1427b6a2018-12-11 13:19:16 -08001// 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
12namespace zx {
13
Adam Barth57eacf52020-11-04 00:38:09 +000014class debuglog final : public object<debuglog> {
15 public:
16 static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_LOG;
Doug Horn1427b6a2018-12-11 13:19:16 -080017
Adam Barth57eacf52020-11-04 00:38:09 +000018 constexpr debuglog() = default;
Doug Horn1427b6a2018-12-11 13:19:16 -080019
Adam Barth57eacf52020-11-04 00:38:09 +000020 explicit debuglog(zx_handle_t value) : object(value) {}
Doug Horn1427b6a2018-12-11 13:19:16 -080021
Adam Barth57eacf52020-11-04 00:38:09 +000022 explicit debuglog(handle&& h) : object(h.release()) {}
Doug Horn1427b6a2018-12-11 13:19:16 -080023
Adam Barth57eacf52020-11-04 00:38:09 +000024 debuglog(debuglog&& other) : object(other.release()) {}
Doug Horn1427b6a2018-12-11 13:19:16 -080025
Adam Barth57eacf52020-11-04 00:38:09 +000026 debuglog& operator=(debuglog&& other) {
27 reset(other.release());
28 return *this;
29 }
Doug Horn1427b6a2018-12-11 13:19:16 -080030
Adam Barth57eacf52020-11-04 00:38:09 +000031 static zx_status_t create(const resource& resource, uint32_t options, debuglog* result);
Doug Horn1427b6a2018-12-11 13:19:16 -080032
Adam Barth57eacf52020-11-04 00:38:09 +000033 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 Horn1427b6a2018-12-11 13:19:16 -080036
Adam Barth57eacf52020-11-04 00:38:09 +000037 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 Horn1427b6a2018-12-11 13:19:16 -080040};
41
42using unowned_debuglog = unowned<debuglog>;
43
Adam Barth57eacf52020-11-04 00:38:09 +000044} // namespace zx
Doug Horn1427b6a2018-12-11 13:19:16 -080045
46#endif // LIB_ZX_DEBUGLOG_H_