OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file provides a C++ wrapping around the Mojo C API for shared buffers, | 5 // This file provides a C++ wrapping around the Mojo C API for shared buffers, |
6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more | 6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more |
7 // strongly-typed representations of |MojoHandle|s. | 7 // strongly-typed representations of |MojoHandle|s. |
8 // | 8 // |
9 // Please see "mojo/public/c/system/buffer.h" for complete documentation of the | 9 // Please see "mojo/public/c/system/buffer.h" for complete documentation of the |
10 // API. | 10 // API. |
11 | 11 |
12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ | 12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ |
13 #define MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ | 13 #define MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ |
14 | 14 |
15 #include <stdint.h> | 15 #include <stdint.h> |
16 | 16 |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "mojo/public/c/system/buffer.h" | 21 #include "mojo/public/c/system/buffer.h" |
22 #include "mojo/public/cpp/system/handle.h" | 22 #include "mojo/public/cpp/system/handle.h" |
| 23 #include "mojo/public/cpp/system/system_export.h" |
23 | 24 |
24 namespace mojo { | 25 namespace mojo { |
25 namespace internal { | 26 namespace internal { |
26 | 27 |
27 struct Unmapper { | 28 struct Unmapper { |
28 void operator()(void* buffer) { | 29 void operator()(void* buffer) { |
29 MojoResult result = MojoUnmapBuffer(buffer); | 30 MojoResult result = MojoUnmapBuffer(buffer); |
30 DCHECK_EQ(MOJO_RESULT_OK, result); | 31 DCHECK_EQ(MOJO_RESULT_OK, result); |
31 } | 32 } |
32 }; | 33 }; |
33 | 34 |
34 } // namespace internal | 35 } // namespace internal |
35 | 36 |
36 using ScopedSharedBufferMapping = std::unique_ptr<void, internal::Unmapper>; | 37 using ScopedSharedBufferMapping = std::unique_ptr<void, internal::Unmapper>; |
37 | 38 |
38 class SharedBufferHandle; | 39 class SharedBufferHandle; |
39 | 40 |
40 typedef ScopedHandleBase<SharedBufferHandle> ScopedSharedBufferHandle; | 41 typedef ScopedHandleBase<SharedBufferHandle> ScopedSharedBufferHandle; |
41 | 42 |
42 // A strongly-typed representation of a |MojoHandle| referring to a shared | 43 // A strongly-typed representation of a |MojoHandle| referring to a shared |
43 // buffer. | 44 // buffer. |
44 class SharedBufferHandle : public Handle { | 45 class MOJO_CPP_SYSTEM_EXPORT SharedBufferHandle |
| 46 : NON_EXPORTED_BASE(public Handle) { |
45 public: | 47 public: |
46 enum class AccessMode { | 48 enum class AccessMode { |
47 READ_WRITE, | 49 READ_WRITE, |
48 READ_ONLY, | 50 READ_ONLY, |
49 }; | 51 }; |
50 | 52 |
51 SharedBufferHandle() {} | 53 SharedBufferHandle() {} |
52 explicit SharedBufferHandle(MojoHandle value) : Handle(value) {} | 54 explicit SharedBufferHandle(MojoHandle value) : Handle(value) {} |
53 | 55 |
54 // Copying and assignment allowed. | 56 // Copying and assignment allowed. |
(...skipping 16 matching lines...) Expand all Loading... |
71 }; | 73 }; |
72 | 74 |
73 static_assert(sizeof(SharedBufferHandle) == sizeof(Handle), | 75 static_assert(sizeof(SharedBufferHandle) == sizeof(Handle), |
74 "Bad size for C++ SharedBufferHandle"); | 76 "Bad size for C++ SharedBufferHandle"); |
75 static_assert(sizeof(ScopedSharedBufferHandle) == sizeof(SharedBufferHandle), | 77 static_assert(sizeof(ScopedSharedBufferHandle) == sizeof(SharedBufferHandle), |
76 "Bad size for C++ ScopedSharedBufferHandle"); | 78 "Bad size for C++ ScopedSharedBufferHandle"); |
77 | 79 |
78 } // namespace mojo | 80 } // namespace mojo |
79 | 81 |
80 #endif // MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ | 82 #endif // MOJO_PUBLIC_CPP_SYSTEM_BUFFER_H_ |
OLD | NEW |