| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SYSTEM_CORE_H_ | 5 #ifndef MOJO_SYSTEM_CORE_H_ |
| 6 #define MOJO_SYSTEM_CORE_H_ | 6 #define MOJO_SYSTEM_CORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 13 #include "mojo/public/c/system/buffer.h" | 14 #include "mojo/public/c/system/buffer.h" |
| 14 #include "mojo/public/c/system/data_pipe.h" | 15 #include "mojo/public/c/system/data_pipe.h" |
| 15 #include "mojo/public/c/system/message_pipe.h" | 16 #include "mojo/public/c/system/message_pipe.h" |
| 16 #include "mojo/public/c/system/types.h" | 17 #include "mojo/public/c/system/types.h" |
| 17 #include "mojo/system/handle_table.h" | 18 #include "mojo/system/handle_table.h" |
| 18 #include "mojo/system/mapping_table.h" | 19 #include "mojo/system/mapping_table.h" |
| 19 #include "mojo/system/memory.h" | 20 #include "mojo/system/memory.h" |
| 20 #include "mojo/system/system_impl_export.h" | 21 #include "mojo/system/system_impl_export.h" |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 24 |
| 25 namespace embedder { |
| 26 class PlatformSupport; |
| 27 } |
| 28 |
| 23 namespace system { | 29 namespace system { |
| 24 | 30 |
| 25 class Dispatcher; | 31 class Dispatcher; |
| 26 struct HandleSignalsState; | 32 struct HandleSignalsState; |
| 27 | 33 |
| 28 // |Core| is an object that implements the Mojo system calls. All public methods | 34 // |Core| is an object that implements the Mojo system calls. All public methods |
| 29 // are thread-safe. | 35 // are thread-safe. |
| 30 class MOJO_SYSTEM_IMPL_EXPORT Core { | 36 class MOJO_SYSTEM_IMPL_EXPORT Core { |
| 31 public: | 37 public: |
| 32 // These methods are only to be used by via the embedder API (and internally). | 38 // --------------------------------------------------------------------------- |
| 39 |
| 40 // These methods are only to be used by via the embedder API (and internally): |
| 33 Core(); | 41 Core(); |
| 34 virtual ~Core(); | 42 virtual ~Core(); |
| 35 | 43 |
| 36 // Adds |dispatcher| to the handle table, returning the handle for it. Returns | 44 // Adds |dispatcher| to the handle table, returning the handle for it. Returns |
| 37 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. | 45 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. |
| 38 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); | 46 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); |
| 39 | 47 |
| 40 // Looks up the dispatcher for the given handle. Returns null if the handle is | 48 // Looks up the dispatcher for the given handle. Returns null if the handle is |
| 41 // invalid. | 49 // invalid. |
| 42 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); | 50 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); |
| 43 | 51 |
| 44 // System calls implementation. | 52 embedder::PlatformSupport* platform_support() const { |
| 53 return platform_support_.get(); |
| 54 } |
| 55 |
| 56 // --------------------------------------------------------------------------- |
| 57 |
| 58 // System calls implementation: |
| 45 MojoTimeTicks GetTimeTicksNow(); | 59 MojoTimeTicks GetTimeTicksNow(); |
| 46 MojoResult Close(MojoHandle handle); | 60 MojoResult Close(MojoHandle handle); |
| 47 MojoResult Wait(MojoHandle handle, | 61 MojoResult Wait(MojoHandle handle, |
| 48 MojoHandleSignals signals, | 62 MojoHandleSignals signals, |
| 49 MojoDeadline deadline, | 63 MojoDeadline deadline, |
| 50 UserPointer<MojoHandleSignalsState> signals_state); | 64 UserPointer<MojoHandleSignalsState> signals_state); |
| 51 MojoResult WaitMany(UserPointer<const MojoHandle> handles, | 65 MojoResult WaitMany(UserPointer<const MojoHandle> handles, |
| 52 UserPointer<const MojoHandleSignals> signals, | 66 UserPointer<const MojoHandleSignals> signals, |
| 53 uint32_t num_handles, | 67 uint32_t num_handles, |
| 54 MojoDeadline deadline, | 68 MojoDeadline deadline, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // validation of arguments. |*result_index| is only set if the result (whether | 130 // validation of arguments. |*result_index| is only set if the result (whether |
| 117 // success or failure) applies to a specific handle, so its value should be | 131 // success or failure) applies to a specific handle, so its value should be |
| 118 // preinitialized to |static_cast<uint32_t>(-1)|. | 132 // preinitialized to |static_cast<uint32_t>(-1)|. |
| 119 MojoResult WaitManyInternal(const MojoHandle* handles, | 133 MojoResult WaitManyInternal(const MojoHandle* handles, |
| 120 const MojoHandleSignals* signals, | 134 const MojoHandleSignals* signals, |
| 121 uint32_t num_handles, | 135 uint32_t num_handles, |
| 122 MojoDeadline deadline, | 136 MojoDeadline deadline, |
| 123 uint32_t* result_index, | 137 uint32_t* result_index, |
| 124 HandleSignalsState* signals_states); | 138 HandleSignalsState* signals_states); |
| 125 | 139 |
| 126 // --------------------------------------------------------------------------- | 140 const scoped_ptr<embedder::PlatformSupport> platform_support_; |
| 127 | 141 |
| 128 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we | 142 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we |
| 129 // had them). | 143 // had them). |
| 130 base::Lock handle_table_lock_; // Protects |handle_table_|. | 144 base::Lock handle_table_lock_; // Protects |handle_table_|. |
| 131 HandleTable handle_table_; | 145 HandleTable handle_table_; |
| 132 | 146 |
| 133 base::Lock mapping_table_lock_; // Protects |mapping_table_|. | 147 base::Lock mapping_table_lock_; // Protects |mapping_table_|. |
| 134 MappingTable mapping_table_; | 148 MappingTable mapping_table_; |
| 135 | 149 |
| 136 // --------------------------------------------------------------------------- | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(Core); | 150 DISALLOW_COPY_AND_ASSIGN(Core); |
| 139 }; | 151 }; |
| 140 | 152 |
| 141 } // namespace system | 153 } // namespace system |
| 142 } // namespace mojo | 154 } // namespace mojo |
| 143 | 155 |
| 144 #endif // MOJO_SYSTEM_CORE_H_ | 156 #endif // MOJO_SYSTEM_CORE_H_ |
| OLD | NEW |