Skip to content

Commit

Permalink
WIP storage trait
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <sebastian.schildt@de.bosch.com>
  • Loading branch information
SebastianSchildt committed Oct 14, 2024
1 parent 89f9943 commit 0610a79
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
25 changes: 24 additions & 1 deletion kuksa-persistence-provider/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License 2.0 which is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

use std::path::PathBuf;
mod storage;

use std::{path::PathBuf};
use clap::Parser;
use tinyjson::JsonValue;

Expand Down Expand Up @@ -35,6 +46,18 @@ fn main() {
let parsed: JsonValue = config_str.parse().unwrap();
println!("Parsed: {:?}", parsed);

match parsed["state-storage"]["type"].get::<String>().unwrap().as_str() {
"file" => {
println!("File Storage");
let mut _storage = storage::FileStorage::new(&parsed["state-storage"]);
},
_ => {
eprintln!("Error: state storage type is invalid");
std::process::exit(1);
}
}




println!("Hello, world!");
Expand Down
26 changes: 26 additions & 0 deletions kuksa-persistence-provider/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License 2.0 which is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/


pub mod filestorage;

pub use filestorage::FileStorage;
use tinyjson::JsonValue;

trait Storage {
// Associated function signature; `Self` refers to the implementor type.
fn new(config: &JsonValue) -> Self;

// Method signatures; these will return a string.
fn get(&self, vsspath: &'static str) -> &'static str;

fn set(&self, vsspath: &'static str, vssvalue: &'static str) -> Result<(), ()>;

}
43 changes: 43 additions & 0 deletions kuksa-persistence-provider/src/storage/filestorage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License 2.0 which is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

use tinyjson::JsonValue;

pub struct FileStorage {
storagefile: String,
}

impl FileStorage {
pub fn new(config: &JsonValue) -> Self {
match config["path"].get::<String>()
{
Some(x) => {
println!("File Storage path: {}", x);
//FileStorage { storagefile: "Lol" }
let path = x.clone();
FileStorage { storagefile: path}
}
_ => {
eprintln!("Error: file storage path is invalid");
std::process::exit(1);
}
}
}

fn get(&self, vsspath: &'static str) -> &'static str {
println!("Try getting VSS signal {}", vsspath);
&"LOL"
}

fn set(&self, vsspath: &'static str, vssvalue: &'static str) -> Result<(), ()> {
println!("Setting VSS signal {} to {}", vsspath, vssvalue);
Ok(())
}
}

0 comments on commit 0610a79

Please sign in to comment.