Retro68/LaunchAPPL/Common/Stream.h

33 lines
584 B
C
Raw Normal View History

#ifndef STREAM_H_
#define STREAM_H_
2018-04-20 22:03:29 +00:00
#include <stdint.h>
#include <stddef.h>
#include <vector>
class StreamListener
{
public:
virtual size_t onReceive(const uint8_t* p, size_t n) = 0;
};
class Stream
{
StreamListener *listener_ = nullptr;
2018-04-20 22:03:29 +00:00
std::vector<uint8_t> buffer_;
public:
Stream();
virtual ~Stream();
void setListener(StreamListener *l) { listener_ = l; }
virtual void write(const void* p, size_t n) = 0;
virtual void flushWrite() {}
2018-04-20 22:03:29 +00:00
long read(void *p, size_t n);
protected:
void notifyReceive(const uint8_t* p, size_t n);
2018-04-20 22:03:29 +00:00
};
#endif