2019-07-01 04:09:31 +02:00
|
|
|
#pragma once
|
2018-04-28 14:22:42 +02:00
|
|
|
|
2019-01-20 05:59:37 +01:00
|
|
|
#include <string>
|
2020-03-09 09:50:30 +01:00
|
|
|
#include <logging.hpp>
|
2019-02-16 02:45:05 +01:00
|
|
|
|
2020-03-09 09:50:30 +01:00
|
|
|
#include <system_properties.h>
|
2018-04-28 14:22:42 +02:00
|
|
|
|
|
|
|
struct prop_t {
|
|
|
|
char *name;
|
|
|
|
char value[PROP_VALUE_MAX];
|
2019-01-20 05:59:37 +01:00
|
|
|
prop_t() : name(nullptr) {}
|
|
|
|
explicit prop_t(const char *name) {
|
2018-11-03 04:56:15 +01:00
|
|
|
this->name = strdup(name);
|
2018-11-05 20:37:47 +01:00
|
|
|
value[0] = '\0';
|
2018-11-03 04:56:15 +01:00
|
|
|
}
|
|
|
|
prop_t(const char *name, const char *value) {
|
|
|
|
this->name = strdup(name);
|
|
|
|
strcpy(this->value, value);
|
|
|
|
}
|
2019-01-20 05:59:37 +01:00
|
|
|
prop_t(prop_t &&prop): name(nullptr) {
|
|
|
|
operator=(std::move(prop));
|
|
|
|
}
|
|
|
|
bool operator<(const prop_t &prop) const {
|
|
|
|
return strcmp(name, prop.name) < 0;
|
|
|
|
}
|
2019-07-01 04:09:31 +02:00
|
|
|
prop_t& operator=(prop_t &&prop) {
|
2018-11-03 04:56:15 +01:00
|
|
|
if (this != &prop) {
|
|
|
|
free(name);
|
|
|
|
name = prop.name;
|
|
|
|
strcpy(value, prop.value);
|
|
|
|
prop.name = nullptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
};
|
|
|
|
~prop_t() {
|
|
|
|
free(name);
|
|
|
|
}
|
2018-04-28 14:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct read_cb_t {
|
2018-11-03 04:56:15 +01:00
|
|
|
void (*cb)(const char *, const char *, void *);
|
|
|
|
void *arg;
|
2019-01-20 05:59:37 +01:00
|
|
|
explicit read_cb_t(void (*cb)(const char *, const char *, void *) = nullptr, void *arg = nullptr)
|
2018-11-03 04:56:15 +01:00
|
|
|
: cb(cb), arg(arg) {}
|
|
|
|
void exec(const char *name, const char *value) {
|
|
|
|
cb(name, value, arg);
|
|
|
|
}
|
2018-04-28 14:22:42 +02:00
|
|
|
};
|
|
|
|
|
2018-11-03 04:56:15 +01:00
|
|
|
#define PERSISTENT_PROPERTY_DIR "/data/property"
|
|
|
|
|
|
|
|
extern bool use_pb;
|
|
|
|
|
2019-01-20 05:59:37 +01:00
|
|
|
std::string persist_getprop(const char *name);
|
2018-11-05 20:37:47 +01:00
|
|
|
void persist_getprop(read_cb_t *read_cb);
|
2018-04-28 14:22:42 +02:00
|
|
|
bool persist_deleteprop(const char *name);
|
2018-11-03 04:56:15 +01:00
|
|
|
void collect_props(const char *name, const char *value, void *v_plist);
|