Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* Copyright (c) 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. | |
|
Sam Clegg
2013/07/17 17:34:56
The convention for C++ headers seem to be to use s
| |
| 4 */ | |
| 5 #ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_H_ | |
| 6 #define LIBRARIES_NACL_IO_EVENT_EMITTER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "nacl_io/error.h" | |
| 12 | |
| 13 #include "sdk_util/ref_object.h" | |
| 14 #include "sdk_util/scoped_ref.h" | |
| 15 #include "sdk_util/simple_lock.h" | |
| 16 | |
| 17 class EventEmitter; | |
| 18 class EventInfo; | |
|
Sam Clegg
2013/07/17 17:34:56
Remove since its is declared just below?
binji
2013/07/19 20:47:17
ping
noelallen1
2013/07/19 21:35:43
Done.
| |
| 19 class EventListener; | |
| 20 | |
| 21 // A ref counted object for storing the state of a single signal request. | |
| 22 // Requests are unique to any FD/EventListener pair. | |
| 23 struct EventInfo : public RefObject { | |
|
binji
2013/07/17 22:23:20
might want to mention that this is not POD, becaus
noelallen1
2013/07/19 21:35:43
Done.
| |
| 24 volatile uint64_t data; | |
| 25 volatile uint32_t events; | |
|
Sam Clegg
2013/07/17 17:34:56
Is this a bitfield of KernnelEventTypes? Perhaps
noelallen1
2013/07/19 21:35:43
Done.
| |
| 26 volatile uint32_t filter; | |
|
Sam Clegg
2013/07/17 17:34:56
Didn't we come to the conclusion that volatile is
noelallen1
2013/07/19 21:35:43
Done.
| |
| 27 // We do not use a ScopedRef to prevent circular references. | |
| 28 EventEmitter* emitter; | |
| 29 EventListener* listener; | |
| 30 uint32_t id; | |
| 31 }; | |
| 32 | |
| 33 typedef ScopedRef<EventInfo> ScopedEventInfo; | |
| 34 | |
| 35 typedef std::map<int, ScopedEventInfo> EventInfoMap_t; | |
| 36 typedef std::set<ScopedEventInfo> EventInfoSet_t; | |
| 37 | |
| 38 // EventEmitter | |
| 39 // | |
| 40 // The EventEmitter class provides notification of events to EventListeners | |
| 41 // by registering EventInfo objects and signalling the EventListener when | |
|
binji
2013/07/17 22:23:20
sp: whenever their state
binji
2013/07/17 22:23:20
signalled or signaled are both correct, but signal
binji
2013/07/19 20:47:18
ping
noelallen1
2013/07/19 21:35:43
Done.
noelallen1
2013/07/19 21:35:43
Done.
noelallen1
2013/07/19 21:35:43
Done.
| |
| 42 // ever thier state is changed. | |
| 43 // | |
| 44 // See "Kernel Events" in event_listener.h for additional information. | |
| 45 class EventEmitter : public RefObject { | |
| 46 typedef std::set<ScopedEventInfo> EventInfoSet_t; | |
|
Sam Clegg
2013/07/17 17:34:56
Isn't this is duplicate of the typedef 10 lines ab
binji
2013/07/19 20:47:18
ping
noelallen1
2013/07/19 21:35:43
Done.
noelallen1
2013/07/19 21:35:43
Done.
| |
| 47 | |
| 48 protected: | |
| 49 // Called automatically prior to delete to inform the EventListeners that | |
| 50 // this EventEmitter is abandoning an associated EventInfo. | |
| 51 virtual void Destroy(); | |
| 52 | |
| 53 private: | |
| 54 // Regisiter or unregister an EventInfo. The lock of the EventListener | |
|
binji
2013/07/17 22:23:20
sp: Register
binji
2013/07/19 20:47:18
ping
noelallen1
2013/07/19 21:35:43
Done.
noelallen1
2013/07/19 21:35:43
Done.
| |
| 55 // associated with this EventInfo must be held prior to calling these | |
| 56 // functions. These functions are private to ensure they are called by the | |
| 57 // EventListener. | |
| 58 void RegisterEventInfo(const ScopedEventInfo& info); | |
| 59 void UnregisterEventInfo(const ScopedEventInfo& info); | |
| 60 | |
| 61 public: | |
| 62 // Returns the current state of the emitter. | |
|
Sam Clegg
2013/07/17 17:34:56
The state is a bitfield of KennelEventType? Perha
noelallen1
2013/07/19 21:35:43
I'm going to think about that as I do the select/p
| |
| 63 virtual uint32_t GetEventStatus() = 0; | |
| 64 | |
| 65 // REturns the type of the emitter (compatible with st_mode in stat) | |
|
binji
2013/07/17 22:23:20
nit: Returns
binji
2013/07/19 20:47:18
ping
noelallen1
2013/07/19 21:35:43
Done.
noelallen1
2013/07/19 21:35:43
Done.
| |
| 66 virtual int GetType() = 0; | |
| 67 | |
| 68 protected: | |
| 69 // Called by the thread causing the Event. | |
| 70 void RaiseEvent(uint32_t events); | |
| 71 | |
| 72 // Called after registering locally, but while lock is still held. | |
| 73 virtual void ChainRegister(const ScopedEventInfo& event); | |
|
binji
2013/07/17 22:23:20
I'd prefer a name that made it clear that it was c
noelallen1
2013/07/19 21:35:43
Done.
| |
| 74 | |
| 75 // Called before unregistering locally, but while lock is still held. | |
| 76 virtual void ChainUnregister(const ScopedEventInfo& event); | |
| 77 | |
| 78 private: | |
| 79 SimpleLock emitter_lock_; | |
| 80 EventInfoSet_t events_; | |
| 81 friend class EventListener; | |
| 82 }; | |
| 83 | |
| 84 typedef ScopedRef<EventEmitter> ScopedEventEmitter; | |
| 85 | |
| 86 #endif // LIBRARIES_NACL_IO_EVENT_EMITTER_H_ | |
| OLD | NEW |