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 #include "mojo/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "mojo/edk/system/handle_signals_state.h" | 28 #include "mojo/edk/system/handle_signals_state.h" |
29 #include "mojo/edk/system/message_for_transit.h" | 29 #include "mojo/edk/system/message_for_transit.h" |
30 #include "mojo/edk/system/message_pipe_dispatcher.h" | 30 #include "mojo/edk/system/message_pipe_dispatcher.h" |
31 #include "mojo/edk/system/platform_handle_dispatcher.h" | 31 #include "mojo/edk/system/platform_handle_dispatcher.h" |
32 #include "mojo/edk/system/ports/name.h" | 32 #include "mojo/edk/system/ports/name.h" |
33 #include "mojo/edk/system/ports/node.h" | 33 #include "mojo/edk/system/ports/node.h" |
34 #include "mojo/edk/system/request_context.h" | 34 #include "mojo/edk/system/request_context.h" |
35 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 35 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
36 #include "mojo/edk/system/wait_set_dispatcher.h" | 36 #include "mojo/edk/system/wait_set_dispatcher.h" |
37 #include "mojo/edk/system/waiter.h" | 37 #include "mojo/edk/system/waiter.h" |
| 38 #include "mojo/edk/system/watcher_dispatcher.h" |
38 | 39 |
39 namespace mojo { | 40 namespace mojo { |
40 namespace edk { | 41 namespace edk { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 // This is an unnecessarily large limit that is relatively easy to enforce. | 45 // This is an unnecessarily large limit that is relatively easy to enforce. |
45 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; | 46 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; |
46 | 47 |
47 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process | 48 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process |
48 // pipes too; for now we just use a constant. This only affects bootstrap pipes. | 49 // pipes too; for now we just use a constant. This only affects bootstrap pipes. |
49 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; | 50 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; |
50 | 51 |
51 void CallWatchCallback(MojoWatchCallback callback, | |
52 uintptr_t context, | |
53 MojoResult result, | |
54 const HandleSignalsState& signals_state, | |
55 MojoWatchNotificationFlags flags) { | |
56 callback(context, result, static_cast<MojoHandleSignalsState>(signals_state), | |
57 flags); | |
58 } | |
59 | |
60 MojoResult MojoPlatformHandleToScopedPlatformHandle( | 52 MojoResult MojoPlatformHandleToScopedPlatformHandle( |
61 const MojoPlatformHandle* platform_handle, | 53 const MojoPlatformHandle* platform_handle, |
62 ScopedPlatformHandle* out_handle) { | 54 ScopedPlatformHandle* out_handle) { |
63 if (platform_handle->struct_size != sizeof(MojoPlatformHandle)) | 55 if (platform_handle->struct_size != sizeof(MojoPlatformHandle)) |
64 return MOJO_RESULT_INVALID_ARGUMENT; | 56 return MOJO_RESULT_INVALID_ARGUMENT; |
65 | 57 |
66 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) { | 58 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) { |
67 out_handle->reset(); | 59 out_handle->reset(); |
68 return MOJO_RESULT_OK; | 60 return MOJO_RESULT_OK; |
69 } | 61 } |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a | 412 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a |
421 // subclass of |MojoHandleSignalsState| that doesn't add any data members. | 413 // subclass of |MojoHandleSignalsState| that doesn't add any data members. |
422 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, | 414 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, |
423 reinterpret_cast<HandleSignalsState*>(signals_state)); | 415 reinterpret_cast<HandleSignalsState*>(signals_state)); |
424 } | 416 } |
425 if (index != static_cast<uint32_t>(-1) && result_index) | 417 if (index != static_cast<uint32_t>(-1) && result_index) |
426 *result_index = index; | 418 *result_index = index; |
427 return rv; | 419 return rv; |
428 } | 420 } |
429 | 421 |
430 MojoResult Core::Watch(MojoHandle handle, | 422 MojoResult Core::CreateWatcher(MojoWatcherCallback callback, |
| 423 MojoHandle* watcher_handle) { |
| 424 RequestContext request_context; |
| 425 if (!watcher_handle) |
| 426 return MOJO_RESULT_INVALID_ARGUMENT; |
| 427 *watcher_handle = AddDispatcher(new WatcherDispatcher(callback)); |
| 428 if (*watcher_handle == MOJO_HANDLE_INVALID) |
| 429 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 430 return MOJO_RESULT_OK; |
| 431 } |
| 432 |
| 433 MojoResult Core::Watch(MojoHandle watcher_handle, |
| 434 MojoHandle handle, |
431 MojoHandleSignals signals, | 435 MojoHandleSignals signals, |
432 MojoWatchCallback callback, | |
433 uintptr_t context) { | 436 uintptr_t context) { |
434 RequestContext request_context; | 437 RequestContext request_context; |
| 438 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); |
| 439 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) |
| 440 return MOJO_RESULT_INVALID_ARGUMENT; |
435 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); | 441 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); |
436 if (!dispatcher) | 442 if (!dispatcher) |
437 return MOJO_RESULT_INVALID_ARGUMENT; | 443 return MOJO_RESULT_INVALID_ARGUMENT; |
438 return dispatcher->Watch( | 444 return watcher->WatchDispatcher(dispatcher, signals, context); |
439 signals, base::Bind(&CallWatchCallback, callback, context), context); | |
440 } | 445 } |
441 | 446 |
442 MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) { | 447 MojoResult Core::CancelWatch(MojoHandle watcher_handle, uintptr_t context) { |
443 RequestContext request_context; | 448 RequestContext request_context; |
444 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); | 449 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); |
445 if (!dispatcher) | 450 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) |
446 return MOJO_RESULT_INVALID_ARGUMENT; | 451 return MOJO_RESULT_INVALID_ARGUMENT; |
447 return dispatcher->CancelWatch(context); | 452 return watcher->CancelWatch(context); |
| 453 } |
| 454 |
| 455 MojoResult Core::ArmWatcher(MojoHandle watcher_handle, |
| 456 uint32_t* num_ready_contexts, |
| 457 uintptr_t* ready_contexts, |
| 458 MojoResult* ready_results, |
| 459 MojoHandleSignalsState* ready_signals_states) { |
| 460 RequestContext request_context; |
| 461 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); |
| 462 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) |
| 463 return MOJO_RESULT_INVALID_ARGUMENT; |
| 464 return watcher->Arm(num_ready_contexts, ready_contexts, ready_results, |
| 465 ready_signals_states); |
448 } | 466 } |
449 | 467 |
450 MojoResult Core::AllocMessage(uint32_t num_bytes, | 468 MojoResult Core::AllocMessage(uint32_t num_bytes, |
451 const MojoHandle* handles, | 469 const MojoHandle* handles, |
452 uint32_t num_handles, | 470 uint32_t num_handles, |
453 MojoAllocMessageFlags flags, | 471 MojoAllocMessageFlags flags, |
454 MojoMessageHandle* message) { | 472 MojoMessageHandle* message) { |
455 if (!message) | 473 if (!message) |
456 return MOJO_RESULT_INVALID_ARGUMENT; | 474 return MOJO_RESULT_INVALID_ARGUMENT; |
457 | 475 |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 std::unique_ptr<NodeController> node_controller) { | 1187 std::unique_ptr<NodeController> node_controller) { |
1170 // It's OK to leak this reference. At this point we know the IO loop is still | 1188 // It's OK to leak this reference. At this point we know the IO loop is still |
1171 // running, and we know the NodeController will observe its eventual | 1189 // running, and we know the NodeController will observe its eventual |
1172 // destruction. This tells the NodeController to delete itself when that | 1190 // destruction. This tells the NodeController to delete itself when that |
1173 // happens. | 1191 // happens. |
1174 node_controller.release()->DestroyOnIOThreadShutdown(); | 1192 node_controller.release()->DestroyOnIOThreadShutdown(); |
1175 } | 1193 } |
1176 | 1194 |
1177 } // namespace edk | 1195 } // namespace edk |
1178 } // namespace mojo | 1196 } // namespace mojo |
OLD | NEW |