RbootOutputStream.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  * RbootOutputStream.h
8  *
9  * Created on: 2015/09/03.
10  * Author: Richard A Burton & Anakod
11  *
12  * Modified: 2017 - Slavey Karadzhov <slav@attachix.com>
13  *
14  ****/
15 
16 #pragma once
17 
19 #include <rboot-api.h>
20 
22 {
23 public:
28  RbootOutputStream(uint32_t startAddress, size_t maxLength = 0) : startAddress(startAddress), maxLength(maxLength)
29  {
30  }
31 
33  {
34  close();
35  }
36 
37  size_t write(const uint8_t* data, size_t size) override;
38 
39  StreamType getStreamType() const override
40  {
41  return eSST_File;
42  }
43 
44  uint16_t readMemoryBlock(char* data, int bufSize) override
45  {
46  return 0;
47  }
48 
49  bool seek(int len) override
50  {
51  return false;
52  }
53 
54  int available() override
55  {
56  return written;
57  }
58 
59  bool isFinished() override
60  {
61  return true;
62  }
63 
64  virtual bool close();
65 
66  size_t getStartAddress() const
67  {
68  return startAddress;
69  }
70 
71  size_t getMaxLength() const
72  {
73  return maxLength;
74  }
75 
76 protected:
77  bool initialized = false;
79  size_t written = 0; // << the number of written bytes
80  uint32_t startAddress = 0; // << the start address on the storage
81  size_t maxLength = 0; // << maximum allowed length
82 
83 protected:
84  virtual bool init();
85 };
86 
uint32_t startAddress
Definition: RbootOutputStream.h:80
size_t getStartAddress() const
Definition: RbootOutputStream.h:66
size_t write(const uint8_t *data, size_t size) override
Write chars to stream.
size_t maxLength
Definition: RbootOutputStream.h:81
int available() override
Return the total length of the stream.
Definition: RbootOutputStream.h:54
bool initialized
Definition: RbootOutputStream.h:77
#define SMING_DEPRECATED
Definition: sming_attr.h:30
rboot_write_status rBootWriteStatus
Definition: RbootOutputStream.h:78
StreamType
Data stream type.
Definition: DataSourceStream.h:22
File data stream.
Definition: DataSourceStream.h:25
Structure defining flash write status.
Definition: rboot-api.h:26
RbootOutputStream(uint32_t startAddress, size_t maxLength=0)
Definition: RbootOutputStream.h:28
Definition: RbootOutputStream.h:21
size_t getMaxLength() const
Definition: RbootOutputStream.h:71
size_t written
Definition: RbootOutputStream.h:79
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
Definition: RbootOutputStream.h:44
bool isFinished() override
Check if all data has been read.
Definition: RbootOutputStream.h:59
virtual ~RbootOutputStream()
Definition: RbootOutputStream.h:32
virtual bool init()
StreamType getStreamType() const override
Get the stream type.
Definition: RbootOutputStream.h:39
Base class for read/write stream.
Definition: ReadWriteStream.h:22
bool seek(int len) override
Move read cursor.
Definition: RbootOutputStream.h:49
virtual bool close()