DataSourceStream.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * DataSourceStream.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <user_config.h>
14 #include "Stream.h"
15 #include "WString.h"
16 #include <unistd.h>
17 
22 enum StreamType {
30 };
38 class IDataSourceStream : public Stream
40 {
41 public:
45  virtual StreamType getStreamType() const
46  {
47  return eSST_Unknown;
48  }
49 
55  virtual bool isValid() const
56  {
57  return getStreamType() != eSST_Invalid;
58  }
59 
66  virtual uint16_t readMemoryBlock(char* data, int bufSize) = 0;
67 
72  int read() override;
73 
78  int peek() override;
79 
87  virtual int seekFrom(int offset, unsigned origin)
88  {
89  return -1;
90  }
91 
96  virtual bool seek(int len)
97  {
98  return seekFrom(len, SEEK_CUR) >= 0;
99  }
100 
104  virtual bool isFinished() = 0;
105 
110  virtual int available()
111  {
112  return -1;
113  }
114 
119  size_t write(uint8_t charToWrite) override
120  {
121  (void)charToWrite;
122  return 0;
123  }
124 
132  {
133  return available();
134  }
135 
136  /*
137  * @brief Flushes the stream
138  */
139  void flush() override
140  {
141  }
142 
147  virtual String id() const
148  {
149  return nullptr;
150  }
151 
157  virtual String getName() const
158  {
159  return nullptr;
160  }
161 
166  String readString(size_t maxLen = UINT16_MAX);
167 };
168 
Memory data stream.
Definition: DataSourceStream.h:24
Base class for data source stream.
Definition: DataSourceStream.h:39
int read() override
Read one character and moves the stream pointer.
int length()
Return the total length of the stream.
Definition: DataSourceStream.h:131
virtual bool isFinished()=0
Check if all data has been read.
virtual uint16_t readMemoryBlock(char *data, int bufSize)=0
Read a block of memory.
The String class.
Definition: WString.h:136
virtual bool isValid() const
Determine if the stream object contains valid data.
Definition: DataSourceStream.h:55
JSON object data stream.
Definition: DataSourceStream.h:27
void flush() override
Definition: DataSourceStream.h:139
virtual bool seek(int len)
Move read cursor.
Definition: DataSourceStream.h:96
virtual int seekFrom(int offset, unsigned origin)
Change position in stream.
Definition: DataSourceStream.h:87
Unknown data stream type.
Definition: DataSourceStream.h:29
#define SMING_DEPRECATED
Definition: sming_attr.h:30
StreamType
Data stream type.
Definition: DataSourceStream.h:22
virtual String getName() const
Returns name of the resource.
Definition: DataSourceStream.h:157
File data stream.
Definition: DataSourceStream.h:25
String readString()
Template data stream.
Definition: DataSourceStream.h:26
Stream content not valid.
Definition: DataSourceStream.h:23
int peek() override
Read a character without advancing the stream pointer.
virtual StreamType getStreamType() const
Get the stream type.
Definition: DataSourceStream.h:45
virtual String id() const
Returns unique id of the resource.
Definition: DataSourceStream.h:147
size_t write(uint8_t charToWrite) override
From Stream class: We don&#39;t write using this stream.
Definition: DataSourceStream.h:119
User defined data stream.
Definition: DataSourceStream.h:28
virtual int available()
Return the total length of the stream.
Definition: DataSourceStream.h:110
Base Stream class.
Definition: Stream.h:32