From a057ffa4d82a2da36a85c8019d7ed4cb941da2ad Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Tue, 17 Nov 2020 14:15:29 +0100 Subject: [PATCH] API cleanup --- src/api.rs | 50 ++--------------------------------------- src/api/machine.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/api/machines.rs | 24 ++++++++++++++++++++ src/db/machine.rs | 4 ++-- src/machines.rs | 2 -- src/main.rs | 1 - 6 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 src/api/machine.rs create mode 100644 src/api/machines.rs delete mode 100644 src/machines.rs diff --git a/src/api.rs b/src/api.rs index 5b17596..98742e7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,48 +1,2 @@ -use std::sync::Arc; - -use slog::Logger; - -use crate::error::Result; -pub use crate::schema::api_capnp; - -use capnp::capability::Promise; -use capnp::Error; -use capnp_rpc::RpcSystem; -use capnp_rpc::twoparty::VatNetwork; -use capnp_rpc::rpc_twoparty_capnp::Side; -use capnp::capability::FromServer; - -use crate::machines::Machines; -use crate::db::user::User; - -use uuid::Uuid; - -pub struct MachinesAPI { - log: Logger, - user: User, - machines: Machines, -} - -impl MachinesAPI { - pub fn new(log: Logger, user: User, machines: Machines) -> Self { - Self { log, user, machines } - } -} - -impl api_capnp::machines::Server for MachinesAPI { - fn list_machines(&mut self, - _params: api_capnp::machines::ListMachinesParams, - mut results: api_capnp::machines::ListMachinesResults) - -> Promise<(), Error> - { - Promise::ok(()) - } - - fn get_machine(&mut self, - _params: api_capnp::machines::GetMachineParams, - mut results: api_capnp::machines::GetMachineResults) - -> Promise<(), Error> - { - Promise::ok(()) - } -} +mod machine; +mod machines; diff --git a/src/api/machine.rs b/src/api/machine.rs new file mode 100644 index 0000000..a616f85 --- /dev/null +++ b/src/api/machine.rs @@ -0,0 +1,55 @@ +use crate::schema::api_capnp::machine::*; + +use capnp::capability::Promise; +use capnp::Error; + + +struct Machine; + +impl read::Server for Machine { + fn info(&mut self, + _params: read::InfoParams, + _results: read::InfoResults) + -> Promise<(), Error> + { + unimplemented!() + } +} + +impl write::Server for Machine { + fn use_(&mut self, + _params: write::UseParams, + _results: write::UseResults) + -> Promise<(), Error> + { + unimplemented!() + } +} + +impl manage::Server for Machine { + fn ok(&mut self, + _params: manage::OkParams, + _results: manage::OkResults) + -> Promise<(), Error> + { + unimplemented!() + } +} + +impl admin::Server for Machine { + fn force_set_state(&mut self, + _params: admin::ForceSetStateParams, + _results: admin::ForceSetStateResults) + -> Promise<(), Error> + { + unimplemented!() + } + + fn force_set_user(&mut self, + _params: admin::ForceSetUserParams, + _results: admin::ForceSetUserResults) + -> Promise<(), Error> + { + unimplemented!() + } +} diff --git a/src/api/machines.rs b/src/api/machines.rs new file mode 100644 index 0000000..378941f --- /dev/null +++ b/src/api/machines.rs @@ -0,0 +1,24 @@ +use crate::schema::api_capnp::machines; + +use capnp::capability::Promise; +use capnp::Error; + +struct Machines; + +impl machines::Server for Machines { + fn list_machines(&mut self, + _params: machines::ListMachinesParams, + mut results: machines::ListMachinesResults) + -> Promise<(), Error> + { + Promise::ok(()) + } + + fn get_machine(&mut self, + _params: machines::GetMachineParams, + mut results: machines::GetMachineResults) + -> Promise<(), Error> + { + Promise::ok(()) + } +} diff --git a/src/db/machine.rs b/src/db/machine.rs index 6e95eaa..5b2d84c 100644 --- a/src/db/machine.rs +++ b/src/db/machine.rs @@ -54,13 +54,13 @@ pub enum Status { Reserved(UserIdentifier), } -fn uuid_from_api(uuid: crate::api::api_capnp::u_u_i_d::Reader) -> Uuid { +fn uuid_from_api(uuid: crate::schema::api_capnp::u_u_i_d::Reader) -> Uuid { let uuid0 = uuid.get_uuid0() as u128; let uuid1 = uuid.get_uuid1() as u128; let num: u128 = (uuid1 << 64) + uuid0; Uuid::from_u128(num) } -fn api_from_uuid(uuid: Uuid, mut wr: crate::api::api_capnp::u_u_i_d::Builder) { +fn api_from_uuid(uuid: Uuid, mut wr: crate::schema::api_capnp::u_u_i_d::Builder) { let num = uuid.to_u128_le(); let uuid0 = num as u64; let uuid1 = (num >> 64) as u64; diff --git a/src/machines.rs b/src/machines.rs deleted file mode 100644 index 774f802..0000000 --- a/src/machines.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[derive(Clone)] -pub struct Machines; diff --git a/src/main.rs b/src/main.rs index cec1ea6..8ebd526 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,6 @@ mod registries; mod schema; mod db; mod machine; -mod machines; use clap::{App, Arg};