diff --git a/$h b/$h new file mode 100644 index 0000000..31f65fb --- /dev/null +++ b/$h @@ -0,0 +1,36 @@ +use warp::Filter; +use std::{ + thread, + sync::{Arc, Mutex}, +} +use crate::config; +use serde::{Deserialize, Serialize}; +use crate::mpsc::*; +use tokio::sync::RwLock; +use crate::api; + +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Data_to_send { + pub action_type: String, + pub content: String, + pub character: String, +} +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Data_to_receive { + pub response: String, +} + +pub async fn api_process(data_to_send: Arc) +{ + let route = warp::path("happening") + .map({ + let state = Arc::clone(&data_to_send); + move || { + let current_data = state.lock().unwrap().clone(); + warp::reply::json(current_data) + } + }); + warp::serve(routes) + .run(([127, 0, 0, 1],config::API_PORT)); + .await; +} diff --git a/.qtcreator/project.json b/.qtcreator/project.json new file mode 100644 index 0000000..d9860ad --- /dev/null +++ b/.qtcreator/project.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://download.qt.io/official_releases/qtcreator/latest/installer_source/jsonschemas/project.json", + "build.configuration": [ + { + "name": "cargo build", + "steps": [ + { + "arguments": [ + "build" + ], + "executable": "cargo", + "workingDirectory": "%{ActiveProject:ProjectDirectory}" + } + ] + } + ], + "files.exclude": [ + ".qtcreator/project.json.user" + ], + "targets": [ + { + "arguments": [ + "run" + ], + "executable": "cargo", + "name": "cargo run", + "workingDirectory": "%{ActiveProject:ProjectDirectory}" + } + ] +} diff --git a/.qtcreator/project.json.user b/.qtcreator/project.json.user new file mode 100644 index 0000000..c285834 --- /dev/null +++ b/.qtcreator/project.json.user @@ -0,0 +1,294 @@ + + + + + + EnvironmentId + {feb331f8-7617-4b45-82a8-67687dcf787d} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + true + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 0 + 80 + true + true + 1 + 0 + false + true + false + 2 + true + true + 0 + 8 + true + false + 1 + false + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 6 + true + + + + true + + 0 + + + + ProjectExplorer.Project.Target.0 + + Desktop + true + Desktop + Desktop + {120e6ad0-5207-4289-8a6a-7630e1616590} + 0 + 0 + 0 + + /home/deadvey/code/rust/happening + + + true + build + cargo + %{ActiveProject:ProjectDirectory} + /home/deadvey/code/rust/happening + ProjectExplorer.ProcessStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + cargo build + WorkspaceProject.BuildConfiguration + 0 + 0 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + cargo run + WorkspaceProject.RunConfiguration: + cargo run1 + false + + true + true + false + run + cargo + %{ActiveProject:ProjectDirectory} + + 1 + + true + cargo build + + + + build + + cargo + %{ActiveProject:ProjectDirectory} + + + + + + /home/deadvey/code/rust/happening/build + + 0 + Build + Build + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Default + WorkspaceProject.BuildConfiguration + 0 + 0 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + cargo run + WorkspaceProject.RunConfiguration: + cargo run1 + false + + true + true + false + run + cargo + %{ActiveProject:ProjectDirectory} + + 1 + + 2 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + cargo run + WorkspaceProject.RunConfiguration: + cargo run1 + false + + true + true + false + run + cargo + %{ActiveProject:ProjectDirectory} + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + Version + 22 + + diff --git a/.~lock.report.odt# b/.~lock.report.odt# index 64ba272..1f82241 100644 --- a/.~lock.report.odt# +++ b/.~lock.report.odt# @@ -1 +1 @@ -,deadvey,linux-pc,05.04.2026 21:48,file:///home/deadvey/.config/libreoffice/4; \ No newline at end of file +,deadvey,linux-pc,07.04.2026 00:08,file:///home/deadvey/.config/libreoffice/4; \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 9096bc9..ba88abf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,646 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "happening-server" version = "0.1.0" +dependencies = [ + "serde", + "tokio", + "warp", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "headers" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" +dependencies = [ + "http", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "indexmap" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a8a2b9cb3e0b0c1803dbb0758ffac5de2f425b23c28f518faabd9d805342ff" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "libc" +version = "0.2.184" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd1c4c0fc4a7ab90fc15ef6daaa3ec3b893f004f915f2392557ed23237820cd" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "warp" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d06d9202adc1f15d709c4f4a2069be5428aa912cc025d6f268ac441ab066b0" +dependencies = [ + "bytes", + "futures-util", + "headers", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-util", + "tower-service", + "tracing", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 3c7f246..94a3e47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] +serde = { version = "1.0.228", features = ["derive"] } +tokio = { version = "1.51.0", features = ["rt-multi-thread","macros"] } +warp = { version = "0.4.2", features = ["server"] } diff --git a/report.odt b/report.odt index 18ffc82..15a4491 100644 Binary files a/report.odt and b/report.odt differ diff --git a/src/parsing/.strings.rs.swp b/src/.api.rs.swp similarity index 87% rename from src/parsing/.strings.rs.swp rename to src/.api.rs.swp index e5337a8..9dc8f1c 100644 Binary files a/src/parsing/.strings.rs.swp and b/src/.api.rs.swp differ diff --git a/src/.parsing.rs.swp b/src/.parsing.rs.swp deleted file mode 100644 index 9a669e0..0000000 Binary files a/src/.parsing.rs.swp and /dev/null differ diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..8336191 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,41 @@ +use warp::Filter; +use std::{ + thread, + sync::{Arc, Mutex}, +}; +use crate::config; +use serde::{Deserialize, Serialize}; +use crate::mpsc::*; +use tokio::sync::RwLock; +use crate::api; + +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Data_to_send { + pub action_type: String, + pub content: String, + pub character: String, +} +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Data_to_receive { + pub response: String, +} + +pub async fn api_process(data_to_send: Arc>, tx: Sender) +{ + let data_filter = warp::any().map(move || Arc::clone(&data_to_send)); + let tx_filter = warp::any().map(move || tx.clone()); + println!("Running server"); + let route = warp::path("happening") + .and(warp::get()) + .and(data_filter) + .and(tx_filter) + .map(|state: Arc>, tx_handle: Sender| { + println!("GET: {:?}", state); + let reply = state.as_ref(); + tx_handle.send(1); + warp::reply::json(&reply) + }).boxed(); + warp::serve(route) + .run(([127, 0, 0, 1],config::API_PORT)) + .await; +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..4f60f44 --- /dev/null +++ b/src/config.rs @@ -0,0 +1 @@ +pub static API_PORT: u16 = 20264; diff --git a/src/main.rs b/src/main.rs index b8527b9..afce756 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,38 @@ -use std::fs; -use std::collections::HashMap; +use std:: +{ + fs, + thread, + collections::HashMap, + sync::{Arc, Mutex, mpsc}, +}; +use serde::{Deserialize, Serialize}; +use tokio::runtime::Runtime; +use tokio::task; +use warp::Filter; mod parsing; mod character; +mod config; +mod api; -fn main() { +#[tokio::main] +async fn main() { + let (tx,rx) = mpsc::channel(); + let mut data_to_send = Arc::new(Mutex::new(api::Data_to_send + { + action_type: "initialise".to_string(), + content: "".to_string(), + character: "".to_string(), + })); + + let data = Arc::clone(&data_to_send); + let tx_clone = tx.clone(); + // Spawn a thread for warp + tokio::spawn( + async move { + api::api_process(data, tx_clone).await; + }); + println!("and continue"); let mut characters = HashMap::::new(); let file_contents: String = fs::read_to_string("stories/story.ha").unwrap(); // Split the file contents into tokens @@ -12,7 +40,9 @@ fn main() { .split_whitespace() .collect(); // Run the parsing process - match parsing::token_parse(&tokens, &mut characters) { + let data_clone = Arc::clone(&data_to_send); + match parsing::token_parse(&tokens, &mut characters, data_clone, &rx).await + { Ok(()) => println!("Program exited successfully"), Err(error) => println!("{}", error), } diff --git a/src/parsing.rs b/src/parsing.rs index b10af6d..787fdc8 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -1,60 +1,82 @@ use std::collections::HashMap; use crate::character; +use crate::api; +use crate::mpsc::*; +use std::{thread}; +use std::sync::{Arc,Mutex}; +use std::time::Duration; mod strings; // Parse the tokens in a file // Returns success or an error string -pub fn token_parse( +pub async fn token_parse( tokens: &Vec<&str>, - mut characters: &mut HashMap:: -) -> ( Result<(),&'static str> ) + mut characters: &mut HashMap::, + data_to_send: Arc>, + rx: &Receiver, +) -> Result<(),String> { let mut index: usize = 0; // Run an infinite loop loop { - match tokens.get(index) { - Some(token) => { - // The instructions are related to characters - if token.chars().next().unwrap() == '@' - { - let character_name: String = token.chars().skip(1).collect(); - // If the character doesn't exist, then create it - if ! characters.contains_key(&character_name) - { - let new_character = character::Character::new(character_name.clone()); - characters.insert(character_name.clone(),new_character); - } - println!("Doing something with a character: {}", character_name); - // The index is incremented to after the character's instructions - index += match character_parse(index+1, &tokens, character_name, &mut characters) - { - Ok(increment) => increment, - Err(error) => return Err(error), - } - } - // Miscelleneous instructions - if token.to_lowercase() == "end" - { - return Ok(()); + match rx.try_recv() + { + Ok(_) => + { + match tokens.get(index) { + Some(token) => { + // The instructions are related to characters + if token.chars().next().unwrap() == '@' + { + let character_name: String = token.chars().skip(1).collect(); + // If the character doesn't exist, then create it + if ! characters.contains_key(&character_name) + { + let new_character = character::Character::new(character_name.clone()); + characters.insert(character_name.clone(),new_character); + } + println!("Doing something with a character: {}", character_name); + // The index is incremented to after the character's instructions + index += match character_parse(index+1, &tokens, character_name, &mut characters, &data_to_send, &rx).await + { + Ok(increment) => { + increment + }, + Err(error) => return Err(error), + } + } + // Miscelleneous instructions + if token.to_lowercase() == "end" + { + return Ok(()) // quit + } + }, + None => return Err(String::from("File reached termination point")), } index += 1; }, - None => return Err("File reached termination point") + Err(_) => thread::sleep(Duration::from_millis(4000)), } } } - // Parsing character related instructions -fn character_parse(index: usize, tokens: &Vec<&str>, character_name: String, characters: &mut HashMap::) -> -( Result ) +async fn character_parse +( + index: usize, + tokens: &Vec<&str>, + character_name: String, + characters: &mut HashMap::, + data_to_send: &Arc>, + rx: &Receiver, +) -> Result { let mut sum_index: usize = index; loop { - - match tokens.get(sum_index) + // Ensure the index is valid (the index is not beyond the vector) + let _ = match tokens.get(sum_index) { Some(token) => { match token.to_lowercase().as_str() @@ -68,18 +90,21 @@ fn character_parse(index: usize, tokens: &Vec<&str>, character_name: String, cha Some(output_string) => { println!("{}", output_string); - return Ok(sum_index - index); + let mut data = data_to_send.lock().unwrap(); + data.action_type = String::from("output"); + data.content = output_string; + data.character = character_name.clone(); }, - None => return Err("Unable to read string"), + None => return Err(String::from("Unable to read string")), } }, // Catch all condition, if the instruction is unrecognised as a // character command - &_ => return Err("Invalid command"), + _ => return Err(String::from("Invalid command")), } }, - None => return Err("File reached termination point") - } + None => return Err(String::from("File reached termination point")) + }; sum_index += 1; } }