// 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!() } } } }