Struct sep2_client::client::Client
source · pub struct Client { /* private fields */ }
Expand description
Represents an IEEE 2030.5 Client connection to a single server
Can be cloned cheaply as poll tasks, and the underlying hyper
connection pool are shared between cloned clients.
Implementations§
source§impl Client
impl Client
sourcepub fn new(
server_addr: &str,
tcp_keepalive: Option<Duration>,
tickrate: Option<Duration>
) -> Result<Self>
pub fn new( server_addr: &str, tcp_keepalive: Option<Duration>, tickrate: Option<Duration> ) -> Result<Self>
Construct an IEEE 2030.5 Client instance that uses HTTP
TCP KeepAlive:
Pass the given value to SO_KEEPALIVE
.
Tickrate:
Set how often the client background task should wakeup to check the polling queue.
Defaults to 10 minutes, if this function is not called.
If Client::start_poll
is never called, this setting has no effect.
sourcepub fn new_https(
server_addr: &str,
cert_path: impl AsRef<Path>,
pk_path: impl AsRef<Path>,
rootca_path: impl AsRef<Path>,
tcp_keepalive: Option<Duration>,
tickrate: Option<Duration>
) -> Result<Self>
pub fn new_https( server_addr: &str, cert_path: impl AsRef<Path>, pk_path: impl AsRef<Path>, rootca_path: impl AsRef<Path>, tcp_keepalive: Option<Duration>, tickrate: Option<Duration> ) -> Result<Self>
Construct an IEEE 2030.5 Client instance that uses HTTPS
sourcepub async fn get<R: SEResource>(&self, path: &str) -> Result<R>
pub async fn get<R: SEResource>(&self, path: &str) -> Result<R>
Retrieve the SEResource
at the given relative path.
Returns an error if the resource could not be retrieved or deserialized.
sourcepub async fn post<R: SEResource>(
&self,
path: &str,
resource: &R
) -> Result<SEPResponse>
pub async fn post<R: SEResource>( &self, path: &str, resource: &R ) -> Result<SEPResponse>
Update a SEResource
at the given relative path.
Returns an error if the server does not respond with 204 No Content or 201 Created.
sourcepub async fn put<R: SEResource>(
&self,
path: &str,
resource: &R
) -> Result<SEPResponse>
pub async fn put<R: SEResource>( &self, path: &str, resource: &R ) -> Result<SEPResponse>
Create a SEResource
at the given relative path.
Returns an error if the server does not respond with 204 No Content or 201 Created.
sourcepub async fn delete(&self, path: &str) -> Result<SEPResponse>
pub async fn delete(&self, path: &str) -> Result<SEPResponse>
Delete the SEResource
at the given relative path.
Returns an error if the server does not respond with 204 No Content.
sourcepub async fn start_poll<T>(
&self,
path: impl Into<String>,
poll_rate: Option<Uint32>,
callback: impl PollCallback<T>
)where
T: SEResource,
pub async fn start_poll<T>( &self, path: impl Into<String>, poll_rate: Option<Uint32>, callback: impl PollCallback<T> )where T: SEResource,
Begin polling the given route by performing GET requests on a regular interval. Passes the returned SEResource
to the given callback.
The callback will not be run if the GET request fails, or the resource cannot be deserialized.
As per IEEE 2030.5, if a poll rate is not specified, a default of 900 seconds (15 minutes) is used.
All poll events created can be forcibly run using Client::force_polls
, such as is required when reconnecting to the server after a period of connectivity loss.
sourcepub async fn force_polls(&self)
pub async fn force_polls(&self)
Forcibly poll & run the callbacks of all routes polled using Client::start_poll
sourcepub async fn cancel_polls(&self)
pub async fn cancel_polls(&self)
Cancel all poll tasks created using Client::start_poll
pub async fn send_msg_response( &self, lfdi: HexBinary160, event: &TextMessage, status: ResponseStatus, time: SEPTime ) -> Result<SEPResponse>
messaging
only.pub async fn send_der_response( &self, lfdi: HexBinary160, event: &DERControl, status: ResponseStatus, time: SEPTime ) -> Result<SEPResponse>
der
only.pub async fn send_drlc_response( &self, device: &SEDevice, event: &EndDeviceControl, status: ResponseStatus, time: SEPTime ) -> Result<SEPResponse>
drlc
only.pub async fn send_pricing_response( &self, lfdi: HexBinary160, event: &TimeTariffInterval, status: ResponseStatus, time: SEPTime ) -> Result<SEPResponse>
pricing
only.