1 // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //         http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef PARTITION_HPP_
16 #define PARTITION_HPP_
17 
18 #include "esp_err.h"
19 
20 namespace nvs {
21 
22 /**
23  * @brief Abstract interface for partition related operations, currently in NVS.
24  *
25  * It resembles the main operations according to esp_partition.h.
26  */
27 class Partition {
28 public:
~Partition()29     virtual ~Partition() { }
30 
31     /**
32      * Return the partition name as in the partition table.
33      */
34     virtual const char *get_partition_name() = 0;
35 
36     virtual esp_err_t read_raw(size_t src_offset, void* dst, size_t size) = 0;
37 
38     virtual esp_err_t read(size_t src_offset, void* dst, size_t size) = 0;
39 
40     virtual esp_err_t write_raw(size_t dst_offset, const void* src, size_t size) = 0;
41 
42     virtual esp_err_t write(size_t dst_offset, const void* src, size_t size) = 0;
43 
44     virtual esp_err_t erase_range(size_t dst_offset, size_t size) = 0;
45 
46     /**
47      * Return the address of the beginning of the partition.
48      */
49     virtual uint32_t get_address() = 0;
50 
51     /**
52      * Return the partition size in bytes.
53      */
54     virtual uint32_t get_size() = 0;
55 };
56 
57 } // nvs
58 
59 #endif // PARTITION_HPP_
60