API cleanup

This commit is contained in:
Gregor Reitzenstein 2020-11-17 14:15:29 +01:00
parent 0fef683f41
commit a057ffa4d8
6 changed files with 83 additions and 53 deletions

View File

@ -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;

55
src/api/machine.rs Normal file
View File

@ -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!()
}
}

24
src/api/machines.rs Normal file
View File

@ -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(())
}
}

View File

@ -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;

View File

@ -1,2 +0,0 @@
#[derive(Clone)]
pub struct Machines;

View File

@ -18,7 +18,6 @@ mod registries;
mod schema;
mod db;
mod machine;
mod machines;
use clap::{App, Arg};