COSA
An Object-Oriented Platform for Arduino Programming
IOEvent.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_IOEVENT_HH
22 #define COSA_IOEVENT_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/Event.hh"
26 #include "Cosa/IOStream.hh"
27 
35 template <typename DEVICE>
36 class IOEvent : public DEVICE {
37 public:
41  IOEvent(Event::Handler* handler) : DEVICE(), m_handler(handler) {}
42 
49  virtual int putchar(char c)
50  {
51  int res = DEVICE::putchar(c);
52  if (UNLIKELY(c == '\n' || DEVICE::room() == 0))
54  return (res);
55  }
56 
62  virtual int getchar()
63  {
64  int res = DEVICE::getchar();
65  if (UNLIKELY(res == IOStream::EOF))
67  return (res);
68  }
69 
70 protected:
72 };
73 
74 #endif
Event::Handler * m_handler
Definition: IOEvent.hh:71
virtual int putchar(char c)
Definition: IOEvent.hh:49
IOEvent(Event::Handler *handler)
Definition: IOEvent.hh:41
static const int EOF
Definition: IOStream.hh:33
virtual int getchar()
Definition: IOEvent.hh:62
#define UNLIKELY(x)
Definition: Types.h:153
static bool push(uint8_t type, Handler *target, uint16_t value=0)
Definition: Event.hh:180