[][src]Trait webthing::thing::Thing

pub trait Thing: Send + Sync {
    fn as_thing_description(&self) -> Map<String, Value>;
fn as_any(&self) -> &dyn Any;
fn as_mut_any(&mut self) -> &mut dyn Any;
fn get_href(&self) -> String;
fn get_href_prefix(&self) -> String;
fn get_ui_href(&self) -> Option<String>;
fn set_href_prefix(&mut self, prefix: String);
fn set_ui_href(&mut self, href: String);
fn get_id(&self) -> String;
fn get_title(&self) -> String;
fn get_context(&self) -> String;
fn get_type(&self) -> Vec<String>;
fn get_description(&self) -> String;
fn get_property_descriptions(&self) -> Map<String, Value>;
fn get_action_descriptions(&self, action_name: Option<String>) -> Value;
fn get_event_descriptions(&self, event_name: Option<String>) -> Value;
fn add_property(&mut self, property: Box<dyn Property>);
fn remove_property(&mut self, property_name: String);
fn find_property(
        &mut self,
        property_name: String
    ) -> Option<&mut Box<dyn Property>>;
fn get_property(&self, property_name: String) -> Option<Value>;
fn get_properties(&self) -> Map<String, Value>;
fn has_property(&self, property_name: String) -> bool;
fn get_action(
        &self,
        action_name: String,
        action_id: String
    ) -> Option<Arc<RwLock<Box<dyn Action>>>>;
fn add_event(&mut self, event: Box<dyn Event>);
fn add_available_event(
        &mut self,
        name: String,
        metadata: Map<String, Value>
    );
fn add_action(
        &mut self,
        action: Arc<RwLock<Box<dyn Action>>>,
        input: Option<&Value>
    ) -> Result<(), &str>;
fn remove_action(&mut self, action_name: String, action_id: String) -> bool;
fn add_available_action(
        &mut self,
        name: String,
        metadata: Map<String, Value>
    );
fn add_subscriber(&mut self, ws_id: String);
fn remove_subscriber(&mut self, ws_id: String);
fn add_event_subscriber(&mut self, name: String, ws_id: String);
fn remove_event_subscriber(&mut self, name: String, ws_id: String);
fn property_notify(&mut self, name: String, value: Value);
fn action_notify(&mut self, action: Map<String, Value>);
fn event_notify(&mut self, name: String, event: Map<String, Value>);
fn start_action(&mut self, name: String, id: String);
fn cancel_action(&mut self, name: String, id: String);
fn finish_action(&mut self, name: String, id: String);
fn drain_queue(&mut self, ws_id: String) -> Vec<Drain<String>>; fn set_property(
        &mut self,
        property_name: String,
        value: Value
    ) -> Result<(), &'static str> { ... } }

High-level Thing trait.

Required methods

fn as_thing_description(&self) -> Map<String, Value>

Return the thing state as a Thing Description.

Returns the state as a JSON map.

fn as_any(&self) -> &dyn Any

Return this thing as an Any.

fn as_mut_any(&mut self) -> &mut dyn Any

Return this thing as a mutable Any.

fn get_href(&self) -> String

Get this thing's href.

fn get_href_prefix(&self) -> String

Get this thing's href prefix, i.e. /0.

fn get_ui_href(&self) -> Option<String>

Get the UI href.

fn set_href_prefix(&mut self, prefix: String)

Set the prefix of any hrefs associated with this thing.

prefix -- the prefix

fn set_ui_href(&mut self, href: String)

Set the href of this thing's custom UI.

href -- the href

fn get_id(&self) -> String

Get the ID of the thing.

Returns the ID as a string.

fn get_title(&self) -> String

Get the title of the thing.

Returns the title as a string.

fn get_context(&self) -> String

Get the type context of the thing.

Returns the context as a string.

fn get_type(&self) -> Vec<String>

Get the type(s) of the thing.

Returns the list of types.

fn get_description(&self) -> String

Get the description of the thing.

Returns the description as a string.

fn get_property_descriptions(&self) -> Map<String, Value>

Get the thing's properties as a JSON map.

Returns the properties as a JSON map, i.e. name -> description.

fn get_action_descriptions(&self, action_name: Option<String>) -> Value

Get the thing's actions as an array.

action_name -- Optional action name to get descriptions for

Returns the action descriptions.

fn get_event_descriptions(&self, event_name: Option<String>) -> Value

Get the thing's events as an array.

event_name -- Optional event name to get descriptions for

Returns the event descriptions.

fn add_property(&mut self, property: Box<dyn Property>)

Add a property to this thing.

property -- property to add

fn remove_property(&mut self, property_name: String)

Remove a property from this thing.

property -- property to remove

fn find_property(
    &mut self,
    property_name: String
) -> Option<&mut Box<dyn Property>>

Find a property by name.

property_name -- the property to find

Returns a boxed property trait object, if found, else None.

fn get_property(&self, property_name: String) -> Option<Value>

Get a property's value.

property_name -- the property to get the value of

Returns the properties value, if found, else None.

fn get_properties(&self) -> Map<String, Value>

Get a mapping of all properties and their values.

Returns an object of propertyName -> value.

fn has_property(&self, property_name: String) -> bool

Determine whether or not this thing has a given property.

property_name -- the property to look for

Returns a boolean, indicating whether or not the thing has the property.

fn get_action(
    &self,
    action_name: String,
    action_id: String
) -> Option<Arc<RwLock<Box<dyn Action>>>>

Get an action.

action_name -- name of the action action_id -- ID of the action

Returns the requested action if found, else None.

fn add_event(&mut self, event: Box<dyn Event>)

Add a new event and notify subscribers.

event -- the event that occurred

fn add_available_event(&mut self, name: String, metadata: Map<String, Value>)

Add an available event.

name -- name of the event metadata -- event metadata, i.e. type, description, etc., as a JSON map

fn add_action(
    &mut self,
    action: Arc<RwLock<Box<dyn Action>>>,
    input: Option<&Value>
) -> Result<(), &str>

Perform an action on the thing.

action_name -- name of the action input_ -- any action inputs

Returns the action that was created.

fn remove_action(&mut self, action_name: String, action_id: String) -> bool

Remove an existing action.

action_name -- name of the action action_id -- ID of the action

Returns a boolean indicating the presence of the action.

fn add_available_action(&mut self, name: String, metadata: Map<String, Value>)

Add an available action.

name -- name of the action metadata -- action metadata, i.e. type, description, etc., as a JSON map

fn add_subscriber(&mut self, ws_id: String)

Add a new websocket subscriber.

ws_id -- ID of the websocket

fn remove_subscriber(&mut self, ws_id: String)

Remove a websocket subscriber.

ws_id -- ID of the websocket

fn add_event_subscriber(&mut self, name: String, ws_id: String)

Add a new websocket subscriber to an event.

name -- name of the event ws_id -- ID of the websocket

fn remove_event_subscriber(&mut self, name: String, ws_id: String)

Remove a websocket subscriber from an event.

name -- name of the event ws_id -- ID of the websocket

fn property_notify(&mut self, name: String, value: Value)

Notify all subscribers of a property change.

name -- name of the property that changed value -- new property value

fn action_notify(&mut self, action: Map<String, Value>)

Notify all subscribers of an action status change.

action -- JSON description the action whose status changed

fn event_notify(&mut self, name: String, event: Map<String, Value>)

Notify all subscribers of an event.

name -- name of the event that occurred event -- JSON description of the event

fn start_action(&mut self, name: String, id: String)

Start the specified action.

name -- name of the action id -- ID of the action

fn cancel_action(&mut self, name: String, id: String)

Cancel the specified action.

name -- name of the action id -- ID of the action

fn finish_action(&mut self, name: String, id: String)

Finish the specified action.

name -- name of the action id -- ID of the action

fn drain_queue(&mut self, ws_id: String) -> Vec<Drain<String>>

Drain any message queues for the specified weboscket ID.

ws_id -- ID of the websocket

Loading content...

Provided methods

fn set_property(
    &mut self,
    property_name: String,
    value: Value
) -> Result<(), &'static str>

Set a property value.

property_name -- name of the property to set value -- value to set

Loading content...

Implementors

impl Thing for BaseThing[src]

fn as_thing_description(&self) -> Map<String, Value>[src]

Return the thing state as a Thing Description.

Returns the state as a JSON map.

fn as_any(&self) -> &dyn Any[src]

Return this thing as an Any.

fn as_mut_any(&mut self) -> &mut dyn Any[src]

Return this thing as a mutable Any.

fn get_href(&self) -> String[src]

Get this thing's href.

fn get_href_prefix(&self) -> String[src]

Get this thing's href prefix, i.e. /0.

fn get_ui_href(&self) -> Option<String>[src]

Get the UI href.

fn set_href_prefix(&mut self, prefix: String)[src]

Set the prefix of any hrefs associated with this thing.

prefix -- the prefix

fn set_ui_href(&mut self, href: String)[src]

Set the href of this thing's custom UI.

href -- the href

fn get_id(&self) -> String[src]

Get the ID of the thing.

Returns the ID as a string.

fn get_title(&self) -> String[src]

Get the title of the thing.

Returns the title as a string.

fn get_context(&self) -> String[src]

Get the type context of the thing.

Returns the context as a string.

fn get_type(&self) -> Vec<String>[src]

Get the type(s) of the thing.

Returns the list of types.

fn get_description(&self) -> String[src]

Get the description of the thing.

Returns the description as a string.

fn get_property_descriptions(&self) -> Map<String, Value>[src]

Get the thing's properties as a JSON map.

Returns the properties as a JSON map, i.e. name -> description.

fn get_action_descriptions(&self, action_name: Option<String>) -> Value[src]

Get the thing's actions as an array.

action_name -- Optional action name to get descriptions for

Returns the action descriptions.

fn get_event_descriptions(&self, event_name: Option<String>) -> Value[src]

Get the thing's events as an array.

event_name -- Optional event name to get descriptions for

Returns the event descriptions.

fn add_property(&mut self, property: Box<dyn Property>)[src]

Add a property to this thing.

property -- property to add

fn remove_property(&mut self, property_name: String)[src]

Remove a property from this thing.

property -- property to remove

fn find_property(
    &mut self,
    property_name: String
) -> Option<&mut Box<dyn Property>>
[src]

Find a property by name.

property_name -- the property to find

Returns a boxed property trait object, if found, else None.

fn get_property(&self, property_name: String) -> Option<Value>[src]

Get a property's value.

property_name -- the property to get the value of

Returns the properties value, if found, else None.

fn get_properties(&self) -> Map<String, Value>[src]

Get a mapping of all properties and their values.

Returns an object of propertyName -> value.

fn has_property(&self, property_name: String) -> bool[src]

Determine whether or not this thing has a given property.

property_name -- the property to look for

Returns a boolean, indicating whether or not the thing has the property.

fn get_action(
    &self,
    action_name: String,
    action_id: String
) -> Option<Arc<RwLock<Box<dyn Action>>>>
[src]

Get an action.

action_name -- name of the action action_id -- ID of the action

Returns the requested action if found, else None.

fn add_event(&mut self, event: Box<dyn Event>)[src]

Add a new event and notify subscribers.

event -- the event that occurred

fn add_available_event(&mut self, name: String, metadata: Map<String, Value>)[src]

Add an available event.

name -- name of the event metadata -- event metadata, i.e. type, description, etc., as a JSON map

fn add_action(
    &mut self,
    action: Arc<RwLock<Box<dyn Action>>>,
    input: Option<&Value>
) -> Result<(), &str>
[src]

Perform an action on the thing.

action_name -- name of the action input_ -- any action inputs

Returns the action that was created.

fn remove_action(&mut self, action_name: String, action_id: String) -> bool[src]

Remove an existing action.

action_name -- name of the action action_id -- ID of the action

Returns a boolean indicating the presence of the action.

fn add_available_action(&mut self, name: String, metadata: Map<String, Value>)[src]

Add an available action.

name -- name of the action metadata -- action metadata, i.e. type, description, etc., as a JSON map

fn add_subscriber(&mut self, ws_id: String)[src]

Add a new websocket subscriber.

ws_id -- ID of the websocket

fn remove_subscriber(&mut self, ws_id: String)[src]

Remove a websocket subscriber.

ws_id -- ID of the websocket

fn add_event_subscriber(&mut self, name: String, ws_id: String)[src]

Add a new websocket subscriber to an event.

name -- name of the event ws_id -- ID of the websocket

fn remove_event_subscriber(&mut self, name: String, ws_id: String)[src]

Remove a websocket subscriber from an event.

name -- name of the event ws_id -- ID of the websocket

fn property_notify(&mut self, name: String, value: Value)[src]

Notify all subscribers of a property change.

name -- name of the property that changed value -- new property value

fn action_notify(&mut self, action: Map<String, Value>)[src]

Notify all subscribers of an action status change.

action -- JSON description the action whose status changed

fn event_notify(&mut self, name: String, event: Map<String, Value>)[src]

Notify all subscribers of an event.

name -- name of the event that occurred event -- JSON description of the event

fn start_action(&mut self, name: String, id: String)[src]

Start the specified action.

name -- name of the action id -- ID of the action

fn cancel_action(&mut self, name: String, id: String)[src]

Cancel the specified action.

name -- name of the action id -- ID of the action

fn finish_action(&mut self, name: String, id: String)[src]

Finish the specified action.

name -- name of the action id -- ID of the action

fn drain_queue(&mut self, ws_id: String) -> Vec<Drain<String>>[src]

Drain any message queues for the specified weboscket ID.

ws_id -- ID of the websocket

Loading content...