| 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..fe8e882d4666405eb2e6aced3a6429e196a031ab
|
| --- /dev/null
|
| +++ b/native_client_sdk/src/libraries/nacl_io/event_emitter.h
|
| @@ -0,0 +1,93 @@
|
| +/* 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.
|
| + */
|
| +#ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_H_
|
| +#define LIBRARIES_NACL_IO_EVENT_EMITTER_H_
|
| +
|
| +#include <stdint.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;
|
| +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 {
|
| + uint64_t user_data;
|
| + uint32_t events;
|
| + uint32_t filter;
|
| + // We do not use a ScopedRef to prevent circular references.
|
| + EventEmitter* emitter;
|
| + EventListener* listener;
|
| + uint32_t id;
|
| +};
|
| +
|
| +typedef ScopedRef<EventInfo> ScopedEventInfo;
|
| +
|
| +// Provide comparison for std::map and std::set
|
| +bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b);
|
| +
|
| +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
|
| +// 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;
|
| +
|
| +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
|
| + // 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.
|
| + virtual uint32_t GetEventStatus() = 0;
|
| +
|
| + // REturns the type of the emitter (compatible with st_mode in stat)
|
| + virtual int GetType() = 0;
|
| +
|
| + protected:
|
| + // Called by the thread causing the Event.
|
| + void RaiseEvent(uint32_t events);
|
| +
|
| + // Provided to allow one EventEmitter to register the same EventInfo with
|
| + // a child EventEmitter so that they can both signal the EventListener.
|
| + // Called after registering locally, but while lock is still held.
|
| + virtual void ChainRegister(const ScopedEventInfo& event);
|
| +
|
| + // 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_
|
|
|