mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-11 17:42:25 +00:00
Update nanopb
This commit is contained in:
@@ -8,41 +8,30 @@
|
||||
#define PERSISTENT_PROPERTY_DIR "/data/property"
|
||||
|
||||
struct prop_cb {
|
||||
virtual void exec(const char *name, const char *value) = 0;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct prop_cb_impl : public prop_cb {
|
||||
typedef void (*callback_type)(const char *, const char *, T&);
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-field" // Dangling field is expected
|
||||
prop_cb_impl(T &arg, callback_type fn) : arg(arg), fn(fn) {}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
void exec(const char *name, const char *value) override {
|
||||
fn(name, value, arg);
|
||||
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);
|
||||
}
|
||||
private:
|
||||
T &arg;
|
||||
callback_type fn;
|
||||
};
|
||||
|
||||
extern bool use_pb;
|
||||
|
||||
using prop_list = std::map<std::string_view, std::string>;
|
||||
using prop_list = std::map<std::string, std::string>;
|
||||
|
||||
struct prop_collector : prop_cb_impl<prop_list> {
|
||||
prop_collector(prop_list &list) :
|
||||
prop_cb_impl<prop_list>(list, [](auto name, auto val, auto list){ list.emplace(name, val); }) {}
|
||||
struct prop_collector : prop_cb {
|
||||
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);
|
||||
}
|
||||
private:
|
||||
prop_list &list;
|
||||
};
|
||||
|
||||
template <class T, class Func>
|
||||
prop_cb_impl<T> make_prop_cb(T &arg, Func f) {
|
||||
return prop_cb_impl<T>(arg, f);
|
||||
}
|
||||
|
||||
std::string persist_getprop(const char *name);
|
||||
void persist_getprops(prop_cb *prop_cb);
|
||||
bool persist_deleteprop(const char *name);
|
||||
void persist_cleanup();
|
||||
|
||||
Reference in New Issue
Block a user