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
3 // found in the LICENSE file.
5 #include "mojo/system/dispatcher.h"
7 #include "base/logging.h"
12 MojoResult Dispatcher::Close() {
13 base::AutoLock locker(lock_);
15 return MOJO_RESULT_INVALID_ARGUMENT;
18 CancelAllWaitersNoLock();
19 return CloseImplNoLock();
22 MojoResult Dispatcher::WriteMessage(const void* bytes,
24 const MojoHandle* handles,
26 MojoWriteMessageFlags flags) {
27 base::AutoLock locker(lock_);
29 return MOJO_RESULT_INVALID_ARGUMENT;
31 return WriteMessageImplNoLock(bytes, num_bytes, handles, num_handles, flags);
34 MojoResult Dispatcher::ReadMessage(void* bytes,
37 uint32_t* num_handles,
38 MojoReadMessageFlags flags) {
39 base::AutoLock locker(lock_);
41 return MOJO_RESULT_INVALID_ARGUMENT;
43 return ReadMessageImplNoLock(bytes, num_bytes, handles, num_handles, flags);
46 MojoResult Dispatcher::AddWaiter(Waiter* waiter,
48 MojoResult wake_result) {
49 DCHECK_GE(wake_result, 0);
51 base::AutoLock locker(lock_);
53 return MOJO_RESULT_INVALID_ARGUMENT;
55 return AddWaiterImplNoLock(waiter, flags, wake_result);
58 void Dispatcher::RemoveWaiter(Waiter* waiter) {
59 base::AutoLock locker(lock_);
62 RemoveWaiterImplNoLock(waiter);
65 Dispatcher::Dispatcher()
69 Dispatcher::~Dispatcher() {
70 // Make sure that |Close()| was called.
74 void Dispatcher::CancelAllWaitersNoLock() {
75 lock_.AssertAcquired();
77 // By default, waiting isn't supported. Only dispatchers that can be waited on
78 // will do something nontrivial.
81 MojoResult Dispatcher::CloseImplNoLock() {
82 lock_.AssertAcquired();
84 // This may not need to do anything. Dispatchers should override this to do
85 // any actual close-time cleanup necessary.
86 return MOJO_RESULT_OK;
89 MojoResult Dispatcher::WriteMessageImplNoLock(const void* bytes,
91 const MojoHandle* handles,
93 MojoWriteMessageFlags flags) {
94 lock_.AssertAcquired();
96 // By default, this isn't supported. Only dispatchers for message pipes (with
97 // whatever implementation, possibly a proxy) will do something nontrivial.
98 return MOJO_RESULT_INVALID_ARGUMENT;
101 MojoResult Dispatcher::ReadMessageImplNoLock(void* bytes,
104 uint32_t* num_handles,
105 MojoReadMessageFlags flags) {
106 lock_.AssertAcquired();
108 // By default, this isn't supported. Only dispatchers for message pipes (with
109 // whatever implementation, possibly a proxy) will do something nontrivial.
110 return MOJO_RESULT_INVALID_ARGUMENT;
113 MojoResult Dispatcher::AddWaiterImplNoLock(Waiter* waiter,
115 MojoResult wake_result) {
116 lock_.AssertAcquired();
118 // By default, waiting isn't supported. Only dispatchers that can be waited on
119 // will do something nontrivial.
120 return MOJO_RESULT_FAILED_PRECONDITION;
123 void Dispatcher::RemoveWaiterImplNoLock(Waiter* waiter) {
124 lock_.AssertAcquired();
126 // By default, waiting isn't supported. Only dispatchers that can be waited on
127 // will do something nontrivial.
130 } // namespace system