mirror of
https://github.com/autc04/Retro68.git
synced 2025-02-08 10:31:22 +00:00
33 lines
584 B
C++
33 lines
584 B
C++
#ifndef STREAM_H_
|
|
#define STREAM_H_
|
|
|
|
#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;
|
|
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() {}
|
|
long read(void *p, size_t n);
|
|
|
|
protected:
|
|
void notifyReceive(const uint8_t* p, size_t n);
|
|
};
|
|
|
|
#endif
|