Index: mojo/public/cpp/system/buffer.cc |
diff --git a/mojo/public/cpp/system/buffer.cc b/mojo/public/cpp/system/buffer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dcc2b8b517a0558b65325a62b7196722f9d76a42 |
--- /dev/null |
+++ b/mojo/public/cpp/system/buffer.cc |
@@ -0,0 +1,36 @@ |
+// Copyright 2016 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. |
+ |
+#include "mojo/public/cpp/system/buffer.h" |
+ |
+namespace mojo { |
+ |
+ScopedSharedBufferHandle SharedBufferHandle::Clone(bool read_only) const { |
Ken Rockot(use gerrit already)
2016/06/03 20:14:35
optional nit: Maybe add an enum in SharedBufferHan
Sam McNally
2016/06/05 23:49:20
Done.
|
+ ScopedSharedBufferHandle result; |
+ if (!is_valid()) |
+ return result; |
+ |
+ MojoDuplicateBufferHandleOptions options = { |
+ sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; |
+ if (read_only) |
+ options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY; |
+ SharedBufferHandle result_handle; |
+ MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value()); |
+ result.reset(result_handle); |
+ return result; |
+} |
+ |
+ScopedSharedBufferMapping SharedBufferHandle::Map(uint64_t size) const { |
+ return MapAtOffset(size, 0); |
+} |
+ |
+ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset( |
+ uint64_t size, |
+ uint64_t offset) const { |
+ void* buffer = nullptr; |
+ MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE); |
+ return ScopedSharedBufferMapping(buffer); |
+} |
+ |
+} // namespace mojo |