1 // Copyright 2015-2016 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 #ifndef NVS_PARTITION_MANAGER_HPP_
15 #define NVS_PARTITION_MANAGER_HPP_
16 
17 #include "nvs_handle_simple.hpp"
18 #include "nvs_storage.hpp"
19 #include "nvs_partition.hpp"
20 #include "nvs_flash.h"
21 
22 namespace nvs {
23 
24 class NVSPartitionManager {
25 public:
~NVSPartitionManager()26     virtual ~NVSPartitionManager() { }
27 
28     static NVSPartitionManager* get_instance();
29 
30     esp_err_t init_partition(const char *partition_label);
31 
32     esp_err_t init_custom(Partition *partition, uint32_t baseSector, uint32_t sectorCount);
33 
34 #ifdef CONFIG_NVS_ENCRYPTION
35     esp_err_t secure_init_partition(const char *part_name, nvs_sec_cfg_t* cfg);
36 #endif
37 
38     esp_err_t deinit_partition(const char *partition_label);
39 
40     Storage* lookup_storage_from_name(const char* name);
41 
42     esp_err_t open_handle(const char *part_name, const char *ns_name, nvs_open_mode_t open_mode, NVSHandleSimple** handle);
43 
44     esp_err_t close_handle(NVSHandleSimple* handle);
45 
46     size_t open_handles_size();
47 
48 protected:
NVSPartitionManager()49     NVSPartitionManager() { }
50 
51     static NVSPartitionManager* instance;
52 
53     intrusive_list<NVSHandleSimple> nvs_handles;
54 
55     intrusive_list<nvs::Storage> nvs_storage_list;
56 
57     intrusive_list<nvs::NVSPartition> nvs_partition_list;
58 };
59 
60 } // nvs
61 
62 #endif // NVS_PARTITION_MANAGER_HPP_
63