From 0610a79bb1a0797c98cb6f2fd427be6849ce4905 Mon Sep 17 00:00:00 2001 From: Sebastian Schildt Date: Mon, 14 Oct 2024 18:15:17 +0200 Subject: [PATCH] WIP storage trait Signed-off-by: Sebastian Schildt --- kuksa-persistence-provider/src/main.rs | 25 ++++++++++- kuksa-persistence-provider/src/storage.rs | 26 +++++++++++ .../src/storage/filestorage.rs | 43 +++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 kuksa-persistence-provider/src/storage.rs create mode 100644 kuksa-persistence-provider/src/storage/filestorage.rs diff --git a/kuksa-persistence-provider/src/main.rs b/kuksa-persistence-provider/src/main.rs index 44b8983..b536177 100644 --- a/kuksa-persistence-provider/src/main.rs +++ b/kuksa-persistence-provider/src/main.rs @@ -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; @@ -35,6 +46,18 @@ fn main() { let parsed: JsonValue = config_str.parse().unwrap(); println!("Parsed: {:?}", parsed); + match parsed["state-storage"]["type"].get::().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!"); diff --git a/kuksa-persistence-provider/src/storage.rs b/kuksa-persistence-provider/src/storage.rs new file mode 100644 index 0000000..c1345c4 --- /dev/null +++ b/kuksa-persistence-provider/src/storage.rs @@ -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<(), ()>; + +} diff --git a/kuksa-persistence-provider/src/storage/filestorage.rs b/kuksa-persistence-provider/src/storage/filestorage.rs new file mode 100644 index 0000000..a8fadb9 --- /dev/null +++ b/kuksa-persistence-provider/src/storage/filestorage.rs @@ -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::() + { + 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(()) + } +}