Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: mojo/edk/system/watcher_set.h

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef MOJO_EDK_SYSTEM_WATCHER_SET_H_ 5 #ifndef MOJO_EDK_SYSTEM_WATCHER_SET_H_
6 #define MOJO_EDK_SYSTEM_WATCHER_SET_H_ 6 #define MOJO_EDK_SYSTEM_WATCHER_SET_H_
7 7
8 #include <unordered_map> 8 #include <map>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "mojo/edk/system/handle_signals_state.h" 13 #include "mojo/edk/system/handle_signals_state.h"
14 #include "mojo/edk/system/watcher.h" 14 #include "mojo/edk/system/watcher.h"
15 #include "mojo/public/c/system/types.h" 15 #include "mojo/public/c/system/types.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace edk { 18 namespace edk {
19 19
20 // A WatcherSet maintains a set of Watchers attached to a single handle and 20 // A WatcherSet maintains a set of Watchers attached to a single handle and
21 // keyed on an arbitrary user context. 21 // keyed on an arbitrary user context.
22 class WatcherSet { 22 class WatcherSet {
23 public: 23 public:
24 WatcherSet(); 24 WatcherSet();
25 ~WatcherSet(); 25 ~WatcherSet();
26 26
27 // Notifies all Watchers of a state change. 27 // Notifies all Watchers of the handle's current signals state.
28 void NotifyForStateChange(const HandleSignalsState& state); 28 void NotifyState(const HandleSignalsState& state);
29 29
30 // Notifies all Watchers that their watched handle has been closed. 30 // Notifies all Watchers that their watched handle has been closed.
31 void NotifyClosed(); 31 void NotifyClosed();
32 32
33 // Adds a new watcher to watch for signals in |signals| to be satisfied or 33 // Adds a new watcher to watch for signals in |signals| to be satisfied or
34 // unsatisfiable. |current_state| is the current signals state of the 34 // unsatisfiable.
35 // handle being watched.
36 MojoResult Add(MojoHandleSignals signals, 35 MojoResult Add(MojoHandleSignals signals,
37 const Watcher::WatchCallback& callback, 36 const Watcher::WatchCallback& callback,
38 uintptr_t context, 37 uintptr_t context,
39 const HandleSignalsState& current_state); 38 const HandleSignalsState& current_state);
40 39
40 // Attempts to arm a watcher. May fail depending on |current_state|. See
41 // public |MojoArmWatcher()| documentation for error code details.
42 MojoResult Arm(uintptr_t context, const HandleSignalsState& current_state);
43
41 // Removes a watcher from the set. 44 // Removes a watcher from the set.
42 MojoResult Remove(uintptr_t context); 45 MojoResult Remove(uintptr_t context);
43 46
44 private: 47 private:
45 // A map of watchers keyed on context value. 48 // A map of watchers keyed on context value.
46 std::unordered_map<uintptr_t, scoped_refptr<Watcher>> watchers_; 49 std::map<uintptr_t, scoped_refptr<Watcher>> watchers_;
47 50
48 DISALLOW_COPY_AND_ASSIGN(WatcherSet); 51 DISALLOW_COPY_AND_ASSIGN(WatcherSet);
49 }; 52 };
50 53
51 } // namespace edk 54 } // namespace edk
52 } // namespace mojo 55 } // namespace mojo
53 56
54 #endif // MOJO_EDK_SYSTEM_WATCHER_SET_H_ 57 #endif // MOJO_EDK_SYSTEM_WATCHER_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698