ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/salaryman/trunk/src/smd/endpoints.rs
Revision: 13
Committed: Wed Jul 9 20:24:36 2025 UTC (3 months ago) by yuzu
File size: 1017 byte(s)
Log Message:
working network communication

File Contents

# Content
1 use super::{
2 Config,
3 context::{SalarymanDContext, StdinBuffer},
4 };
5 use dropshot::{HttpError, HttpResponseOk, RequestContext, TypedBody, endpoint};
6 use std::sync::Arc;
7
8 #[endpoint {
9 method = GET,
10 path = "/config",
11 }]
12 pub async fn endpoint_get_config(
13 rqctx: RequestContext<Arc<SalarymanDContext>>,
14 ) -> Result<HttpResponseOk<Config>, HttpError> {
15 Ok(HttpResponseOk(rqctx.context().config.clone()))
16 }
17
18 #[endpoint {
19 method = PUT,
20 path = "/services/write"
21 }]
22 pub async fn endpoint_post_stdin(
23 rqctx: RequestContext<Arc<SalarymanDContext>>,
24 update: TypedBody<StdinBuffer>,
25 ) -> Result<HttpResponseOk<()>, HttpError> {
26 let ctx = rqctx.context();
27 let stdin_str = update.into_inner();
28 for i in 0..ctx.service.len() {
29 let mut lock = ctx.service[i].lock().await;
30 if lock.started().await {
31 lock.writeln_stdin(stdin_str.string.clone()).await.unwrap(); //TODO: PROPERLY HANDLE ERROR!
32 }
33 drop(lock);
34 }
35
36 Ok(HttpResponseOk(()))
37 }