Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3457)

Unified Diff: dbus/file_descriptor.h

Issue 9700072: dbus: add support for passing file descriptors (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: add dbus::FileDescriptor per keybuk's request Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dbus/file_descriptor.h
diff --git a/dbus/file_descriptor.h b/dbus/file_descriptor.h
new file mode 100644
index 0000000000000000000000000000000000000000..e4d5710dfa2e7f3dec0421c4e37d8194cb5809c2
--- /dev/null
+++ b/dbus/file_descriptor.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 The Chromium 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 DBUS_FILE_DESCRIPTOR_H_
+#define DBUS_FILE_DESCRIPTOR_H_
+#pragma once
+
+namespace dbus {
+
+// FileDescriptor is a type used to encapsulate D-Bus file descriptors
+// and to follow the RAII idiom appropiate for use with message operations
+// where the descriptor might be easily leaked. Ownership is asserted
+// only when PutValue is used.
+class FileDescriptor {
+ public:
+ // Permit initialization without a value for passing to
satorux1 2012/03/28 00:32:43 nit: Permit -> Permits. Please also fix other plac
Sam Leffler 2012/03/28 17:28:09 Not sure which clause you're pointed me at but "Pe
satorux1 2012/03/28 17:30:16 These comments should be descriptive ("Opens the f
Sam Leffler 2012/03/28 19:25:27 Done.
+ // dbus::MessageReader::PopFileDescriptor to fill in and from int values.
+ FileDescriptor() : value_(-1), owner_(true) {}
keybuk 2012/03/27 22:36:35 owner_(true) here means you'll close(-1) later; be
+ explicit FileDescriptor(int value) : value_(value), owner_(false) {}
satorux1 2012/03/28 00:32:43 Could you remove the default constructor? The st
Sam Leffler 2012/03/28 17:28:09 This cribs from dbus::ObjectPath. Removing it make
+
+ virtual ~FileDescriptor();
+
+ // Retrieve value as an int.
keybuk 2012/03/28 17:57:37 nit: Retrieves. Also explain that this does not ta
+ int value() const { return value_; }
+
+ // Set the value and assign ownership.
keybuk 2012/03/28 17:57:37 nit: Sets
+ void PutValue(int value) {
satorux1 2012/03/28 00:32:43 Put -> Set? Set is more common for this.
Sam Leffler 2012/03/28 17:28:09 Please get together w/ keybuk and decide which way
keybuk 2012/03/28 17:57:37 I asked Sam to change this from Set to Put because
+ value_ = value;
+ owner_ = true;
+ }
+
+ // Take the value and ownership.
+ int TakeValue(void) {
satorux1 2012/03/28 00:32:43 nit: (void) -> ()
Sam Leffler 2012/03/28 17:28:09 Done.
+ owner_ = false;
+ return value_;
satorux1 2012/03/28 00:32:43 I guess owner_ is unnecessary. We can use -1 as no
Sam Leffler 2012/03/28 17:28:09 They are not equivalent. It is useful to preserve
keybuk 2012/03/28 17:57:37 It's probably worth explaining in the class commen
Sam Leffler 2012/03/28 19:25:27 Done.
+ }
satorux1 2012/03/28 00:32:43 nit: we usually have a blank line here.
Sam Leffler 2012/03/28 17:28:09 Done.
+ private:
+ int value_;
+ bool owner_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileDescriptor);
+};
+
+} // namespace dbus
+
+#endif // DBUS_FILE_DESCRIPTOR_H_
« no previous file with comments | « dbus/dbus.gyp ('k') | dbus/file_descriptor.cc » ('j') | dbus/file_descriptor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698