Skip to content

Commit

Permalink
plumbing for source locator
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Oct 20, 2023
1 parent 665d9ec commit 5a97972
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,12 +2539,21 @@ impl UiExtra for egui::Ui {
}

#[cfg(not(target_arch = "wasm32"))]
pub fn start(data_sources: Vec<Box<dyn DeferredDataSource>>) {
pub fn start(mut data_sources: Vec<Box<dyn DeferredDataSource>>) {
env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`).

let app_name = if data_sources.len() == 1 {
match data_sources[0].get_description().source_locator {
Some(source_locator) => source_locator,
_ => String::from("Legion Prof"),
}
} else {
String::from("Legion Prof")
};

let native_options = eframe::NativeOptions::default();
eframe::run_native(
"Legion Prof",
&app_name,
native_options,
Box::new(|cc| Box::new(ProfApp::new(cc, data_sources))),
)
Expand Down
10 changes: 10 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ pub struct SlotMetaTile {
pub data: SlotMetaTileData,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DataSourceDescription {
pub source_locator: Option<String>,
}

pub trait DataSource {
fn fetch_description(&self) -> DataSourceDescription;
fn fetch_info(&self) -> DataSourceInfo;
fn fetch_summary_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SummaryTile;
fn fetch_slot_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SlotTile;
Expand All @@ -215,6 +221,7 @@ pub trait DataSource {
}

pub trait DataSourceMut {
fn fetch_description(&mut self) -> DataSourceDescription;
fn fetch_info(&mut self) -> DataSourceInfo;
fn fetch_summary_tile(
&mut self,
Expand All @@ -232,6 +239,9 @@ pub trait DataSourceMut {
}

impl<T: DataSource> DataSourceMut for T {
fn fetch_description(&mut self) -> DataSourceDescription {
DataSource::fetch_description(self)
}
fn fetch_info(&mut self) -> DataSourceInfo {
DataSource::fetch_info(self)
}
Expand Down
31 changes: 30 additions & 1 deletion src/deferred_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::data::{
DataSourceInfo, DataSourceMut, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSourceDescription, DataSourceInfo, DataSourceMut, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
};

pub trait DeferredDataSource {
fn fetch_description(&mut self);
fn get_description(&mut self) -> DataSourceDescription;
fn fetch_info(&mut self);
fn get_infos(&mut self) -> Vec<DataSourceInfo>;
fn fetch_summary_tile(&mut self, entry_id: &EntryID, tile_id: TileID, full: bool);
Expand Down Expand Up @@ -34,6 +36,14 @@ impl<T: DataSourceMut> DeferredDataSourceWrapper<T> {
}

impl<T: DataSourceMut> DeferredDataSource for DeferredDataSourceWrapper<T> {
fn fetch_description(&mut self) {

}

fn get_description(&mut self) -> DataSourceDescription {
self.data_source.fetch_description()
}

fn fetch_info(&mut self) {
self.infos.push(self.data_source.fetch_info());
}
Expand Down Expand Up @@ -102,6 +112,17 @@ impl<T: DeferredDataSource> CountingDeferredDataSource<T> {
}

impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T> {
fn fetch_description(&mut self) {
self.start_request();
self.data_source.fetch_description()
}

fn get_description(&mut self) -> DataSourceDescription {
let result = self.data_source.get_description();
self.outstanding_requests -= 1;
result
}

fn fetch_info(&mut self) {
self.start_request();
self.data_source.fetch_info()
Expand Down Expand Up @@ -145,6 +166,14 @@ impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T>
}

impl DeferredDataSource for Box<dyn DeferredDataSource> {
fn fetch_description(&mut self) {
self.as_mut().fetch_description()
}

fn get_description(&mut self) -> DataSourceDescription {
self.as_mut().get_description()
}

fn fetch_info(&mut self) {
self.as_mut().fetch_info()
}
Expand Down
5 changes: 4 additions & 1 deletion src/file_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use serde::Deserialize;

use crate::data::{
DataSource, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSource, DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
};
use crate::http::schema::TileRequestRef;

Expand All @@ -30,6 +30,9 @@ impl FileDataSource {
}

impl DataSource for FileDataSource {
fn fetch_description(&self) -> DataSourceDescription {
DataSourceDescription { source_locator: None }
}
fn fetch_info(&self) -> DataSourceInfo {
let path = self.basedir.join("info");
self.read_file::<DataSourceInfo>(&path)
Expand Down
10 changes: 9 additions & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::Deserialize;

use url::Url;

use crate::data::{DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID};
use crate::data::{DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID};
use crate::deferred_data::DeferredDataSource;
use crate::http::fetch::{fetch, DataSourceResponse};
use crate::http::schema::TileRequestRef;
Expand Down Expand Up @@ -62,6 +62,14 @@ impl HTTPClientDataSource {
}

impl DeferredDataSource for HTTPClientDataSource {
fn fetch_description(&mut self) {

}

fn get_description(&mut self) -> DataSourceDescription {
DataSourceDescription {source_locator: None}
}

fn fetch_info(&mut self) {
let url = self.baseurl.join("info").expect("invalid baseurl");
self.request::<DataSourceInfo>(url, self.infos.clone());
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::Rng;
use std::collections::BTreeMap;

use legion_prof_viewer::data::{
DataSourceInfo, DataSourceMut, EntryID, EntryInfo, Field, FieldID, FieldSchema, Item, ItemMeta,
DataSourceDescription, DataSourceInfo, DataSourceMut, EntryID, EntryInfo, Field, FieldID, FieldSchema, Item, ItemMeta,
ItemUID, SlotMetaTile, SlotMetaTileData, SlotTile, SlotTileData, SummaryTile, SummaryTileData,
TileID, TileSet, UtilPoint,
};
Expand Down Expand Up @@ -268,6 +268,9 @@ impl RandomDataSource {
}

impl DataSourceMut for RandomDataSource {
fn fetch_description(&mut self) -> DataSourceDescription {
DataSourceDescription { source_locator: None }
}
fn fetch_info(&mut self) -> DataSourceInfo {
self.info.clone()
}
Expand Down
10 changes: 9 additions & 1 deletion src/parallel_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use crate::data::{
DataSource, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSource, DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
};
use crate::deferred_data::DeferredDataSource;

Expand All @@ -26,6 +26,14 @@ impl<T: DataSource + Send + Sync + 'static> ParallelDeferredDataSource<T> {
}

impl<T: DataSource + Send + Sync + 'static> DeferredDataSource for ParallelDeferredDataSource<T> {
fn fetch_description(&mut self) {

}

fn get_description(&mut self) -> DataSourceDescription {
self.data_source.fetch_description()
}

fn fetch_info(&mut self) {
let data_source = self.data_source.clone();
let infos = self.infos.clone();
Expand Down

0 comments on commit 5a97972

Please sign in to comment.