2018-04-22 09:23:08 +00:00
|
|
|
#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
|
|
|
|
{
|
2018-04-22 09:23:08 +00:00
|
|
|
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;
|
2018-04-22 09:23:08 +00:00
|
|
|
virtual void flushWrite() {}
|
2018-04-20 22:03:29 +00:00
|
|
|
long read(void *p, size_t n);
|
|
|
|
|
|
|
|
protected:
|
2018-04-22 09:23:08 +00:00
|
|
|
void notifyReceive(const uint8_t* p, size_t n);
|
2018-04-20 22:03:29 +00:00
|
|
|
};
|
2018-04-22 09:23:08 +00:00
|
|
|
|
|
|
|
#endif
|