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
18 class PartitionTable
19 {
20 public:
22  {
23  }
24 
25  explicit operator bool() const
26  {
27  return mEntries.isEmpty();
28  }
29 
43  {
44  return Iterator(mDevice, type, subType);
45  }
46 
47  Iterator find(Partition::FullType fullType) const
48  {
49  return find(fullType.type, fullType.subtype);
50  }
51 
61  Partition find(const String& name) const
62  {
63  return *std::find(begin(), end(), name);
64  }
65 
71  Partition find(uint32_t address) const
72  {
73  return *std::find_if(begin(), end(), [address](Partition part) { return part.contains(address); });
74  }
75 
79  Partition findOta(uint8_t index) const
80  {
81  using App = Partition::SubType::App;
82  auto subtype = App(uint8_t(App::ota0) + index);
83  return (subtype >= App::ota_min && subtype <= App::ota_max) ? *find(subtype) : Partition{};
84  }
85 
86  Iterator begin() const
87  {
88  return Iterator(mDevice);
89  }
90 
91  Iterator end() const
92  {
93  return Iterator(mDevice).end();
94  }
95 
96  Device& device() const
97  {
98  return mDevice;
99  }
100 
106  Partition add(const Partition::Info* info)
107  {
108  return mEntries.add(info) ? Partition(mDevice, *info) : Partition{};
109  }
110 
111  template <typename... Args> Partition add(const String& name, Partition::FullType type, Args... args)
112  {
113  return add(new Partition::Info(name, type, args...));
114  }
115 
116  void clear()
117  {
118  mEntries.clear();
119  }
120 
121 protected:
122  friend Device;
123  friend Iterator;
124 
125  void load(const esp_partition_info_t* entry, unsigned count);
126 
129 };
130 
131 } // namespace Storage
Represents a flash partition.
Definition: Partition.h:85
void clear()
Definition: PartitionTable.h:132
Internal structure describing the binary layout of a partition table entry.
Definition: partition_info.h:26
Partition::Info::OwnedList mEntries
Definition: PartitionTable.h:144
void clear()
Definition: LinkedObjectList.h:194
Partition information.
Definition: Partition.h:181
Device & device() const
Definition: PartitionTable.h:112
void load(const esp_partition_info_t *entry, unsigned count)
The String class.
Definition: WString.h:136
Partition findOta(uint8_t index) const
Find the n'th OTA partition.
Definition: PartitionTable.h:95
bool add(ObjectType *object)
Definition: LinkedObjectList.h:134
Iterator begin() const
Definition: PartitionTable.h:102
friend Iterator
Definition: PartitionTable.h:139
Definition: FileDevice.h:25
Express both partition type and subtype together.
Definition: Partition.h:139
Partition add(const Partition::Info *info)
Add new partition using given Info.
Definition: PartitionTable.h:122
Definition: Iterator.h:26
Represents a storage device (e.g. flash memory)
Definition: Components/Storage/src/include/Storage/Device.h:33
App
Application partition type.
Definition: Partition.h:105
bool isEmpty() const
Definition: LinkedObjectList.h:88
static constexpr uint8_t any
Definition: Partition.h:99
Iterator end() const
Definition: PartitionTable.h:107
Type
Definition: Partition.h:88
Device & mDevice
Definition: PartitionTable.h:143
bool contains(storage_size_t addr) const
Determine if given address contained within this partition.
Definition: Partition.h:416
PartitionTable(Device &device)
Definition: PartitionTable.h:37
Iterator find(Partition::Type type=Partition::Type::any, uint8_t subType=Partition::SubType::any) const
Find partitions based on one or more parameters.
Definition: PartitionTable.h:58
friend Device
Definition: PartitionTable.h:138