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 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
6 #define MOJO_EDK_EMBEDDER_EMBEDDER_H_ | 6 #define MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
12 #include "mojo/edk/embedder/channel_info_forward.h" | 12 #include "mojo/edk/embedder/channel_info_forward.h" |
13 #include "mojo/edk/embedder/scoped_platform_handle.h" | 13 #include "mojo/edk/embedder/scoped_platform_handle.h" |
14 #include "mojo/edk/system/system_impl_export.h" | 14 #include "mojo/edk/system/system_impl_export.h" |
15 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/message_pipe.h" |
16 | 16 |
17 namespace mojo { | 17 namespace mojo { |
18 namespace embedder { | 18 namespace embedder { |
19 | 19 |
| 20 struct Configuration; |
20 class PlatformSupport; | 21 class PlatformSupport; |
21 | 22 |
22 // Must be called first to initialize the (global, singleton) system. | 23 // Must be called first, or just after setting configuration parameters, |
| 24 // to initialize the (global, singleton) system. |
23 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support); | 25 MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support); |
24 | 26 |
| 27 // Returns the global configuration. In general there should be no need to |
| 28 // change the configuration, but if you do so this must be done before calling |
| 29 // |Init()|. |
| 30 MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration(); |
| 31 |
25 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo | 32 // A "channel" is a connection on top of an OS "pipe", on top of which Mojo |
26 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread. | 33 // message pipes (etc.) can be multiplexed. It must "live" on some I/O thread. |
27 // | 34 // |
28 // There are two "channel" creation/destruction APIs: the synchronous | 35 // There are two "channel" creation/destruction APIs: the synchronous |
29 // |CreateChannelOnIOThread()|/|DestroyChannelOnIOThread()|, which must be | 36 // |CreateChannelOnIOThread()|/|DestroyChannelOnIOThread()|, which must be |
30 // called from the I/O thread, and the asynchronous | 37 // called from the I/O thread, and the asynchronous |
31 // |CreateChannel()|/|DestroyChannel()|, which may be called from any thread. | 38 // |CreateChannel()|/|DestroyChannel()|, which may be called from any thread. |
32 // | 39 // |
33 // Both creation functions have a |platform_handle| argument, which should be an | 40 // Both creation functions have a |platform_handle| argument, which should be an |
34 // OS-dependent handle to one side of a suitable bidirectional OS "pipe" (e.g., | 41 // OS-dependent handle to one side of a suitable bidirectional OS "pipe" (e.g., |
(...skipping 22 matching lines...) Expand all Loading... |
57 // respectively, and take the |ChannelInfo*| produced by the creation functions. | 64 // respectively, and take the |ChannelInfo*| produced by the creation functions. |
58 // | 65 // |
59 // TODO(vtl): Figure out channel teardown. | 66 // TODO(vtl): Figure out channel teardown. |
60 | 67 |
61 // Creates a channel; must only be called from the I/O thread. |platform_handle| | 68 // Creates a channel; must only be called from the I/O thread. |platform_handle| |
62 // should be a handle to a connected OS "pipe". Eventually (even on failure), | 69 // should be a handle to a connected OS "pipe". Eventually (even on failure), |
63 // the "out" value |*channel_info| should be passed to | 70 // the "out" value |*channel_info| should be passed to |
64 // |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the | 71 // |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the |
65 // channel. Returns a handle to the bootstrap message pipe. | 72 // channel. Returns a handle to the bootstrap message pipe. |
66 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle | 73 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle |
67 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, | 74 CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, |
68 ChannelInfo** channel_info); | 75 ChannelInfo** channel_info); |
69 | 76 |
70 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback; | 77 typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback; |
71 // Creates a channel asynchronously; may be called from any thread. | 78 // Creates a channel asynchronously; may be called from any thread. |
72 // |platform_handle| should be a handle to a connected OS "pipe". | 79 // |platform_handle| should be a handle to a connected OS "pipe". |
73 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread. | 80 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread. |
74 // |callback| should be the callback to call with the |ChannelInfo*|, which | 81 // |callback| should be the callback to call with the |ChannelInfo*|, which |
75 // should eventually be passed to |DestroyChannel()| (or | 82 // should eventually be passed to |DestroyChannel()| (or |
76 // |DestroyChannelOnIOThread()|) to tear down the channel; the callback will be | 83 // |DestroyChannelOnIOThread()|) to tear down the channel; the callback will be |
77 // called using |callback_thread_task_runner| if that is non-null, or otherwise | 84 // called using |callback_thread_task_runner| if that is non-null, or otherwise |
78 // it will be called using |io_thread_task_runner|. Returns a handle to the | 85 // it will be called using |io_thread_task_runner|. Returns a handle to the |
79 // bootstrap message pipe. | 86 // bootstrap message pipe. |
80 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle | 87 MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle |
81 CreateChannel(ScopedPlatformHandle platform_handle, | 88 CreateChannel(ScopedPlatformHandle platform_handle, |
82 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 89 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
83 DidCreateChannelCallback callback, | 90 DidCreateChannelCallback callback, |
84 scoped_refptr<base::TaskRunner> callback_thread_task_runner); | 91 scoped_refptr<base::TaskRunner> callback_thread_task_runner); |
85 | 92 |
86 // Destroys a channel that was created using either |CreateChannelOnIOThread()| | 93 // Destroys a channel that was created using either |CreateChannelOnIOThread()| |
87 // or |CreateChannel()|; must only be called from the I/O thread. |channel_info| | 94 // or |CreateChannel()|; must only be called from the I/O thread. |channel_info| |
88 // should be the "out" value from |CreateChannelOnIOThread()| or the value | 95 // should be the "out" value from |CreateChannelOnIOThread()| or the value |
89 // provided to the callback to |CreateChannel()|. | 96 // provided to the callback to |CreateChannel()|. |
90 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread( | 97 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread( |
91 ChannelInfo* channel_info); | 98 ChannelInfo* channel_info); |
92 | 99 |
93 // Destroys a channel (asynchronously) that was created using |CreateChannel()|; | 100 // Destroys a channel (asynchronously) that was created using |CreateChannel()|; |
94 // may be called from any thread. |channel_info| should be the value provided to | 101 // may be called from any thread. |channel_info| should be the value provided to |
95 // the callback to |CreateChannel()|. | 102 // the callback to |CreateChannel()|. |
96 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info); | 103 MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info); |
97 | 104 |
98 // Inform the channel that it will soon be destroyed (doing so is optional). | 105 // Inform the channel that it will soon be destroyed (doing so is optional). |
99 // This may be called from any thread, but the caller must ensure that this is | 106 // This may be called from any thread, but the caller must ensure that this is |
100 // called before |DestroyChannel()| or |DestroyChannelOnIOThread()|. | 107 // called before |DestroyChannel()| or |DestroyChannelOnIOThread()|. |
101 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info); | 108 MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info); |
102 | 109 |
103 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking | 110 // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking |
104 // ownership of it). This |MojoHandle| can then, e.g., be passed through message | 111 // ownership of it). This |MojoHandle| can then, e.g., be passed through message |
105 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on | 112 // pipes. Note: This takes ownership (and thus closes) |platform_handle| even on |
106 // failure, which is different from what you'd expect from a Mojo API, but it | 113 // failure, which is different from what you'd expect from a Mojo API, but it |
107 // makes for a more convenient embedder API. | 114 // makes for a more convenient embedder API. |
108 MOJO_SYSTEM_IMPL_EXPORT MojoResult | 115 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
109 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, | 116 CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle, |
110 MojoHandle* platform_handle_wrapper_handle); | 117 MojoHandle* platform_handle_wrapper_handle); |
111 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using | 118 // Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using |
112 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still | 119 // |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still |
113 // be closed separately. | 120 // be closed separately. |
114 MOJO_SYSTEM_IMPL_EXPORT MojoResult | 121 MOJO_SYSTEM_IMPL_EXPORT MojoResult |
115 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, | 122 PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
116 ScopedPlatformHandle* platform_handle); | 123 ScopedPlatformHandle* platform_handle); |
117 | 124 |
118 } // namespace embedder | 125 } // namespace embedder |
119 } // namespace mojo | 126 } // namespace mojo |
120 | 127 |
121 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ | 128 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_H_ |
OLD | NEW |