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_EDK_SYSTEM_CORE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CORE_H_ |
6 #define MOJO_EDK_SYSTEM_CORE_H_ | 6 #define MOJO_EDK_SYSTEM_CORE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
11 | 11 |
| 12 #include "mojo/edk/system/entrypoint_class.h" |
12 #include "mojo/edk/system/handle.h" | 13 #include "mojo/edk/system/handle.h" |
13 #include "mojo/edk/system/handle_table.h" | 14 #include "mojo/edk/system/handle_table.h" |
14 #include "mojo/edk/system/mapping_table.h" | 15 #include "mojo/edk/system/mapping_table.h" |
15 #include "mojo/edk/system/memory.h" | 16 #include "mojo/edk/system/memory.h" |
16 #include "mojo/edk/util/mutex.h" | 17 #include "mojo/edk/util/mutex.h" |
17 #include "mojo/edk/util/ref_ptr.h" | 18 #include "mojo/edk/util/ref_ptr.h" |
18 #include "mojo/edk/util/thread_annotations.h" | 19 #include "mojo/edk/util/thread_annotations.h" |
19 #include "mojo/public/c/system/buffer.h" | 20 #include "mojo/public/c/system/buffer.h" |
20 #include "mojo/public/c/system/data_pipe.h" | 21 #include "mojo/public/c/system/data_pipe.h" |
21 #include "mojo/public/c/system/handle.h" | 22 #include "mojo/public/c/system/handle.h" |
(...skipping 26 matching lines...) Expand all Loading... |
48 | 49 |
49 // |*platform_support| must outlive this object. | 50 // |*platform_support| must outlive this object. |
50 explicit Core(embedder::PlatformSupport* platform_support); | 51 explicit Core(embedder::PlatformSupport* platform_support); |
51 virtual ~Core(); | 52 virtual ~Core(); |
52 | 53 |
53 // Adds |handle| (which must have a dispatcher) to the handle table, returning | 54 // Adds |handle| (which must have a dispatcher) to the handle table, returning |
54 // the handle value for it. Returns |MOJO_HANDLE_INVALID| on failure, namely | 55 // the handle value for it. Returns |MOJO_HANDLE_INVALID| on failure, namely |
55 // if the handle table is full. | 56 // if the handle table is full. |
56 MojoHandle AddHandle(Handle&& h); | 57 MojoHandle AddHandle(Handle&& h); |
57 | 58 |
58 // Looks up the dispatcher for the given handle value. On success, gets the | 59 // Gets the handle for the given handle value. On success, returns |
59 // dispatcher for a given handle value. On failure, returns an appropriate | 60 // |MOJO_RESULT_OK| (and sets |*h|). On failure, returns an appropriate result |
60 // result and leaves |dispatcher| alone), namely | 61 // (and leaves |*h| alone), namely |MOJO_RESULT_INVALID_ARGUMENT| if the |
61 // |MOJO_RESULT_INVALID_ARGUMENT| if the handle value is invalid or | 62 // handle value is invalid or |MOJO_RESULT_BUSY| if the handle is marked as |
62 // |MOJO_RESULT_BUSY| if the handle is marked as busy. | 63 // busy. |
| 64 MojoResult GetHandle(MojoHandle handle, Handle* h); |
| 65 // TODO(vtl): Remove this. |
63 MojoResult GetDispatcher(MojoHandle handle, | 66 MojoResult GetDispatcher(MojoHandle handle, |
64 util::RefPtr<Dispatcher>* dispatcher); | 67 util::RefPtr<Dispatcher>* dispatcher); |
65 | 68 |
| 69 // TODO(vtl): Convert this to |GetAndRemoveHandle()|. |
66 // Like |GetDispatcher()|, but on success also removes the handle from the | 70 // Like |GetDispatcher()|, but on success also removes the handle from the |
67 // handle table. | 71 // handle table. |
68 MojoResult GetAndRemoveDispatcher(MojoHandle handle, | 72 MojoResult GetAndRemoveDispatcher(MojoHandle handle, |
69 util::RefPtr<Dispatcher>* dispatcher); | 73 util::RefPtr<Dispatcher>* dispatcher); |
70 | 74 |
| 75 // Gets the dispatcher for the given handle value, which must have (all of) |
| 76 // the rights in |required_handle_rights|. |
| 77 // |
| 78 // On success, returns |MOJO_RESULT_OK| and sets |*dispatcher| appropriately. |
| 79 // On failure, returns: |
| 80 // - |MOJO_RESULT_INVALID_ARGUMENT| if there's no handle for the given |
| 81 // handle value (or the handle value was |MOJO_HANDLE_INVALID|), |
| 82 // - |MOJO_RESULT_BUSY| if the handle is marked as busy, |
| 83 // - |MOJO_RESULT_PERMISSION_DENIED| if the handle does not have the |
| 84 // required rights *and* the dispatcher supports the specified |
| 85 // |entrypoint_class|, or |
| 86 // - |MOJO_RESULT_INVALID_ARGUMENT| if the handle does not have the required |
| 87 // rights *but* the dispatcher does not support |entrypoint_class|. |
| 88 // (Warning: if the handle has the required rights, then its dispatcher will |
| 89 // be returned even if the dispatcher does not support |entrypoint_class|.) |
| 90 MojoResult GetDispatcherAndCheckRights( |
| 91 MojoHandle handle_value, |
| 92 MojoHandleRights required_handle_rights, |
| 93 EntrypointClass entrypoint_class, |
| 94 util::RefPtr<Dispatcher>* dispatcher); |
| 95 |
71 // Watches on the given handle for the given signals, calling |callback| when | 96 // Watches on the given handle for the given signals, calling |callback| when |
72 // a signal is satisfied or when all signals become unsatisfiable. |callback| | 97 // a signal is satisfied or when all signals become unsatisfiable. |callback| |
73 // must satisfy stringent requirements -- see |Awakable::Awake()| in | 98 // must satisfy stringent requirements -- see |Awakable::Awake()| in |
74 // awakable.h. In particular, it must not call any Mojo system functions. | 99 // awakable.h. In particular, it must not call any Mojo system functions. |
75 MojoResult AsyncWait(MojoHandle handle, | 100 MojoResult AsyncWait(MojoHandle handle, |
76 MojoHandleSignals signals, | 101 MojoHandleSignals signals, |
77 const std::function<void(MojoResult)>& callback); | 102 const std::function<void(MojoResult)>& callback); |
78 | 103 |
79 embedder::PlatformSupport* platform_support() const { | 104 embedder::PlatformSupport* platform_support() const { |
80 return platform_support_; | 105 return platform_support_; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 util::Mutex mapping_table_mutex_; | 239 util::Mutex mapping_table_mutex_; |
215 MappingTable mapping_table_ MOJO_GUARDED_BY(mapping_table_mutex_); | 240 MappingTable mapping_table_ MOJO_GUARDED_BY(mapping_table_mutex_); |
216 | 241 |
217 MOJO_DISALLOW_COPY_AND_ASSIGN(Core); | 242 MOJO_DISALLOW_COPY_AND_ASSIGN(Core); |
218 }; | 243 }; |
219 | 244 |
220 } // namespace system | 245 } // namespace system |
221 } // namespace mojo | 246 } // namespace mojo |
222 | 247 |
223 #endif // MOJO_EDK_SYSTEM_CORE_H_ | 248 #endif // MOJO_EDK_SYSTEM_CORE_H_ |
OLD | NEW |