Skip to content

Commit

Permalink
Move the rust source down the folder tree too.
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Jul 31, 2024
1 parent 1ff28b5 commit 9dd588b
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "AGPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "cynthiaweb"
path = "./source/Main/src/main.rs"
path = "./source/Main/main.rs"


[dependencies]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use serde_json::from_str;
use tokio::sync::mpsc::Receiver;
use tokio::sync::Mutex;

use crate::{EPSCommunicationsID, ServerContext};
use crate::config::CynthiaConfig;
use crate::files::tempfolder;
use crate::{EPSCommunicationsID, ServerContext};

#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct EPSRequest {
Expand Down Expand Up @@ -66,7 +66,7 @@ pub(crate) async fn main(
// We gotta write the javascript to a temporary file and then run it.
let jstempfolder = tempfolder().join("js");
std::fs::create_dir_all(&jstempfolder).unwrap();
let jsfile = include_bytes!("../../../target/generated/js/plugins-runtime.js");
let jsfile = include_bytes!("../../target/generated/js/plugins-runtime.js");
std::fs::write(jstempfolder.join("main.js"), jsfile).unwrap();
// now we can run the javascript
let node_runtime: &str = config_clone.runtimes.node.as_ref();
Expand All @@ -75,57 +75,59 @@ pub(crate) async fn main(
let p = Arc::new(std::sync::Mutex::new(String::new()));
let mut proc = InteractiveProcess::new(&mut r, move |line| {
let y = p.clone();
match line {
Ok(o) => {
if o.starts_with("parse: ") {
let l = o.split("parse: ").collect::<Vec<&str>>()[1];
let mut z = y.lock().unwrap();
z.push_str(l);
debug!("JsPluginRuntime is now parsing `{l}` of `{z}`");
let q = from_str::<EPSResponse>(z.as_str());
match q {
Ok(o) => {
debug!("JsPluginRuntime parsed a response: {:?}", o);
rt.spawn(and_now(o, _server_context_mutex.clone()));
z.clear();
}
_ => {}
}
} else {
if o.replace("\n", "").is_empty() {
// Just wait for the next line
} else {
let mut z = y.lock().unwrap();
z.clear();
if o.starts_with("info: ") {
info!("[JsPluginRuntime]: {}", o.split("info: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("debug: ") {
debug!("[JsPluginRuntime]: {}", o.split("debug: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("error: ") {
error!("[JsPluginRuntime]: {}", o.split("error: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("warn: ") {
warn!("[JsPluginRuntime]: {}", o.split("warn: ").collect::<Vec<&str>>()[1]);
} else if o.starts_with("log: "){
config_clone
.clone()
.tell(format!("[JsPluginRuntime]: {}", o.split("log: ").collect::<Vec<&str>>()[1]));
}
}
if let Ok(o) = line {
if o.starts_with("parse: ") {
let l = o.split("parse: ").collect::<Vec<&str>>()[1];
let mut z = y.lock().unwrap();
z.push_str(l);
debug!("JsPluginRuntime is now parsing `{l}` of `{z}`");
let q = from_str::<EPSResponse>(z.as_str());
if let Ok(o) = q {
debug!("JsPluginRuntime parsed a response: {:?}", o);
rt.spawn(and_now(o, _server_context_mutex.clone()));
z.clear();
}
} else if o.replace("\n", "").is_empty() {
// Just wait for the next line
} else {
let mut z = y.lock().unwrap();
z.clear();
if o.starts_with("info: ") {
info!(
"[JsPluginRuntime]: {}",
o.split("info: ").collect::<Vec<&str>>()[1]
);
} else if o.starts_with("debug: ") {
debug!(
"[JsPluginRuntime]: {}",
o.split("debug: ").collect::<Vec<&str>>()[1]
);
} else if o.starts_with("error: ") {
error!(
"[JsPluginRuntime]: {}",
o.split("error: ").collect::<Vec<&str>>()[1]
);
} else if o.starts_with("warn: ") {
warn!(
"[JsPluginRuntime]: {}",
o.split("warn: ").collect::<Vec<&str>>()[1]
);
} else if o.starts_with("log: ") {
config_clone.clone().tell(format!(
"[JsPluginRuntime]: {}",
o.split("log: ").collect::<Vec<&str>>()[1]
));
}
}
_ => {}
}
})
.unwrap();
loop {
match eps_r.recv().await {
Some(o) => {
let mut s = String::from("parse: ");
s.push_str(serde_json::to_string(&o).unwrap().as_str());
debug!("Sending to JsPluginRuntime: `{}`", s);
proc.send(s.as_str()).unwrap();
}
_ => {}
if let Some(o) = eps_r.recv().await {
let mut s = String::from("parse: ");
s.push_str(serde_json::to_string(&o).unwrap().as_str());
debug!("Sending to JsPluginRuntime: `{}`", s);
proc.send(s.as_str()).unwrap();
}
}
}
Expand Down Expand Up @@ -161,7 +163,7 @@ pub(crate) async fn contact_eps(
{
// It's unique! Now add it to the vector to claim it.
server_context.external_plugin_server.unreturned_ids.push(d);
break
break;
} else {
continue;
};
Expand Down Expand Up @@ -199,10 +201,7 @@ pub(crate) async fn contact_eps(
server_context
.external_plugin_server
.response_queue
.retain(|o| match o {
Some(_) => true,
None => false,
});
.retain(|o| o.is_some());

let left_threads = server_context.external_plugin_server.unreturned_ids.len();
for o in server_context
Expand All @@ -220,9 +219,10 @@ pub(crate) async fn contact_eps(
drop(server_context);
{
let mut server_context = _server_context_mutex.lock().await;
server_context.external_plugin_server.unreturned_ids.retain(
|a| a != &random_id
);
server_context
.external_plugin_server
.unreturned_ids
.retain(|a| a != &random_id);
return p;
}
} else {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 14 additions & 6 deletions source/Main/src/main.rs → source/Main/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use std::{fs, process};
use std::fs::File;
use std::option::Option;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{fs, process};

use actix_web::{App, HttpServer};
use actix_web::web::Data;
use actix_web::{App, HttpServer};
use colored::Colorize;
use futures::join;
use log::{debug, error};
#[allow(unused_imports)]
use log::info;
use log::LevelFilter;
use simplelog::{ColorChoice, CombinedLogger, TerminalMode, TermLogger, WriteLogger};
use log::{debug, error};
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use tokio::sync::{Mutex, MutexGuard};

use crate::config::{CynthiaConf, SceneCollectionTrait};
Expand Down Expand Up @@ -49,7 +49,7 @@ struct ServerContext {
cache: CynthiaCache,
request_count: u64,
start_time: u128,
external_plugin_server: EPSCommunicationMemory
external_plugin_server: EPSCommunicationMemory,
}
type EPSCommunicationsID = u32;

Expand Down Expand Up @@ -130,7 +130,15 @@ async fn main() {
"cynthiapluginmanifest.json".bright_green(),);
process::exit(0);
}
"start" | _ => start().await,
"start" => start().await,
_ => {
eprintln!(
"{} Could not interpret command `{}`! Please run `cynthiaweb help` for a list of commands.",
"error:".red(),
args.get(1).unwrap_or(&String::from("")).to_ascii_lowercase()
);
process::exit(1);
}
}
}
async fn start() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9dd588b

Please sign in to comment.