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