ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / event_emitter.cc
blob2e620bc7f4ae02eec777126c18105907c388de0a
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.
5 #include <assert.h>
6 #include <poll.h>
8 #include "nacl_io/event_emitter.h"
9 #include "nacl_io/event_listener.h"
10 #include "nacl_io/fifo_interface.h"
12 #include "sdk_util/auto_lock.h"
14 namespace nacl_io {
16 bool operator<(const ScopedEventEmitter& src_a,
17 const ScopedEventEmitter& src_b) {
18 return src_a.get() < src_b.get();
21 EventEmitter::EventEmitter() : event_status_(0) {
24 void EventEmitter::RegisterListener(EventListener* listener, uint32_t events) {
25 AUTO_LOCK(emitter_lock_);
26 RegisterListener_Locked(listener, events);
29 void EventEmitter::UnregisterListener(EventListener* listener) {
30 AUTO_LOCK(emitter_lock_);
31 UnregisterListener_Locked(listener);
34 void EventEmitter::RegisterListener_Locked(EventListener* listener,
35 uint32_t events) {
36 assert(listeners_.count(listener) == 0);
37 listeners_[listener] = events;
40 void EventEmitter::UnregisterListener_Locked(EventListener* listener) {
41 assert(listeners_.count(listener) == 1);
42 listeners_.erase(listener);
45 void EventEmitter::ClearEvents_Locked(uint32_t event_bits) {
46 event_status_ &= ~event_bits;
49 void EventEmitter::RaiseEvents_Locked(uint32_t event_bits) {
50 event_status_ |= event_bits;
52 EventListenerMap_t::iterator it;
53 for (it = listeners_.begin(); it != listeners_.end(); it++) {
54 uint32_t bits = it->second & event_bits;
55 if (0 != bits)
56 it->first->ReceiveEvents(this, bits);
60 } // namespace nacl_io