From d3b15a5d4f4c1b1f01117b0623ab4c8763e52ae4 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 18 Aug 2021 00:25:53 -0300 Subject: Prepare design of data --- src/data/managers.rs | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/data/managers.rs (limited to 'src/data/managers.rs') diff --git a/src/data/managers.rs b/src/data/managers.rs new file mode 100644 index 0000000..71a9484 --- /dev/null +++ b/src/data/managers.rs @@ -0,0 +1,98 @@ +// This file is part of GAnarchy - decentralized development hub +// Copyright (C) 2021 Soni L. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use std::error; +use std::sync::Arc; +use std::sync::Mutex; +use std::sync::RwLock; +use std::time::Duration; + +use impl_trait::impl_trait; + +use super::DataSourceBase; +use super::DataSource; +use super::effective::EffectiveKind; +//use super::Kind; +use super::kinds::{InstanceTitle, InstanceBaseUrl, RepoListUrl, ProjectFork}; +//use super::OverridableKind; + +/// Stores multiple DataSource capable of ProjectFork +#[derive(Default)] +pub struct RepoListManager { + repos: Vec> + Send + Sync>>, + durations: Vec, + valid: usize, +} + +/// Stores multiple DataSource capable of InstanceTitle, InstanceBaseUrl and +/// RepoListUrl +#[derive(Default)] +pub struct ConfigManager { + // conceptually the actual objects + bases: Vec>>, + // conceptually just views of the above objects + titles: Vec + Send + Sync>>>>, + urls: Vec + Send + Sync>>>>, + repolists: Vec + Send + Sync>>>>, + durations: Vec, + // add_source can be called after update. + valid: usize, +} + +impl_trait! { + impl ConfigManager { + /// Creates a new `ConfigManager`. + pub fn new() -> Self { + Default::default() + } + + /// Adds the given combined `DataSource` to this `ConfigManager`. + pub fn add_source(&mut self, source: T) + where + T: DataSource, + T: DataSource, + T: DataSource, + T: Send + Sync + 'static, + { + let arc = Arc::new(RwLock::new(source)); + self.bases.push(arc.clone()); + self.titles.push(Some(arc.clone())); + self.urls.push(Some(arc.clone())); + self.repolists.push(Some(arc)); + } + + impl trait DataSourceBase { + /// Updates the contained `DataSource`s, and returns the shortest + /// duration for the next update. + /// + /// # Errors + /// + /// Returns an error if any `DataSource` returns an error. Always + /// updates all `DataSource`s. + fn update(&mut self) -> ( + Duration, + Result<(), Box>, + ) { + todo!() + } + + /// Returns whether this data source contains any (valid) data. + fn exists(&self) -> bool { + todo!() + } + } + } +} -- cgit 1.4.1