OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 platform handles, | 5 // This file provides a C++ wrapping around the Mojo C API for platform handles, |
6 // replacing the prefix of "Mojo" with a "mojo" namespace. | 6 // replacing the prefix of "Mojo" with a "mojo" namespace. |
7 // | 7 // |
8 // Please see "mojo/public/c/system/platform_handle.h" for complete | 8 // Please see "mojo/public/c/system/platform_handle.h" for complete |
9 // documentation of the API. | 9 // documentation of the API. |
10 | 10 |
11 #ifndef MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ | 11 #ifndef MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ |
12 #define MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ | 12 #define MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ |
13 | 13 |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/files/file.h" | 17 #include "base/files/file.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/shared_memory_handle.h" | 20 #include "base/memory/shared_memory_handle.h" |
21 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
22 #include "mojo/public/c/system/platform_handle.h" | 22 #include "mojo/public/c/system/platform_handle.h" |
23 #include "mojo/public/cpp/system/buffer.h" | 23 #include "mojo/public/cpp/system/buffer.h" |
24 #include "mojo/public/cpp/system/handle.h" | 24 #include "mojo/public/cpp/system/handle.h" |
| 25 #include "mojo/public/cpp/system/system_export.h" |
25 | 26 |
26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
27 #include <windows.h> | 28 #include <windows.h> |
28 #endif | 29 #endif |
29 | 30 |
30 namespace mojo { | 31 namespace mojo { |
31 | 32 |
32 #if defined(OS_POSIX) | 33 #if defined(OS_POSIX) |
33 const MojoPlatformHandleType kPlatformFileHandleType = | 34 const MojoPlatformHandleType kPlatformFileHandleType = |
34 MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR; | 35 MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR; |
35 | 36 |
36 #if defined(OS_MACOSX) && !defined(OS_IOS) | 37 #if defined(OS_MACOSX) && !defined(OS_IOS) |
37 const MojoPlatformHandleType kPlatformSharedBufferHandleType = | 38 const MojoPlatformHandleType kPlatformSharedBufferHandleType = |
38 MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT; | 39 MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT; |
39 #else | 40 #else |
40 const MojoPlatformHandleType kPlatformSharedBufferHandleType = | 41 const MojoPlatformHandleType kPlatformSharedBufferHandleType = |
41 MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR; | 42 MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR; |
42 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 43 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
43 | 44 |
44 #elif defined(OS_WIN) | 45 #elif defined(OS_WIN) |
45 const MojoPlatformHandleType kPlatformFileHandleType = | 46 const MojoPlatformHandleType kPlatformFileHandleType = |
46 MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; | 47 MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; |
47 | 48 |
48 const MojoPlatformHandleType kPlatformSharedBufferHandleType = | 49 const MojoPlatformHandleType kPlatformSharedBufferHandleType = |
49 MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; | 50 MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; |
50 #endif // defined(OS_POSIX) | 51 #endif // defined(OS_POSIX) |
51 | 52 |
52 // Wraps a PlatformFile as a Mojo handle. Takes ownership of the file object. | 53 // Wraps a PlatformFile as a Mojo handle. Takes ownership of the file object. |
53 ScopedHandle WrapPlatformFile(base::PlatformFile platform_file); | 54 ScopedHandle MOJO_CPP_SYSTEM_EXPORT |
| 55 WrapPlatformFile(base::PlatformFile platform_file); |
54 | 56 |
55 // Unwraps a PlatformFile from a Mojo handle. | 57 // Unwraps a PlatformFile from a Mojo handle. |
56 MojoResult UnwrapPlatformFile(ScopedHandle handle, base::PlatformFile* file); | 58 MojoResult MOJO_CPP_SYSTEM_EXPORT UnwrapPlatformFile(ScopedHandle handle, |
| 59 base::PlatformFile* file); |
57 | 60 |
58 // Wraps a base::SharedMemoryHandle as a Mojo handle. Takes ownership of the | 61 // Wraps a base::SharedMemoryHandle as a Mojo handle. Takes ownership of the |
59 // SharedMemoryHandle. Note that |read_only| is only an indicator of whether | 62 // SharedMemoryHandle. Note that |read_only| is only an indicator of whether |
60 // |memory_handle| only supports read-only mapping. It does NOT have any | 63 // |memory_handle| only supports read-only mapping. It does NOT have any |
61 // influence on the access control of the shared buffer object. | 64 // influence on the access control of the shared buffer object. |
62 ScopedSharedBufferHandle WrapSharedMemoryHandle( | 65 ScopedSharedBufferHandle WrapSharedMemoryHandle( |
63 const base::SharedMemoryHandle& memory_handle, | 66 const base::SharedMemoryHandle& memory_handle, |
64 size_t size, | 67 size_t size, |
65 bool read_only); | 68 bool read_only); |
66 | 69 |
67 // Unwraps a base::SharedMemoryHandle from a Mojo handle. The caller assumes | 70 // Unwraps a base::SharedMemoryHandle from a Mojo handle. The caller assumes |
68 // responsibility for the lifetime of the SharedMemoryHandle. | 71 // responsibility for the lifetime of the SharedMemoryHandle. |
69 MojoResult UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle, | 72 MojoResult MOJO_CPP_SYSTEM_EXPORT |
70 base::SharedMemoryHandle* memory_handle, | 73 UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle, |
71 size_t* size, | 74 base::SharedMemoryHandle* memory_handle, |
72 bool* read_only); | 75 size_t* size, |
| 76 bool* read_only); |
73 | 77 |
74 } // namespace mojo | 78 } // namespace mojo |
75 | 79 |
76 #endif // MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ | 80 #endif // MOJO_PUBLIC_CPP_SYSTEM_PLATFORM_HANDLE_H_ |
OLD | NEW |