mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
make the thing compile
This commit is contained in:
parent
8c9cdc4ec5
commit
db9372d5d0
3 changed files with 11 additions and 98 deletions
|
|
@ -29,7 +29,7 @@ default-members = [
|
|||
"services/dns",
|
||||
"services/modals",
|
||||
"services/usb-device-xous",
|
||||
"lib/userprefs"
|
||||
"libs/userprefs"
|
||||
]
|
||||
members = [
|
||||
"xous-ipc",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub fn getter_setter(input: TokenStream) -> TokenStream {
|
|||
syn::Fields::Named(FieldsNamed { named, .. }) => {
|
||||
for field in &named {
|
||||
let ident = field.ident.as_ref().unwrap().clone();
|
||||
let ident_str = ident.to_string();
|
||||
let typ = field.ty.clone();
|
||||
|
||||
let set_fn_name = format_ident!("set_{}", ident);
|
||||
|
|
@ -22,27 +23,17 @@ pub fn getter_setter(input: TokenStream) -> TokenStream {
|
|||
|
||||
let read = quote! {
|
||||
impl Manager {
|
||||
// pub fn #set_fn_name(&mut self, value: #typ) {
|
||||
// self.prefs.#ident = value;
|
||||
// self.pddb_store(&self.prefs).unwrap()
|
||||
// }
|
||||
|
||||
// pub fn #fn_name(&mut self) -> #typ {
|
||||
// self.prefs = self.pddb_get().unwrap();
|
||||
// self.prefs.#ident
|
||||
// }
|
||||
|
||||
pub fn #set_fn_name(&mut self, value: #typ) -> Result<(), Error> {
|
||||
let bytes: Vec<u8> = match bincode::encode_to_vec(value, bincode::config::standard()) {
|
||||
Ok(ret) => Ok(ret),
|
||||
Ok(ret) => ret,
|
||||
Err(err) => return Err(Error::EncodeError(err)),
|
||||
};
|
||||
|
||||
self.pddb_store_key(#fn_name, &bytes)
|
||||
self.pddb_store_key(#ident_str, &bytes)
|
||||
}
|
||||
|
||||
pub fn #fn_name(&mut self) -> Result<#typ, Error> {
|
||||
let bytes = self.pddb_get_key("#fn_name")?;
|
||||
let bytes = self.pddb_get_key(#ident_str)?;
|
||||
let ret: #typ = match bincode::decode_from_slice(&bytes, bincode::config::standard()) {
|
||||
Ok((data, _)) => data,
|
||||
Err(err) => return Err(Error::DecodeError(err)),
|
||||
|
|
@ -52,9 +43,8 @@ pub fn getter_setter(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
};
|
||||
println!("code: {}", read);
|
||||
panic!();
|
||||
//rw_methods.extend(read);
|
||||
|
||||
rw_methods.extend(read);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ use std::io::Read;
|
|||
use std::io::Write;
|
||||
|
||||
static PREFS_DICT: &str = "UserPrefsDict";
|
||||
static PREFS_KEY: &str = "UserPrefsKey";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
|
@ -35,7 +34,6 @@ impl From<DecodeError> for Error {
|
|||
bincode::Encode, bincode::Decode, PartialEq, Debug, Default, prefsgenerator::GetterSetter,
|
||||
)]
|
||||
struct UserPrefs {
|
||||
// TODO: optimize maybe by adding a dirty bit?
|
||||
radio_on_on_boot: bool,
|
||||
connect_known_networks_on_boot: bool,
|
||||
autobacklight_on_boot: bool,
|
||||
|
|
@ -43,86 +41,14 @@ struct UserPrefs {
|
|||
close_bases_on_lock: bool,
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for UserPrefs {
|
||||
fn try_from(data: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
if data.is_empty() {
|
||||
return Ok(Self::default());
|
||||
}
|
||||
let decoded: UserPrefs =
|
||||
match bincode::decode_from_slice(&data, bincode::config::standard()) {
|
||||
Ok((data, _)) => data,
|
||||
Err(err) => return Err(Error::DecodeError(err)),
|
||||
};
|
||||
|
||||
Ok(decoded)
|
||||
}
|
||||
|
||||
type Error = Error;
|
||||
}
|
||||
|
||||
impl TryFrom<&UserPrefs> for Vec<u8> {
|
||||
fn try_from(up: &UserPrefs) -> Result<Self, Self::Error> {
|
||||
match bincode::encode_to_vec(up, bincode::config::standard()) {
|
||||
Ok(ret) => Ok(ret),
|
||||
Err(err) => Err(Error::EncodeError(err)),
|
||||
}
|
||||
}
|
||||
|
||||
type Error = Error;
|
||||
}
|
||||
|
||||
pub struct Manager {
|
||||
pddb_handle: Pddb,
|
||||
prefs: UserPrefs,
|
||||
}
|
||||
|
||||
impl Manager {
|
||||
fn new() -> Self {
|
||||
let mut us = Self {
|
||||
Self {
|
||||
pddb_handle: Pddb::new(),
|
||||
prefs: UserPrefs::default(),
|
||||
};
|
||||
|
||||
us.prefs = us.pddb_get().unwrap();
|
||||
|
||||
us
|
||||
}
|
||||
|
||||
fn pddb_store(&self, payload: &UserPrefs) -> Result<(), Error> {
|
||||
let payload: Vec<u8> = payload.try_into()?;
|
||||
match self.pddb_handle.get(
|
||||
PREFS_DICT,
|
||||
PREFS_KEY,
|
||||
Some(".System"),
|
||||
true,
|
||||
true,
|
||||
None,
|
||||
None::<fn()>,
|
||||
) {
|
||||
Ok(mut data) => match data.write(&payload) {
|
||||
Ok(_) => Ok(self.pddb_handle.sync().unwrap_or(())),
|
||||
Err(e) => Err(e.into()),
|
||||
},
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn pddb_get(&self) -> Result<UserPrefs, Error> {
|
||||
match self.pddb_handle.get(
|
||||
PREFS_DICT,
|
||||
PREFS_KEY,
|
||||
Some(".System"),
|
||||
true,
|
||||
true,
|
||||
None,
|
||||
None::<fn()>,
|
||||
) {
|
||||
Ok(mut record) => {
|
||||
let mut data = Vec::<u8>::new();
|
||||
record.read_to_end(&mut data)?;
|
||||
Ok(data.try_into()?)
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +73,7 @@ impl Manager {
|
|||
fn pddb_get_key(&self, key: &str) -> Result<Vec<u8>, Error> {
|
||||
match self.pddb_handle.get(
|
||||
PREFS_DICT,
|
||||
PREFS_KEY,
|
||||
key,
|
||||
Some(".System"),
|
||||
true,
|
||||
true,
|
||||
|
|
@ -171,11 +97,8 @@ impl Default for Manager {
|
|||
}
|
||||
|
||||
mod test {
|
||||
use crate::{Manager, UserPrefs};
|
||||
|
||||
#[test]
|
||||
fn describe() {
|
||||
//UserPrefs::describe();
|
||||
let m = Manager::new();
|
||||
}
|
||||
use crate::Manager;
|
||||
let _m = Manager::new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue