mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-27 09:04:55 +01:00
Implement first draft of raw write serverside
This commit is contained in:
parent
946a08c19c
commit
b8092e9090
@ -173,12 +173,16 @@ impl InUseServer for Machine {
|
||||
|
||||
fn send_raw_data(
|
||||
&mut self,
|
||||
_: inuse::SendRawDataParams,
|
||||
mut params: inuse::SendRawDataParams,
|
||||
_: inuse::SendRawDataResults,
|
||||
) -> Promise<(), ::capnp::Error> {
|
||||
Promise::err(::capnp::Error::unimplemented(
|
||||
"method not implemented".to_string(),
|
||||
))
|
||||
let data: Vec<u8> = pry!(pry!(params.get()).get_data()).to_vec();
|
||||
let resource = self.resource.clone();
|
||||
let session = self.session.clone();
|
||||
Promise::from_future(async move {
|
||||
resource.send_raw(data).await;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ use crate::config::MachineDescription;
|
||||
use crate::db::ArchivedValue;
|
||||
use crate::resources::modules::fabaccess::{ArchivedStatus, MachineState, Status};
|
||||
use crate::resources::state::db::StateDB;
|
||||
use crate::resources::state::State;
|
||||
use crate::resources::state::{ArchivedState, State};
|
||||
use crate::session::SessionHandle;
|
||||
use crate::users::UserRef;
|
||||
use rkyv::option::ArchivedOption;
|
||||
@ -161,7 +161,7 @@ impl Resource {
|
||||
|
||||
fn set_state(&self, state: MachineState) {
|
||||
let mut serializer = AllocSerializer::<1024>::default();
|
||||
serializer.serialize_value(&state);
|
||||
let _ = serializer.serialize_value(&State::new(state));
|
||||
let archived = ArchivedValue::new(serializer.into_serializer().into_inner());
|
||||
self.inner.set_state(archived)
|
||||
}
|
||||
@ -177,6 +177,24 @@ impl Resource {
|
||||
self.set_state(new);
|
||||
}
|
||||
|
||||
pub async fn send_raw(&self, data: Vec<u8>) {
|
||||
let mut serializer = AllocSerializer::<1024>::default();
|
||||
let old_state_ref = self.inner.get_state_ref();
|
||||
let old_state: &ArchivedState = old_state_ref.as_ref();
|
||||
let m_state: MachineState =
|
||||
match Deserialize::<MachineState, _>::deserialize(&old_state.inner, &mut serializer) {
|
||||
Ok(s) => s,
|
||||
Err(error) => {
|
||||
tracing::error!(?error, "failed to deserialize stored state!");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let _ = serializer.serialize_value(&State::with_raw(m_state, data));
|
||||
let archived = ArchivedValue::new(serializer.into_serializer().into_inner());
|
||||
self.inner.set_state(archived);
|
||||
}
|
||||
|
||||
pub async fn try_update(&self, session: SessionHandle, new: Status) {
|
||||
let old = self.get_state();
|
||||
let old: &Archived<State> = old.as_ref();
|
||||
|
@ -88,9 +88,7 @@ impl MachineState {
|
||||
Deserialize::deserialize(state, &mut Infallible).unwrap()
|
||||
}
|
||||
pub fn to_state(&self) -> State {
|
||||
State {
|
||||
inner: self.clone(),
|
||||
}
|
||||
State::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn free(previous: Option<UserRef>) -> Self {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::{fmt, hash::Hasher};
|
||||
use std::fmt;
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -20,6 +19,16 @@ pub mod value;
|
||||
#[archive_attr(derive(Debug))]
|
||||
pub struct State {
|
||||
pub inner: MachineState,
|
||||
pub raw: Vec<u8>,
|
||||
}
|
||||
impl State {
|
||||
pub fn new(inner: MachineState) -> Self {
|
||||
Self::with_raw(inner, Vec::new())
|
||||
}
|
||||
|
||||
pub fn with_raw(inner: MachineState, raw: Vec<u8>) -> Self {
|
||||
Self { inner, raw }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
@ -34,8 +43,8 @@ impl fmt::Debug for State {
|
||||
}
|
||||
|
||||
impl fmt::Display for ArchivedState {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
Display::fmt(&self.inner, f)
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +71,7 @@ struct StateVisitor;
|
||||
impl<'de> serde::de::Visitor<'de> for StateVisitor {
|
||||
type Value = State;
|
||||
|
||||
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a map from OIDs to value objects")
|
||||
}
|
||||
|
||||
@ -75,7 +84,7 @@ impl<'de> serde::de::Visitor<'de> for StateVisitor {
|
||||
));
|
||||
}
|
||||
let val: MachineState = map.next_value()?;
|
||||
Ok(State { inner: val })
|
||||
Ok(State { inner: val, raw: Vec::new() })
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user