From a455550d3c5e290fcc19027295e81208832bf07d Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 17 Jul 2024 13:23:56 -0300 Subject: [PATCH] src: device: Integrations required for restAPI and websocket --- src/device/manager.rs | 20 +++++++++++--------- src/main.rs | 7 ++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/device/manager.rs b/src/device/manager.rs index 9ab28134..1348a976 100644 --- a/src/device/manager.rs +++ b/src/device/manager.rs @@ -1,3 +1,4 @@ +use paperclip::actix::Apiv2Schema; use serde::{Deserialize, Serialize}; use std::{ collections::{hash_map::DefaultHasher, HashMap}, @@ -59,13 +60,13 @@ enum SourceType { Serial(SerialStream), } -#[derive(Clone, Debug, Deserialize, Serialize, Hash)] +#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)] pub struct SourceUdpStruct { pub ip: Ipv4Addr, pub port: u16, } -#[derive(Clone, Debug, Deserialize, Serialize, Hash)] +#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)] pub struct SourceSerialStruct { pub path: String, pub baudrate: u32, @@ -92,9 +93,9 @@ pub struct ManagerActorHandler { pub sender: mpsc::Sender, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, Apiv2Schema)] pub enum Answer { - Ping(PingAnswer), + DeviceMessage(DeviceAnswer), #[serde(skip)] InnerDeviceHandler(DeviceActorHandler), DeviceInfo(Vec), @@ -113,12 +114,13 @@ pub enum ManagerError { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct PingAnswer { - pub answer: Result, +pub struct DeviceAnswer { + #[serde(flatten)] + pub answer: crate::device::devices::PingAnswer, pub device_id: Uuid, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Apiv2Schema)] pub enum Request { Create(CreateStruct), Delete(Uuid), @@ -410,8 +412,8 @@ impl ManagerActorHandler { match result { Ok(result) => { info!("Handling Ping request: {request:?}: Success"); - Ok(Answer::Ping(PingAnswer { - answer: Ok(result), + Ok(Answer::DeviceMessage(DeviceAnswer { + answer: result, device_id: request.target, })) } diff --git a/src/main.rs b/src/main.rs index f6a271c7..a92bcbe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,13 +21,10 @@ async fn main() { //Todo: Load previous devices info!( "DeviceManager initialized with following devices: {:?}", - handler - .send(crate::device::manager::Request::List {}) - .await - .unwrap() + handler.send(crate::device::manager::Request::List).await ); - server::manager::run(&cli::manager::server_address()) + server::manager::run(&cli::manager::server_address(), handler) .await .unwrap(); }