mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 23:33:58 +08:00
* always c++
* Create C++ params class
* get works
* tests hang now
* passes tests
* cleanup string formatting
* handle interrupt in blocking read
* fix memory leak
* remove unused constructor
* Use delete_db_value directly
* Rename put -> write_db_value
* filename cleanup
* no semicolons in cython
* Update common/SConscript
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
* add std::string version of delete_db_value
* This is handled
* cleanup encoding
* Add clear method to clear all
* add persistent params
* fix android build
* Should be called clear_all
* only import params when needed
* set params path on manager import
* recusrively create directories
* Fix function order
* cleanup mkdirp
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 2e182e5c57
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
#pragma once
|
|
#include <stddef.h>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#define ERR_NO_VALUE -33
|
|
|
|
class Params {
|
|
private:
|
|
std::string params_path;
|
|
|
|
public:
|
|
Params(bool persistent_param = false);
|
|
Params(std::string path);
|
|
|
|
int write_db_value(std::string key, std::string dat);
|
|
int write_db_value(const char* key, const char* value, size_t value_size);
|
|
|
|
// Reads a value from the params database.
|
|
// Inputs:
|
|
// key: The key to read.
|
|
// value: A pointer where a newly allocated string containing the db value will
|
|
// be written.
|
|
// value_sz: A pointer where the size of value will be written. Does not
|
|
// include the NULL terminator.
|
|
// persistent_param: Boolean indicating if the param store in the /persist partition is to be used.
|
|
// e.g. for sensor calibration files. Will not be cleared after wipe or re-install.
|
|
//
|
|
// Returns: Negative on failure, otherwise 0.
|
|
int read_db_value(const char* key, char** value, size_t* value_sz);
|
|
|
|
// Delete a value from the params database.
|
|
// Inputs are the same as read_db_value, without value and value_sz.
|
|
int delete_db_value(std::string key);
|
|
int delete_db_value(const char* key);
|
|
|
|
// Reads a value from the params database, blocking until successful.
|
|
// Inputs are the same as read_db_value.
|
|
int read_db_value_blocking(const char* key, char** value, size_t* value_sz);
|
|
|
|
int read_db_all(std::map<std::string, std::string> *params);
|
|
std::vector<char> read_db_bytes(const char* param_name);
|
|
bool read_db_bool(const char* param_name);
|
|
|
|
std::string get(std::string key, bool block=false);
|
|
};
|