- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / mount_node_tty.h
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 <poll.h>
9 #include <pthread.h>
10
11 #include <deque>
12
13 #include "nacl_io/ioctl.h"
14 #include "nacl_io/mount_node_char.h"
15 #include "nacl_io/ostermios.h"
16
17
18 namespace nacl_io {
19
20 class MountNodeTty : public MountNodeCharDevice {
21  public:
22   explicit MountNodeTty(Mount* mount);
23
24   virtual EventEmitter* GetEventEmitter();
25
26   virtual Error VIoctl(int request, va_list args);
27
28   virtual Error Read(const HandleAttr& attr,
29                      void* buf,
30                      size_t count,
31                      int* out_bytes);
32
33   virtual Error Write(const HandleAttr& attr,
34                       const void* buf,
35                       size_t count,
36                       int* out_bytes);
37
38   virtual Error Tcgetattr(struct termios* termios_p);
39   virtual Error Tcsetattr(int optional_actions,
40                           const struct termios *termios_p);
41
42  private:
43   ScopedEventEmitter emitter_;
44
45   Error ProcessInput(struct tioc_nacl_input_string* message);
46   Error Echo(const char* string, int count);
47   void InitTermios();
48
49   std::deque<char> input_buffer_;
50   struct termios termios_;
51
52   /// Current height of terminal in rows.  Set via ioctl(2).
53   int rows_;
54   /// Current width of terminal in columns.  Set via ioctl(2).
55   int cols_;
56
57   // Output handler for TTY.  This is set via ioctl(2).
58   struct tioc_nacl_output output_handler_;
59   // Lock to protect output_handler_.  This lock gets aquired whenever
60   // output_handler_ is used or set.
61   sdk_util::SimpleLock output_lock_;
62 };
63
64 }
65
66 #endif