| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_ | 5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_ | 
| 6 #define LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_ | 6 #define LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_ | 
| 7 | 7 | 
| 8 #include <poll.h> | 8 #include <poll.h> | 
| 9 #include <pthread.h> | 9 #include <pthread.h> | 
| 10 | 10 | 
| 11 #include <deque> | 11 #include <deque> | 
| 12 | 12 | 
| 13 #include "nacl_io/ioctl.h" | 13 #include "nacl_io/ioctl.h" | 
| 14 #include "nacl_io/mount_node_char.h" | 14 #include "nacl_io/mount_node_char.h" | 
| 15 #include "nacl_io/ostermios.h" | 15 #include "nacl_io/ostermios.h" | 
| 16 | 16 | 
| 17 | 17 | 
| 18 namespace nacl_io { | 18 namespace nacl_io { | 
| 19 | 19 | 
| 20 class MountNodeTty : public MountNodeCharDevice { | 20 class MountNodeTty : public MountNodeCharDevice { | 
| 21  public: | 21  public: | 
| 22   explicit MountNodeTty(Mount* mount); | 22   explicit MountNodeTty(Mount* mount); | 
| 23   ~MountNodeTty(); | 23 | 
|  | 24   virtual EventEmitter* GetEventEmitter(); | 
| 24 | 25 | 
| 25   virtual Error Ioctl(int request, | 26   virtual Error Ioctl(int request, | 
| 26                       char* arg); | 27                       char* arg); | 
| 27 | 28 | 
| 28   virtual Error Read(size_t offs, | 29   virtual Error Read(size_t offs, | 
| 29                      void* buf, | 30                      void* buf, | 
| 30                      size_t count, | 31                      size_t count, | 
| 31                      int* out_bytes); | 32                      int* out_bytes); | 
| 32 | 33 | 
| 33   virtual Error Write(size_t offs, | 34   virtual Error Write(size_t offs, | 
| 34                       const void* buf, | 35                       const void* buf, | 
| 35                       size_t count, | 36                       size_t count, | 
| 36                       int* out_bytes); | 37                       int* out_bytes); | 
| 37 | 38 | 
| 38   virtual Error Tcgetattr(struct termios* termios_p); | 39   virtual Error Tcgetattr(struct termios* termios_p); | 
| 39   virtual Error Tcsetattr(int optional_actions, | 40   virtual Error Tcsetattr(int optional_actions, | 
| 40                           const struct termios *termios_p); | 41                           const struct termios *termios_p); | 
| 41 | 42 | 
| 42   virtual uint32_t GetEventStatus() { | 43  private: | 
| 43     uint32_t status = POLLOUT; | 44   ScopedEventEmitter emitter_; | 
| 44     if (is_readable_) |  | 
| 45       status |= POLLIN; |  | 
| 46     return status; |  | 
| 47   } |  | 
| 48 | 45 | 
| 49  private: |  | 
| 50   Error ProcessInput(struct tioc_nacl_input_string* message); | 46   Error ProcessInput(struct tioc_nacl_input_string* message); | 
| 51   Error Echo(const char* string, int count); | 47   Error Echo(const char* string, int count); | 
| 52   void InitTermios(); | 48   void InitTermios(); | 
| 53 | 49 | 
| 54   std::deque<char> input_buffer_; | 50   std::deque<char> input_buffer_; | 
| 55   bool is_readable_; |  | 
| 56   pthread_cond_t is_readable_cond_; |  | 
| 57   struct termios termios_; | 51   struct termios termios_; | 
| 58 | 52 | 
| 59   /// Current height of terminal in rows.  Set via ioctl(2). | 53   /// Current height of terminal in rows.  Set via ioctl(2). | 
| 60   int rows_; | 54   int rows_; | 
| 61   /// Current width of terminal in columns.  Set via ioctl(2). | 55   /// Current width of terminal in columns.  Set via ioctl(2). | 
| 62   int cols_; | 56   int cols_; | 
| 63 | 57 | 
| 64   // Output handler for TTY.  This is set via ioctl(2). | 58   // Output handler for TTY.  This is set via ioctl(2). | 
| 65   struct tioc_nacl_output output_handler_; | 59   struct tioc_nacl_output output_handler_; | 
| 66   // Lock to protect output_handler_.  This lock gets aquired whenever | 60   // Lock to protect output_handler_.  This lock gets aquired whenever | 
| 67   // output_handler_ is used or set. | 61   // output_handler_ is used or set. | 
| 68   sdk_util::SimpleLock output_lock_; | 62   sdk_util::SimpleLock output_lock_; | 
| 69 }; | 63 }; | 
| 70 | 64 | 
| 71 } | 65 } | 
| 72 | 66 | 
| 73 #endif | 67 #endif | 
| OLD | NEW | 
|---|