OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/watcher_set.h" | 5 #include "mojo/edk/system/watcher_set.h" |
6 | 6 |
7 #include "mojo/edk/system/request_context.h" | 7 #include "mojo/edk/system/request_context.h" |
8 #include "mojo/public/c/system/types.h" | 8 #include "mojo/public/c/system/types.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace edk { | 11 namespace edk { |
12 | 12 |
13 WatcherSet::WatcherSet() {} | 13 WatcherSet::WatcherSet() {} |
14 | 14 |
15 WatcherSet::~WatcherSet() {} | 15 WatcherSet::~WatcherSet() {} |
16 | 16 |
17 void WatcherSet::NotifyForStateChange(const HandleSignalsState& state) { | 17 void WatcherSet::NotifyState(const HandleSignalsState& state) { |
18 for (const auto& entry : watchers_) | 18 for (const auto& entry : watchers_) |
19 entry.second->NotifyForStateChange(state); | 19 entry.second->NotifyState(state); |
20 } | 20 } |
21 | 21 |
22 void WatcherSet::NotifyClosed() { | 22 void WatcherSet::NotifyClosed() { |
23 for (const auto& entry : watchers_) | 23 for (const auto& entry : watchers_) |
24 entry.second->NotifyClosed(); | 24 entry.second->NotifyClosed(); |
25 } | 25 } |
26 | 26 |
27 MojoResult WatcherSet::Add(MojoHandleSignals signals, | 27 MojoResult WatcherSet::Add(MojoHandleSignals signals, |
28 const Watcher::WatchCallback& callback, | 28 const Watcher::WatchCallback& callback, |
29 uintptr_t context, | 29 uintptr_t context, |
30 const HandleSignalsState& current_state) { | 30 const HandleSignalsState& current_state) { |
31 auto it = watchers_.find(context); | 31 auto it = watchers_.find(context); |
32 if (it != watchers_.end()) | 32 if (it != watchers_.end()) |
33 return MOJO_RESULT_ALREADY_EXISTS; | 33 return MOJO_RESULT_ALREADY_EXISTS; |
34 | 34 |
35 if (!current_state.can_satisfy(signals)) | 35 if (!current_state.can_satisfy(signals)) |
36 return MOJO_RESULT_FAILED_PRECONDITION; | 36 return MOJO_RESULT_FAILED_PRECONDITION; |
37 | 37 |
38 scoped_refptr<Watcher> watcher(new Watcher(signals, callback)); | 38 scoped_refptr<Watcher> watcher(new Watcher(signals, callback)); |
39 watchers_.insert(std::make_pair(context, watcher)); | 39 watchers_.insert(std::make_pair(context, watcher)); |
40 | 40 |
41 watcher->NotifyForStateChange(current_state); | 41 return MOJO_RESULT_OK; |
| 42 } |
42 | 43 |
43 return MOJO_RESULT_OK; | 44 MojoResult WatcherSet::Arm(uintptr_t context, |
| 45 const HandleSignalsState& current_state) { |
| 46 auto it = watchers_.find(context); |
| 47 if (it == watchers_.end()) |
| 48 return MOJO_RESULT_INVALID_ARGUMENT; |
| 49 |
| 50 return it->second->Arm(current_state); |
44 } | 51 } |
45 | 52 |
46 MojoResult WatcherSet::Remove(uintptr_t context) { | 53 MojoResult WatcherSet::Remove(uintptr_t context) { |
47 auto it = watchers_.find(context); | 54 auto it = watchers_.find(context); |
48 if (it == watchers_.end()) | 55 if (it == watchers_.end()) |
49 return MOJO_RESULT_INVALID_ARGUMENT; | 56 return MOJO_RESULT_INVALID_ARGUMENT; |
50 | 57 |
51 RequestContext::current()->AddWatchCancelFinalizer(it->second); | 58 RequestContext::current()->AddWatchCancelFinalizer(it->second); |
52 watchers_.erase(it); | 59 watchers_.erase(it); |
53 return MOJO_RESULT_OK; | 60 return MOJO_RESULT_OK; |
54 } | 61 } |
55 | 62 |
56 } // namespace edk | 63 } // namespace edk |
57 } // namespace mojo | 64 } // namespace mojo |
OLD | NEW |