tty.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <kernel/event/evtqueue.hpp>
  3. #include <stdint.h>
  4. #include <sys/types.h>
  5. #include <types/allocator.hpp>
  6. #include <types/buffer.hpp>
  7. #include <types/cplusplus.hpp>
  8. class tty : public types::non_copyable {
  9. public:
  10. static constexpr size_t BUFFER_SIZE = 4096;
  11. static constexpr size_t NAME_SIZE = 32;
  12. public:
  13. tty();
  14. virtual void putchar(char c) = 0;
  15. virtual void recvchar(char c) = 0;
  16. void print(const char* str);
  17. size_t read(char* buf, size_t buf_size, size_t n);
  18. void clear_read_buf(void);
  19. constexpr void set_pgrp(pid_t pgid)
  20. {
  21. fg_pgroup = pgid;
  22. }
  23. constexpr pid_t get_pgrp(void) const
  24. {
  25. return fg_pgroup;
  26. }
  27. char name[NAME_SIZE];
  28. bool echo = true;
  29. protected:
  30. types::buffer buf;
  31. kernel::cond_var m_cv;
  32. pid_t fg_pgroup;
  33. };
  34. class vga_tty : public virtual tty {
  35. public:
  36. vga_tty();
  37. virtual void putchar(char c) override;
  38. virtual void recvchar(char c) override;
  39. };
  40. class serial_tty : public virtual tty {
  41. public:
  42. serial_tty(int id);
  43. virtual void putchar(char c) override;
  44. virtual void recvchar(char c) override;
  45. public:
  46. uint16_t id;
  47. };
  48. inline tty* console;