GUIEventDevice.cpp 935 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "GUIEventDevice.h"
  2. #include <Kernel/Process.h>
  3. #include <AK/Lock.h>
  4. #include <LibC/errno_numbers.h>
  5. //#define GUIEVENTDEVICE_DEBUG
  6. GUIEventDevice::GUIEventDevice()
  7. : CharacterDevice(66, 1)
  8. {
  9. }
  10. GUIEventDevice::~GUIEventDevice()
  11. {
  12. }
  13. bool GUIEventDevice::can_read(Process& process) const
  14. {
  15. return !process.gui_events().is_empty();
  16. }
  17. ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size)
  18. {
  19. #ifdef GUIEVENTDEVICE_DEBUG
  20. dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_Event)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_Event));
  21. #endif
  22. if (process.gui_events().is_empty())
  23. return 0;
  24. LOCKER(process.gui_events_lock());
  25. ASSERT(size == sizeof(GUI_Event));
  26. *reinterpret_cast<GUI_Event*>(buffer) = process.gui_events().take_first();
  27. return size;
  28. }
  29. ssize_t GUIEventDevice::write(Process&, const byte*, size_t)
  30. {
  31. return -EINVAL;
  32. }