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 #ifndef LIBRARIES_NACL_IO_DEVFS_TTY_NODE_H_ 6 #define LIBRARIES_NACL_IO_DEVFS_TTY_NODE_H_ 7 8 #include <poll.h> 9 #include <pthread.h> 10 11 #include <deque> 12 13 #include <ppapi/c/pp_var.h> 14 15 #include "nacl_io/char_node.h" 16 #include "nacl_io/ioctl.h" 17 #include "nacl_io/ostermios.h" 18 19 namespace nacl_io { 20 21 class TtyNode : public CharNode { 22 public: 23 explicit TtyNode(Filesystem* filesystem); 24 25 virtual EventEmitter* GetEventEmitter(); 26 27 virtual Error VIoctl(int request, va_list args); 28 29 virtual Error Read(const HandleAttr& attr, 30 void* buf, 31 size_t count, 32 int* out_bytes); 33 34 virtual Error Write(const HandleAttr& attr, 35 const void* buf, 36 size_t count, 37 int* out_bytes); 38 39 virtual Error Tcgetattr(struct termios* termios_p); 40 virtual Error Tcsetattr(int optional_actions, 41 const struct termios* termios_p); 42 Isatty()43 virtual Error Isatty() { return 0; } 44 45 private: 46 ScopedEventEmitter emitter_; 47 48 Error ProcessInput(PP_Var var); 49 Error ProcessInput(const char* buffer, size_t num_bytes); 50 Error Echo(const char* string, int count); 51 void InitTermios(); 52 53 std::deque<char> input_buffer_; 54 struct termios termios_; 55 56 /// Current height of terminal in rows. Set via ioctl(2). 57 int rows_; 58 /// Current width of terminal in columns. Set via ioctl(2). 59 int cols_; 60 61 // Output handler for TTY. This is set via ioctl(2). 62 struct tioc_nacl_output output_handler_; 63 // Lock to protect output_handler_. This lock gets aquired whenever 64 // output_handler_ is used or set. 65 sdk_util::SimpleLock output_lock_; 66 }; 67 68 } // namespace nacl_io 69 70 #endif // LIBRARIES_NACL_IO_DEVFS_TTY_NODE_H_ 71