Home | History | Annotate | Download | only in nacl_io
      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.
      4 
      5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_
      6 #define LIBRARIES_NACL_IO_MOUNT_NODE_TTY_H_
      7 
      8 #include <pthread.h>
      9 
     10 #include <deque>
     11 
     12 #include "nacl_io/ioctl.h"
     13 #include "nacl_io/mount_node_char.h"
     14 #include "nacl_io/ostermios.h"
     15 
     16 
     17 namespace nacl_io {
     18 
     19 class MountNodeTty : public MountNodeCharDevice {
     20  public:
     21   explicit MountNodeTty(Mount* mount);
     22   ~MountNodeTty();
     23 
     24   virtual Error Ioctl(int request,
     25                       char* arg);
     26 
     27   virtual Error Read(size_t offs,
     28                      void* buf,
     29                      size_t count,
     30                      int* out_bytes);
     31 
     32   virtual Error Write(size_t offs,
     33                       const void* buf,
     34                       size_t count,
     35                       int* out_bytes);
     36 
     37   virtual Error Tcgetattr(struct termios* termios_p);
     38   virtual Error Tcsetattr(int optional_actions,
     39                           const struct termios *termios_p);
     40 
     41  private:
     42   virtual Error Write(size_t offs,
     43                       const void* buf,
     44                       size_t count,
     45                       int* out_bytes,
     46                       bool locked);
     47   Error ProcessInput(struct tioc_nacl_input_string* message);
     48   Error Echo(const char* string, int count);
     49   void InitTermios();
     50 
     51   std::deque<char> input_buffer_;
     52   bool is_readable_;
     53   pthread_cond_t is_readable_cond_;
     54   std::string prefix_;
     55   struct termios termios_;
     56 };
     57 
     58 }
     59 
     60 #endif
     61