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/system/core_impl.h" | 5 #include "mojo/system/core_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "mojo/system/data_pipe_producer_dispatcher.h" |
11 #include "mojo/system/dispatcher.h" | 12 #include "mojo/system/dispatcher.h" |
12 #include "mojo/system/limits.h" | 13 #include "mojo/system/limits.h" |
13 #include "mojo/system/memory.h" | 14 #include "mojo/system/memory.h" |
14 #include "mojo/system/message_pipe.h" | 15 #include "mojo/system/message_pipe.h" |
15 #include "mojo/system/message_pipe_dispatcher.h" | 16 #include "mojo/system/message_pipe_dispatcher.h" |
16 #include "mojo/system/waiter.h" | 17 #include "mojo/system/waiter.h" |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 namespace system { | 20 namespace system { |
20 | 21 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // TODO(vtl): What should we do if we hit the maximum handle table size | 343 // TODO(vtl): What should we do if we hit the maximum handle table size |
343 // here? Currently, we'll just fill in those handles with | 344 // here? Currently, we'll just fill in those handles with |
344 // |MOJO_HANDLE_INVALID| (and return success anyway). | 345 // |MOJO_HANDLE_INVALID| (and return success anyway). |
345 handles[i] = AddDispatcherNoLock(dispatchers[i]); | 346 handles[i] = AddDispatcherNoLock(dispatchers[i]); |
346 } | 347 } |
347 } | 348 } |
348 | 349 |
349 return rv; | 350 return rv; |
350 } | 351 } |
351 | 352 |
352 MojoResult CoreImpl::CreateDataPipe( | 353 MojoResult CoreImpl::CreateDataPipe(const MojoCreateDataPipeOptions* options, |
353 const struct MojoCreateDataPipeOptions* options, | 354 MojoHandle* data_pipe_producer_handle, |
354 MojoHandle* producer_handle, | 355 MojoHandle* data_pipe_consumer_handle) { |
355 MojoHandle* consumer_handle) { | 356 if (options && !VerifyUserPointer<void>(options, sizeof(*options))) |
356 // TODO(vtl) | 357 return MOJO_RESULT_INVALID_ARGUMENT; |
| 358 if (!VerifyUserPointer<MojoHandle>(data_pipe_producer_handle, 1)) |
| 359 return MOJO_RESULT_INVALID_ARGUMENT; |
| 360 if (!VerifyUserPointer<MojoHandle>(data_pipe_consumer_handle, 1)) |
| 361 return MOJO_RESULT_INVALID_ARGUMENT; |
| 362 |
| 363 /* TODO(vtl): The rest of the code will look something like this: |
| 364 scoped_refptr<LocalDataPipe> data_pipe(new LocalDataPipe()); |
| 365 MojoResult result = data_pipe->Init(options); |
| 366 if (result != MOJO_RESULT_OK) |
| 367 return result; |
| 368 |
| 369 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher( |
| 370 new DataPipeProducerDispatcher()); |
| 371 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher( |
| 372 new DataPipeConsumerDispatcher()); |
| 373 |
| 374 MojoHandle producer_handle, consumer_handle; |
| 375 { |
| 376 base::AutoLock locker(handle_table_lock_); |
| 377 |
| 378 producer_handle = AddDispatcherNoLock(producer_dispatcher); |
| 379 if (producer_handle == MOJO_HANDLE_INVALID) |
| 380 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 381 |
| 382 consumer_handle = AddDispatcherNoLock(consumer_dispatcher); |
| 383 if (consumer_handle == MOJO_HANDLE_INVALID) { |
| 384 handle_table_.erase(producer_handle); |
| 385 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 386 } |
| 387 } |
| 388 |
| 389 producer_dispatcher->Init(data_pipe); |
| 390 consumer_dispatcher->Init(data_pipe); |
| 391 |
| 392 *data_pipe_producer_handle = producer_handle; |
| 393 *data_pipe_consumer_handle = consumer_handle; |
| 394 return MOJO_RESULT_OK; |
| 395 */ |
357 NOTIMPLEMENTED(); | 396 NOTIMPLEMENTED(); |
358 return MOJO_RESULT_UNIMPLEMENTED; | 397 return MOJO_RESULT_UNIMPLEMENTED; |
359 } | 398 } |
360 | 399 |
361 MojoResult CoreImpl::WriteData(MojoHandle data_pipe_producer_handle, | 400 MojoResult CoreImpl::WriteData(MojoHandle data_pipe_producer_handle, |
362 const void* elements, | 401 const void* elements, |
363 uint32_t* num_elements, | 402 uint32_t* num_elements, |
364 MojoWriteDataFlags flags) { | 403 MojoWriteDataFlags flags) { |
365 scoped_refptr<Dispatcher> dispatcher( | 404 scoped_refptr<Dispatcher> dispatcher( |
366 GetDispatcher(data_pipe_producer_handle)); | 405 GetDispatcher(data_pipe_producer_handle)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 return MOJO_RESULT_INVALID_ARGUMENT; | 463 return MOJO_RESULT_INVALID_ARGUMENT; |
425 | 464 |
426 return dispatcher->EndReadData(num_elements_read); | 465 return dispatcher->EndReadData(num_elements_read); |
427 } | 466 } |
428 | 467 |
429 CoreImpl::CoreImpl() | 468 CoreImpl::CoreImpl() |
430 : next_handle_(MOJO_HANDLE_INVALID + 1) { | 469 : next_handle_(MOJO_HANDLE_INVALID + 1) { |
431 } | 470 } |
432 | 471 |
433 CoreImpl::~CoreImpl() { | 472 CoreImpl::~CoreImpl() { |
434 // This should usually not be reached (the singleton lives forever), except | 473 // This should usually not be reached (the singleton lives forever), except in |
435 // in tests. | 474 // tests. |
436 } | 475 } |
437 | 476 |
438 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) { | 477 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) { |
439 if (handle == MOJO_HANDLE_INVALID) | 478 if (handle == MOJO_HANDLE_INVALID) |
440 return NULL; | 479 return NULL; |
441 | 480 |
442 base::AutoLock locker(handle_table_lock_); | 481 base::AutoLock locker(handle_table_lock_); |
443 HandleTableMap::iterator it = handle_table_.find(handle); | 482 HandleTableMap::iterator it = handle_table_.find(handle); |
444 if (it == handle_table_.end()) | 483 if (it == handle_table_.end()) |
445 return NULL; | 484 return NULL; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be | 556 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be |
518 // destroyed, but this would still be required if the waiter were in TLS.) | 557 // destroyed, but this would still be required if the waiter were in TLS.) |
519 for (i = 0; i < num_added; i++) | 558 for (i = 0; i < num_added; i++) |
520 dispatchers[i]->RemoveWaiter(&waiter); | 559 dispatchers[i]->RemoveWaiter(&waiter); |
521 | 560 |
522 return rv; | 561 return rv; |
523 } | 562 } |
524 | 563 |
525 } // namespace system | 564 } // namespace system |
526 } // namespace mojo | 565 } // namespace mojo |
OLD | NEW |