diff options
author | Sen Jiang <senj@google.com> | 2018-08-09 16:52:23 -0700 |
---|---|---|
committer | Sen Jiang <senj@google.com> | 2018-08-10 11:07:06 -0700 |
commit | 0fa01c38cc2beff8d7e11e4b512692ecdb640ca8 (patch) | |
tree | 279e9e692e3a7db704f65e6d3977e43e8e75b46a /brillo/dbus/file_descriptor.h | |
parent | b5f20f52ab0885f1676b1c2024df541b3e6cc5f5 (diff) | |
parent | 904c2c9cd8d5ff06783030fb27ee23dcff743035 (diff) | |
download | platform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.tar.gz platform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.tar.bz2 platform_external_libbrillo-0fa01c38cc2beff8d7e11e4b512692ecdb640ca8.zip |
Merge remote-tracking branch 'aosp/upstream-master' into aosp/master.android-o-mr1-iot-release-1.0.4
Merge Chromium ToT to AOSP:
git fetch aosp upstream-master
git merge -X patience aosp/upstream-master
Bug: 112326236
Test: libbrillo_test
Change-Id: I35fbbddad556b051ce12b9cdd95bb2afef3cf6af
Diffstat (limited to 'brillo/dbus/file_descriptor.h')
-rw-r--r-- | brillo/dbus/file_descriptor.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/brillo/dbus/file_descriptor.h b/brillo/dbus/file_descriptor.h new file mode 100644 index 0000000..f7be44f --- /dev/null +++ b/brillo/dbus/file_descriptor.h @@ -0,0 +1,57 @@ +// Copyright 2018 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBBRILLO_BRILLO_DBUS_FILE_DESCRIPTOR_H_ +#define LIBBRILLO_BRILLO_DBUS_FILE_DESCRIPTOR_H_ + +#include <base/files/scoped_file.h> +#include <base/macros.h> + +namespace brillo { +namespace dbus_utils { + +// This struct wraps file descriptors to give them a type other than int. +// Implicit conversions are provided because this should be as transparent +// a wrapper as possible to match the libchrome bindings below when this +// class is used by chromeos-dbus-bindings. +// +// Because we might pass these around and the calling code neither passes +// ownership nor knows when this will be destroyed, it actually dups the FD +// so that the calling code and binding code both have a clear handle on the +// lifetimes of their respective copies of the FD. +struct FileDescriptor { + FileDescriptor() = default; + FileDescriptor(int fd) : fd(dup(fd)) {} + FileDescriptor(FileDescriptor&& other) : fd(std::move(other.fd)) {} + FileDescriptor(base::ScopedFD&& other) : fd(std::move(other)) {} + + inline FileDescriptor& operator=(int new_fd) { + fd.reset(dup(new_fd)); + return *this; + } + + FileDescriptor& operator=(FileDescriptor&& other) { + fd = std::move(other.fd); + return *this; + } + + FileDescriptor& operator=(base::ScopedFD&& other) { + fd = std::move(other); + return *this; + } + + int release() { return fd.release(); } + + int get() const { return fd.get(); } + + private: + DISALLOW_COPY_AND_ASSIGN(FileDescriptor); + + base::ScopedFD fd; +}; + +} // namespace dbus_utils +} // namespace brillo + +#endif // LIBBRILLO_BRILLO_DBUS_FILE_DESCRIPTOR_H_ |