summaryrefslogtreecommitdiff
path: root/WebInterface/wasm/webhogg/src
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-29 21:51:49 +0200
committernatrixaeria <janng@gmx.de>2019-05-29 21:51:49 +0200
commitbf0137c3fc6093df085b9d95cd251b7f67d94815 (patch)
tree435f024e02e4f0bd867d1ca5a829d3ef19a97545 /WebInterface/wasm/webhogg/src
parenta6d2d62fae44b6d8c96e51055f7222bc679efc48 (diff)
Create webhogg project directory
Diffstat (limited to 'WebInterface/wasm/webhogg/src')
-rw-r--r--WebInterface/wasm/webhogg/src/app.rs15
-rw-r--r--WebInterface/wasm/webhogg/src/client_logger.rs46
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs25
-rw-r--r--WebInterface/wasm/webhogg/src/webhogg_exception.rs25
4 files changed, 111 insertions, 0 deletions
diff --git a/WebInterface/wasm/webhogg/src/app.rs b/WebInterface/wasm/webhogg/src/app.rs
new file mode 100644
index 0000000..bee7c08
--- /dev/null
+++ b/WebInterface/wasm/webhogg/src/app.rs
@@ -0,0 +1,15 @@
+use crate::webhogg_exception::WebhoggException;
+
+pub struct WebhoggApplication {
+}
+
+impl WebhoggApplication {
+ pub fn new() -> Result<Self, WebhoggException> {
+ Ok(Self {
+ })
+ }
+
+ pub fn run(&mut self) -> Result<(), WebhoggException> {
+ Ok(())
+ }
+}
diff --git a/WebInterface/wasm/webhogg/src/client_logger.rs b/WebInterface/wasm/webhogg/src/client_logger.rs
new file mode 100644
index 0000000..f71918f
--- /dev/null
+++ b/WebInterface/wasm/webhogg/src/client_logger.rs
@@ -0,0 +1,46 @@
+use wasm_bindgen::prelude::*;
+
+#[wasm_bindgen]
+extern "C" {
+ #[wasm_bindgen(js_namespace=console, js_name=debug)]
+ fn __console_debug_colored2(f: &str, c1: &str, c2: &str);
+ #[wasm_bindgen(js_namespace=console, js_name=info)]
+ fn __console_info_colored2(f: &str, c1: &str, c2: &str);
+ #[wasm_bindgen(js_namespace=console, js_name=warn)]
+ fn __console_warn_colored2(f: &str, c1: &str, c2: &str);
+ #[wasm_bindgen(js_namespace=console, js_name=error)]
+ fn __console_error_colored2(f: &str, c1: &str, c2: &str);
+}
+
+fn log(rec: &log::Record) {
+ let log_fn = match rec.level() {
+ log::Level::Trace | log::Level::Debug => __console_debug_colored2,
+ log::Level::Info => __console_info_colored2,
+ log::Level::Warn => __console_warn_colored2,
+ log::Level::Error => __console_error_colored2,
+ };
+ log_fn(&format!("{}", rec.args()),
+ &format!("color: {}", match rec.level() {
+ log::Level::Trace => "violet",
+ log::Level::Debug => "blue",
+ log::Level::Info => "green",
+ log::Level::Warn => "orange",
+ log::Level::Error => "red"
+ }), "");
+}
+
+pub fn init_logger() {
+ fern::Dispatch::new().format(|out, message, record|{
+ out.finish(format_args!(
+ "%c{}%c {} > {}",
+ record.level(),
+ record.target(),
+ message
+ )
+ )
+ })
+ .level(log::LevelFilter::Debug)
+ .chain(fern::Output::call(log))
+ .apply().unwrap();
+}
+
diff --git a/WebInterface/wasm/webhogg/src/lib.rs b/WebInterface/wasm/webhogg/src/lib.rs
new file mode 100644
index 0000000..8b75ee1
--- /dev/null
+++ b/WebInterface/wasm/webhogg/src/lib.rs
@@ -0,0 +1,25 @@
+mod client_logger;
+mod webhogg_exception;
+mod app;
+
+use wasm_bindgen::prelude::*;
+use app::WebhoggApplication as App;
+
+#[macro_use]
+extern crate log;
+
+fn run_application() {
+ match App::new().and_then(|mut app| app.run()) {
+ Ok(_) => info!("program terminated successfully"),
+ Err(e) => error!("program terminated with failure > {}", e)
+ }
+}
+
+#[wasm_bindgen(start)]
+pub fn entry() {
+ client_logger::init_logger();
+
+ info!("begin running wasm application");
+
+ run_application()
+}
diff --git a/WebInterface/wasm/webhogg/src/webhogg_exception.rs b/WebInterface/wasm/webhogg/src/webhogg_exception.rs
new file mode 100644
index 0000000..eac67c7
--- /dev/null
+++ b/WebInterface/wasm/webhogg/src/webhogg_exception.rs
@@ -0,0 +1,25 @@
+use std::error::Error;
+
+#[derive(Debug)]
+pub enum WebhoggException {
+}
+
+impl Error for WebhoggException {
+ fn description(&self) -> &str {
+ "webhogg exception"
+ }
+
+ fn cause(&self) -> Option<&dyn Error> {
+ self.source()
+ }
+
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ None
+ }
+}
+
+impl std::fmt::Display for WebhoggException {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(f, "WebhoggException: {}", self.description())
+ }
+}