mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
No more priority pls
This commit is contained in:
parent
53564b6bca
commit
cda947a0e9
@ -6,7 +6,10 @@
|
|||||||
, initiators =
|
, initiators =
|
||||||
{ Initiator = { module = "Dummy", params = {=} }
|
{ Initiator = { module = "Dummy", params = {=} }
|
||||||
}
|
}
|
||||||
, listens = [{ address = "localhost", port = Some 59661 }]
|
, listens =
|
||||||
|
[ { address = "127.0.0.1", port = Some 59661 }
|
||||||
|
, { address = "::1", port = Some 59661 }
|
||||||
|
]
|
||||||
, machines =
|
, machines =
|
||||||
{ Testmachine =
|
{ Testmachine =
|
||||||
{ description = Some "A test machine"
|
{ description = Some "A test machine"
|
||||||
|
@ -8,7 +8,7 @@ use crate::schema::api_capnp::State;
|
|||||||
use crate::schema::api_capnp::machine::*;
|
use crate::schema::api_capnp::machine::*;
|
||||||
use crate::connection::Session;
|
use crate::connection::Session;
|
||||||
use crate::db::Databases;
|
use crate::db::Databases;
|
||||||
use crate::db::machine::Status;
|
use crate::db::machine::{Status, MachineState};
|
||||||
use crate::machine::Machine as NwMachine;
|
use crate::machine::Machine as NwMachine;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -45,16 +45,16 @@ impl Machine {
|
|||||||
Status::Disabled => {
|
Status::Disabled => {
|
||||||
builder.set_state(State::Disabled);
|
builder.set_state(State::Disabled);
|
||||||
}
|
}
|
||||||
Status::Blocked(_,_) => {
|
Status::Blocked(_) => {
|
||||||
builder.set_state(State::Blocked);
|
builder.set_state(State::Blocked);
|
||||||
}
|
}
|
||||||
Status::InUse(_,_) => {
|
Status::InUse(_) => {
|
||||||
builder.set_state(State::InUse);
|
builder.set_state(State::InUse);
|
||||||
}
|
}
|
||||||
Status::ToCheck(_,_) => {
|
Status::ToCheck(_) => {
|
||||||
builder.set_state(State::ToCheck);
|
builder.set_state(State::ToCheck);
|
||||||
}
|
}
|
||||||
Status::Reserved(_,_) => {
|
Status::Reserved(_) => {
|
||||||
builder.set_state(State::Reserved);
|
builder.set_state(State::Reserved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +80,23 @@ struct Write(Arc<Machine>);
|
|||||||
impl write::Server for Write {
|
impl write::Server for Write {
|
||||||
fn use_(&mut self,
|
fn use_(&mut self,
|
||||||
_params: write::UseParams,
|
_params: write::UseParams,
|
||||||
_results: write::UseResults)
|
results: write::UseResults)
|
||||||
|
-> Promise<(), Error>
|
||||||
|
{
|
||||||
|
let uid = self.0.session.user.as_ref().map(|u| u.id.clone());
|
||||||
|
let new_state = MachineState::used(uid.clone());
|
||||||
|
if let Ok(tok) = self.0.machine.request_state_change(self.0.session.user.as_ref(), new_state) {
|
||||||
|
info!(self.0.session.log, "yay");
|
||||||
|
} else {
|
||||||
|
info!(self.0.session.log, "nay");
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise::ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reserve(&mut self,
|
||||||
|
_params: write::ReserveParams,
|
||||||
|
_results: write::ReserveResults)
|
||||||
-> Promise<(), Error>
|
-> Promise<(), Error>
|
||||||
{
|
{
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -26,8 +26,8 @@ use crate::network::Network;
|
|||||||
pub struct Session {
|
pub struct Session {
|
||||||
// Session-spezific log
|
// Session-spezific log
|
||||||
pub log: Logger,
|
pub log: Logger,
|
||||||
user: Option<User>,
|
pub user: Option<User>,
|
||||||
accessdb: Arc<AccessControl>,
|
pub accessdb: Arc<AccessControl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
|
@ -43,15 +43,15 @@ pub enum Status {
|
|||||||
/// Not currently used by anybody
|
/// Not currently used by anybody
|
||||||
Free,
|
Free,
|
||||||
/// Used by somebody
|
/// Used by somebody
|
||||||
InUse(UserId, Priority),
|
InUse(Option<UserId>),
|
||||||
/// Was used by somebody and now needs to be checked for cleanliness
|
/// Was used by somebody and now needs to be checked for cleanliness
|
||||||
ToCheck(UserId, Priority),
|
ToCheck(UserId),
|
||||||
/// Not used by anybody but also can not be used. E.g. down for maintenance
|
/// Not used by anybody but also can not be used. E.g. down for maintenance
|
||||||
Blocked(UserId, Priority),
|
Blocked(UserId),
|
||||||
/// Disabled for some other reason
|
/// Disabled for some other reason
|
||||||
Disabled,
|
Disabled,
|
||||||
/// Reserved
|
/// Reserved
|
||||||
Reserved(UserId, Priority),
|
Reserved(UserId),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uuid_from_api(uuid: crate::schema::api_capnp::u_u_i_d::Reader) -> Uuid {
|
pub fn uuid_from_api(uuid: crate::schema::api_capnp::u_u_i_d::Reader) -> Uuid {
|
||||||
@ -83,24 +83,8 @@ impl MachineState {
|
|||||||
Self { state: Status::Free }
|
Self { state: Status::Free }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn used(uid: UserId, priority: Priority) -> Self {
|
pub fn used(uid: Option<UserId>) -> Self {
|
||||||
Self { state: Status::InUse(uid, priority) }
|
Self { state: Status::InUse(uid) }
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the given priority is higher than one's own.
|
|
||||||
///
|
|
||||||
/// If `self` does not have a priority then this function always returns `true`
|
|
||||||
pub fn is_higher_priority(&self, priority: u64) -> bool {
|
|
||||||
match self.state {
|
|
||||||
Status::Disabled | Status::Free => { true },
|
|
||||||
Status::Blocked(_, self_prio) |
|
|
||||||
Status::InUse(_, self_prio) |
|
|
||||||
Status::ToCheck(_, self_prio) |
|
|
||||||
Status::Reserved(_, self_prio) =>
|
|
||||||
{
|
|
||||||
priority > self_prio
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,9 +157,8 @@ impl Sensor for Dummy {
|
|||||||
UserId::new("test".to_string(), None, None),
|
UserId::new("test".to_string(), None, None),
|
||||||
UserData::new(vec![], 0),
|
UserData::new(vec![], 0),
|
||||||
);
|
);
|
||||||
let p = user.data.priority;
|
|
||||||
let id = user.id.clone();
|
let id = user.id.clone();
|
||||||
return (Some(user), MachineState::used(id, p));
|
return (Some(user), MachineState::used(Some(id)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,9 +154,8 @@ impl Inner {
|
|||||||
return self.do_state_change(new_state);
|
return self.do_state_change(new_state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if self.state.lock_ref().is_higher_priority(who.unwrap().data.priority) {
|
// TODO: Correctly check permissions here
|
||||||
return self.do_state_change(new_state);
|
return self.do_state_change(new_state);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err(Error::Denied);
|
return Err(Error::Denied);
|
||||||
|
@ -195,8 +195,10 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
|||||||
// when bffh should exit
|
// when bffh should exit
|
||||||
let r = server::serve_api_connections(log.clone(), config, db, network);
|
let r = server::serve_api_connections(log.clone(), config, db, network);
|
||||||
|
|
||||||
|
// One of them would be enough really, but *shrug*
|
||||||
signal.try_send(());
|
signal.try_send(());
|
||||||
std::mem::drop(signal);
|
std::mem::drop(signal);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ impl Actuator for Shelly {
|
|||||||
info!(self.log, "Machine Status changed: {:?}", state);
|
info!(self.log, "Machine Status changed: {:?}", state);
|
||||||
let topic = format!("shellies/{}/relay/0/command", self.name);
|
let topic = format!("shellies/{}/relay/0/command", self.name);
|
||||||
let pl = match state.state {
|
let pl = match state.state {
|
||||||
Status::InUse(_, _) => "on",
|
Status::InUse(_) => "on",
|
||||||
_ => "off",
|
_ => "off",
|
||||||
};
|
};
|
||||||
let msg = mqtt::Message::new(topic, pl, 0);
|
let msg = mqtt::Message::new(topic, pl, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user