Trait proj_billing::billing::BillingProtocol
[−]
[src]
pub trait BillingProtocol<T: Read + Write, B> { type Consumption; type Prices; fn null_prices() -> Self::Prices; fn consume(&mut self, consumption: &Self::Consumption); fn send_billing_information(&mut self); fn pay_bill(&mut self) -> B; fn change_prices(&mut self, prices: &Self::Prices); fn new_meter(channel: T, prices: &Self::Prices, keys: MeterKeys) -> Self; fn new_server(channel: T, keys: Keys, prices: &Self::Prices) -> Self; }
Functionality which all billing protocols must provide.
The first type argument it the channel over which communication occurs. This should probably be a proj_net::{Server, Client}. The second type argument is the return value of the constructors (i.e the structure implementing this trait)
Associated Types
type Consumption
Consumption information for billing e.g. the time of consumption and the units consumed
type Prices
Information used to calculate the bill (e.g. coefficients for each in which a unit could be consumed)
Required Methods
fn null_prices() -> Self::Prices
returns a null Prices object
fn consume(&mut self, consumption: &Self::Consumption)
To be run on the meter. This function should check for any new prices, and then add the price of consumption to the running bill
fn send_billing_information(&mut self)
Get the server up to speed with the current billing information: a message from the device to the server.
fn pay_bill(&mut self) -> B
Pay bill (run on the server) This will block until it has received the billing information from the meter (via send_billing_information)
fn change_prices(&mut self, prices: &Self::Prices)
Change the way bills are calculated. This is a message sent from the server (utility company) to the meter.
fn new_meter(channel: T, prices: &Self::Prices, keys: MeterKeys) -> Self
Instantiate a new meter
fn new_server(channel: T, keys: Keys, prices: &Self::Prices) -> Self
Instantiate a new server
Implementors
impl<T: Read + Write> BillingProtocol<T, f64> for SignOnMeter<T>