SlavePTY.cpp 837 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "SlavePTY.h"
  2. #include "MasterPTY.h"
  3. #include "DevPtsFS.h"
  4. SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
  5. : TTY(11, index)
  6. , m_master(master)
  7. , m_index(index)
  8. {
  9. VFS::the().register_character_device(*this);
  10. DevPtsFS::the().register_slave_pty(*this);
  11. set_size(80, 25);
  12. }
  13. SlavePTY::~SlavePTY()
  14. {
  15. DevPtsFS::the().unregister_slave_pty(*this);
  16. }
  17. String SlavePTY::tty_name() const
  18. {
  19. char buffer[32];
  20. ksprintf(buffer, "/dev/pts/%u", m_index);
  21. return buffer;
  22. }
  23. void SlavePTY::on_master_write(const byte* buffer, size_t size)
  24. {
  25. for (size_t i = 0; i < size; ++i)
  26. emit(buffer[i]);
  27. }
  28. void SlavePTY::on_tty_write(const byte* data, size_t size)
  29. {
  30. m_master.on_slave_write(data, size);
  31. }
  32. bool SlavePTY::can_write(Process&) const
  33. {
  34. return m_master.can_write_from_slave();
  35. }