1 // Copyright 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. 4 5 #include "nacl_io/stream/stream_event_emitter.h" 6 7 #include <poll.h> 8 #include <stdint.h> 9 #include <stdlib.h> 10 11 #include "nacl_io/fifo_interface.h" 12 #include "sdk_util/auto_lock.h" 13 14 namespace nacl_io { 15 StreamEventEmitter()16StreamEventEmitter::StreamEventEmitter() : stream_(NULL) { 17 } 18 AttachStream(StreamNode * stream)19void StreamEventEmitter::AttachStream(StreamNode* stream) { 20 AUTO_LOCK(GetLock()); 21 stream_ = stream; 22 } 23 DetachStream()24void StreamEventEmitter::DetachStream() { 25 AUTO_LOCK(GetLock()); 26 27 RaiseEvents_Locked(POLLHUP); 28 stream_ = NULL; 29 } 30 UpdateStatus_Locked()31void StreamEventEmitter::UpdateStatus_Locked() { 32 uint32_t status = 0; 33 if (!in_fifo()->IsEmpty()) 34 status |= POLLIN; 35 36 if (!out_fifo()->IsFull()) 37 status |= POLLOUT; 38 39 ClearEvents_Locked(~status); 40 RaiseEvents_Locked(status); 41 } 42 43 } // namespace nacl_io 44