Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io/event_emitter.h |
| diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter.h b/native_client_sdk/src/libraries/nacl_io/event_emitter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..78b963f4f42fda8421a61fe6d9003e5a7a0f48a1 |
| --- /dev/null |
| +++ b/native_client_sdk/src/libraries/nacl_io/event_emitter.h |
| @@ -0,0 +1,86 @@ |
| +/* Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
|
Sam Clegg
2013/07/17 17:34:56
The convention for C++ headers seem to be to use s
|
| + */ |
| +#ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_H_ |
| +#define LIBRARIES_NACL_IO_EVENT_EMITTER_H_ |
| + |
| +#include <map> |
| +#include <set> |
| + |
| +#include "nacl_io/error.h" |
| + |
| +#include "sdk_util/ref_object.h" |
| +#include "sdk_util/scoped_ref.h" |
| +#include "sdk_util/simple_lock.h" |
| + |
| +class EventEmitter; |
| +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.
|
| +class EventListener; |
| + |
| +// A ref counted object for storing the state of a single signal request. |
| +// Requests are unique to any FD/EventListener pair. |
| +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.
|
| + volatile uint64_t data; |
| + 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.
|
| + 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.
|
| + // We do not use a ScopedRef to prevent circular references. |
| + EventEmitter* emitter; |
| + EventListener* listener; |
| + uint32_t id; |
| +}; |
| + |
| +typedef ScopedRef<EventInfo> ScopedEventInfo; |
| + |
| +typedef std::map<int, ScopedEventInfo> EventInfoMap_t; |
| +typedef std::set<ScopedEventInfo> EventInfoSet_t; |
| + |
| +// EventEmitter |
| +// |
| +// The EventEmitter class provides notification of events to EventListeners |
| +// 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.
|
| +// ever thier state is changed. |
| +// |
| +// See "Kernel Events" in event_listener.h for additional information. |
| +class EventEmitter : public RefObject { |
| + 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.
|
| + |
| +protected: |
| + // Called automatically prior to delete to inform the EventListeners that |
| + // this EventEmitter is abandoning an associated EventInfo. |
| + virtual void Destroy(); |
| + |
| + private: |
| + // 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.
|
| + // associated with this EventInfo must be held prior to calling these |
| + // functions. These functions are private to ensure they are called by the |
| + // EventListener. |
| + void RegisterEventInfo(const ScopedEventInfo& info); |
| + void UnregisterEventInfo(const ScopedEventInfo& info); |
| + |
| + public: |
| + // 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
|
| + virtual uint32_t GetEventStatus() = 0; |
| + |
| + // 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.
|
| + virtual int GetType() = 0; |
| + |
| + protected: |
| + // Called by the thread causing the Event. |
| + void RaiseEvent(uint32_t events); |
| + |
| + // Called after registering locally, but while lock is still held. |
| + 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.
|
| + |
| + // Called before unregistering locally, but while lock is still held. |
| + virtual void ChainUnregister(const ScopedEventInfo& event); |
| + |
| +private: |
| + SimpleLock emitter_lock_; |
| + EventInfoSet_t events_; |
| + friend class EventListener; |
| +}; |
| + |
| +typedef ScopedRef<EventEmitter> ScopedEventEmitter; |
| + |
| +#endif // LIBRARIES_NACL_IO_EVENT_EMITTER_H_ |