UpgradeOutputStream.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  * UpgradeOutputStream.h
8  *
9  *
10 */
11 
12 #pragma once
13 
14 #include <Ota/Upgrader.h>
15 #include <Storage/Partition.h>
17 
18 namespace Ota
19 {
23 class UpgradeOutputStream : public ReadWriteStream
24 {
25 public:
27 
33  : partition(partition), maxLength(std::min(storage_size_t(maxLength ?: 0x1000000), partition.size()))
34  {
35  }
36 
37  virtual ~UpgradeOutputStream()
38  {
39  close();
40  }
41 
42  size_t write(const uint8_t* data, size_t size) override;
43 
44  StreamType getStreamType() const override
45  {
46  return eSST_File;
47  }
48 
49  uint16_t readMemoryBlock(char* data, int bufSize) override
50  {
51  return 0;
52  }
53 
54  bool seek(int len) override
55  {
56  return false;
57  }
58 
59  int available() override
60  {
61  return written;
62  }
63 
64  bool isFinished() override
65  {
66  return true;
67  }
68 
69  virtual bool close();
70 
71  size_t getStartAddress() const
72  {
73  return partition.address();
74  }
75 
76  size_t getMaxLength() const
77  {
78  return maxLength;
79  }
80 
81 protected:
84  bool initialized{false};
85  size_t written{0}; // << the number of written bytes
86  size_t maxLength{0}; // << maximum allowed length
87 
88 protected:
89  virtual bool init();
90 };
91 
92 } // namespace Ota
UpgradeOutputStream(Partition partition, size_t maxLength=0)
Construct a stream for the given partition.
Definition: UpgradeOutputStream.h:50
Represents a flash partition.
Definition: Partition.h:85
storage_size_t address() const
Obtain partition starting address.
Definition: Partition.h:335
size_t maxLength
Definition: UpgradeOutputStream.h:104
size_t write(const uint8_t *data, size_t size) override
Write chars to stream.
Storage::Partition Partition
Definition: UpgradeOutputStream.h:44
bool initialized
Definition: UpgradeOutputStream.h:102
OtaUpgrader ota
Definition: UpgradeOutputStream.h:100
size_t written
Definition: UpgradeOutputStream.h:103
ESP32 OTA Upgrader implementation.
Definition: IdfUpgrader.h:32
StreamType
Data stream type.
Definition: DataSourceStream.h:25
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
Definition: UpgradeOutputStream.h:67
Definition: HttpUpgrader.h:21
int available() override
Return the total length of the stream.
Definition: UpgradeOutputStream.h:77
bool seek(int len) override
Move read cursor.
Definition: UpgradeOutputStream.h:72
size_t getMaxLength() const
Definition: UpgradeOutputStream.h:94
Partition partition
Definition: UpgradeOutputStream.h:101
StreamType getStreamType() const override
Get the stream type.
Definition: UpgradeOutputStream.h:62
size_t getStartAddress() const
Definition: UpgradeOutputStream.h:89
bool isFinished() override
Check if all data has been read.
Definition: UpgradeOutputStream.h:82
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19
virtual ~UpgradeOutputStream()
Definition: UpgradeOutputStream.h:55
@ eSST_File
< Memory stream where data can be safely written to.
Definition: DataSourceStream.h:30
Base class for read/write stream.
Definition: ReadWriteStream.h:19