2019-07-01 02:09:31 +00:00
|
|
|
#pragma once
|
2018-04-28 12:22:42 +00:00
|
|
|
|
2019-01-20 04:59:37 +00:00
|
|
|
#include <string>
|
2020-05-07 13:08:30 +00:00
|
|
|
#include <map>
|
2019-02-16 01:45:05 +00:00
|
|
|
|
2020-03-09 08:50:30 +00:00
|
|
|
#include <system_properties.h>
|
2018-04-28 12:22:42 +00:00
|
|
|
|
2020-05-07 13:08:30 +00:00
|
|
|
#define PERSISTENT_PROPERTY_DIR "/data/property"
|
|
|
|
|
|
|
|
struct prop_cb {
|
2020-12-31 06:11:24 +00:00
|
|
|
virtual void exec(const char *name, const char *value) {
|
|
|
|
exec(std::string(name), value);
|
|
|
|
}
|
|
|
|
virtual void exec(std::string &&name, const char *value) {
|
|
|
|
exec(name.data(), value);
|
|
|
|
}
|
2018-04-28 12:22:42 +00:00
|
|
|
};
|
|
|
|
|
2020-11-04 09:56:49 +00:00
|
|
|
extern bool use_pb;
|
2020-05-07 13:08:30 +00:00
|
|
|
|
2020-11-04 09:56:49 +00:00
|
|
|
using prop_list = std::map<std::string, std::string>;
|
2020-05-07 13:08:30 +00:00
|
|
|
|
2020-11-04 09:56:49 +00:00
|
|
|
struct prop_collector : prop_cb {
|
2020-12-31 06:11:24 +00:00
|
|
|
explicit prop_collector(prop_list &list) : list(list) {}
|
|
|
|
void exec(const char *name, const char *value) override {
|
|
|
|
list.insert_or_assign(name, value);
|
|
|
|
}
|
|
|
|
void exec(std::string &&name, const char *value) override {
|
|
|
|
list.insert_or_assign(std::move(name), value);
|
|
|
|
}
|
2020-05-07 13:08:30 +00:00
|
|
|
private:
|
2020-12-31 06:11:24 +00:00
|
|
|
prop_list &list;
|
2020-05-07 13:08:30 +00:00
|
|
|
};
|
|
|
|
|
2019-01-20 04:59:37 +00:00
|
|
|
std::string persist_getprop(const char *name);
|
2020-05-07 13:08:30 +00:00
|
|
|
void persist_getprops(prop_cb *prop_cb);
|
2018-04-28 12:22:42 +00:00
|
|
|
bool persist_deleteprop(const char *name);
|