52 lines
1.2 KiB
Rust
Raw Normal View History

2020-11-10 14:56:28 +01:00
use std::sync::Arc;
2020-02-14 12:20:17 +01:00
2020-02-18 16:55:19 +01:00
use slog::Logger;
2020-05-04 13:22:14 +02:00
use crate::error::Result;
2020-10-22 13:00:58 +02:00
pub use crate::schema::api_capnp;
2020-02-18 16:55:19 +01:00
use capnp::capability::Promise;
use capnp::Error;
use capnp_rpc::RpcSystem;
use capnp_rpc::twoparty::VatNetwork;
use capnp_rpc::rpc_twoparty_capnp::Side;
2020-10-22 13:00:58 +02:00
use capnp::capability::FromServer;
2020-11-10 14:56:28 +01:00
use crate::db::machine::Machines;
use crate::db::user::User;
use uuid::Uuid;
pub struct MachinesAPI {
log: Logger,
user: User,
machines: Arc<Machines>,
}
2020-11-10 14:56:28 +01:00
impl MachinesAPI {
pub fn new(log: Logger, user: User, machines: Arc<Machines>) -> Self {
Self { log, user, machines }
}
}
2020-10-22 13:00:58 +02:00
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>
{
2020-11-10 14:56:28 +01:00
let l = results.get();
let keys: Vec<api_capnp::machine::Reader> = self.machines.iter().map(|x| x.into()).collect();
l.set_machines(keys);
Promise::ok(())
}
2020-10-22 13:00:58 +02:00
fn get_machine(&mut self,
_params: api_capnp::machines::GetMachineParams,
mut results: api_capnp::machines::GetMachineResults)
-> Promise<(), Error>
{
Promise::ok(())
}
2020-02-14 12:20:17 +01:00
}