| Index: native_client_sdk/src/libraries/nacl_io/event_emitter_pipe.h | 
| diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter_pipe.h b/native_client_sdk/src/libraries/nacl_io/event_emitter_pipe.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..0d780b8a01729af4e212f0b83a85176baaed53cf | 
| --- /dev/null | 
| +++ b/native_client_sdk/src/libraries/nacl_io/event_emitter_pipe.h | 
| @@ -0,0 +1,83 @@ | 
| +// 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_PIPE_H_ | 
| +#define LIBRARIES_NACL_IO_EVENT_EMITTER_PIPE_H_ | 
| + | 
| +#include <poll.h> | 
| +#include <stdint.h> | 
| +#include <stdlib.h> | 
| + | 
| +#include "nacl_io/event_emitter.h" | 
| +#include "nacl_io/fifo_char.h" | 
| + | 
| +#include "sdk_util/auto_lock.h" | 
| + | 
| +namespace nacl_io { | 
| + | 
| +class EventEmitterPipe; | 
| +typedef sdk_util::ScopedRef<EventEmitterPipe> ScopedEmitterPipe; | 
| + | 
| +class EventEmitterPipe : public EventEmitter { | 
| + public: | 
| +  EventEmitterPipe(size_t size) | 
| +      : fifo_(NULL), | 
| +        event_status_(0) { | 
| +    size = std::max<size_t>(1, size); | 
| +    fifo_ = new FIFOChar(size); | 
| + | 
| +    UpdateStatus_Locked(); | 
| +  } | 
| + | 
| +  ~EventEmitterPipe() { | 
| +    delete fifo_; | 
| +  } | 
| + | 
| +  virtual uint32_t GetEventStatus() { | 
| +    return event_status_; | 
| +  } | 
| + | 
| +  size_t Read_Locked(char* data, size_t len) { | 
| +    size_t out_len = fifo_->Read(data, len); | 
| + | 
| +    UpdateStatus_Locked(); | 
| +    return out_len; | 
| +  } | 
| + | 
| +  size_t Write_Locked(const char* data, size_t len) { | 
| +    size_t out_len = fifo_->Write(data, len); | 
| + | 
| +    UpdateStatus_Locked(); | 
| +    return out_len; | 
| +  } | 
| + | 
| + protected: | 
| +  void UpdateStatus_Locked() { | 
| +    uint32_t old_status = event_status_; | 
| + | 
| +    if (!fifo_->IsEmpty()) { | 
| +      event_status_ |= POLLIN; | 
| +    } else { | 
| +      event_status_ &= ~POLLIN; | 
| +    } | 
| + | 
| +    if (!fifo_->IsFull()) { | 
| +      event_status_ |= POLLOUT; | 
| +    } else { | 
| +      event_status_ &= ~POLLOUT; | 
| +    } | 
| + | 
| +    uint32_t raise_status = event_status_ & ~old_status; | 
| +    if (raise_status) | 
| +      RaiseEvents_Locked(raise_status); | 
| +  } | 
| + | 
| +  FIFOChar* fifo_; | 
| +  uint32_t event_status_; | 
| +}; | 
| + | 
| +}  // namespace nacl_io | 
| + | 
| +#endif  // LIBRARIES_NACL_IO_EVENT_EMITTER_PIPE_H_ | 
| + | 
|  |