PartitionTable.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  * PartitionTable.h
8  *
9  ****/
10 #pragma once
11 
12 #include "Partition.h"
13 #include "Iterator.h"
14 
15 namespace Storage
16 {
17 // Used Partition table entries cached in RAM, initialised on first request
19 {
20 public:
22  {
23  }
24 
35  {
36  return Iterator(mDevice, type, subType);
37  }
38 
39  template <typename T> Iterator find(T subType) const
40  {
41  return find(Partition::Type(T::partitionType), uint8_t(subType));
42  }
43 
53  Partition find(const String& name) const
54  {
55  return *std::find(begin(), end(), name);
56  }
57 
63  Partition find(uint32_t address) const
64  {
65  return *std::find_if(begin(), end(), [address](Partition part) { return part.contains(address); });
66  }
67 
71  Partition findOta(uint8_t index)
72  {
73  using App = Partition::SubType::App;
74  auto subtype = App(uint8_t(App::ota0) + index);
75  return (subtype >= App::ota_min && subtype <= App::ota_max) ? *find(subtype) : Partition{};
76  }
77 
78  Iterator begin() const
79  {
80  return Iterator(mDevice, 0);
81  }
82 
83  Iterator end() const
84  {
85  return Iterator(mDevice, mCount);
86  }
87 
88  uint8_t count() const
89  {
90  return mCount;
91  }
92 
93  Device& device() const
94  {
95  return mDevice;
96  }
97 
98  Partition operator[](unsigned index) const
99  {
100  return (index < mCount) ? Partition(mDevice, mEntries.get()[index]) : Partition();
101  }
102 
103 protected:
104  friend Device;
105  void load(const esp_partition_info_t* entry, unsigned count);
106 
108  std::unique_ptr<Partition::Info[]> mEntries;
109  uint8_t mCount{0};
110 };
111 
112 } // namespace Storage
uint8_t count() const
Definition: PartitionTable.h:88
bool contains(uint32_t addr) const
Determine if given address contained within this partition.
Definition: Partition.h:342
Partition find(uint32_t address) const
Find partition containing the given address.
Definition: PartitionTable.h:63
Iterator find(T subType) const
Definition: PartitionTable.h:39
Device & mDevice
Definition: PartitionTable.h:107
friend Device
Definition: PartitionTable.h:104
Iterator end() const
Definition: PartitionTable.h:83
uint8_t mCount
Definition: PartitionTable.h:109
The String class.
Definition: WString.h:136
Iterator begin() const
Definition: PartitionTable.h:78
Partition find(const String &name) const
Find partition by name.
Definition: PartitionTable.h:53
Definition: Iterator.h:18
Device & device() const
Definition: PartitionTable.h:93
static constexpr uint8_t any
Definition: Partition.h:92
Partition findOta(uint8_t index)
Find the n&#39;th OTA partition.
Definition: PartitionTable.h:71
PartitionTable(Device &device)
Definition: PartitionTable.h:21
Internal structure describing the binary layout of a partition table entry.
Definition: partition_info.h:18
Type
Definition: Partition.h:81
Represents a storage device (e.g. flash memory)
Definition: Components/Storage/src/include/Storage/Device.h:32
void load(const esp_partition_info_t *entry, unsigned count)
Represents a flash partition.
Definition: Partition.h:78
Partition operator[](unsigned index) const
Definition: PartitionTable.h:98
Iterator find(Partition::Type type=Partition::Type::any, uint8_t subType=Partition::SubType::any) const
Definition: PartitionTable.h:34
std::unique_ptr< Partition::Info[]> mEntries
Definition: PartitionTable.h:108
Definition: FileDevice.h:23
App
Application partition type.
Definition: Partition.h:98
Definition: PartitionTable.h:18