FREEDM DGI
Public Types | Public Member Functions | Private Attributes | List of all members
freedm::broker::device::CDevice Class Reference

Defines the interface used to access physical hardware. More...

#include <CDevice.hpp>

Inheritance diagram for freedm::broker::device::CDevice:

Public Types

typedef boost::shared_ptr< CDevicePointer
 Pointer to physical device interface. More...
 

Public Member Functions

 CDevice (std::string id, DeviceInfo info, IAdapter::Pointer adapter)
 Constructs a device with a specific structure and adapter. More...
 
std::set< std::string > GetCommandSet () const
 Gets the set of command signals recognized by the device. More...
 
std::string GetID () const
 Gets the unique identifier for this device. More...
 
SignalValue GetState (std::string signal) const
 Gets the current state of some signal from the adapter. More...
 
std::set< std::string > GetStateSet () const
 Gets the set of state signals recognized by the device. More...
 
bool HasCommand (std::string signal) const
 Checks if the device recognizes a command signal. More...
 
bool HasState (std::string signal) const
 Checks if the device recognizes a state signal. More...
 
bool HasType (std::string type) const
 Checks if the device recognizes a type. More...
 
void SetCommand (std::string signal, SignalValue value)
 Sets the next command for some signal in the adapter. More...
 

Private Attributes

IAdapter::Pointer m_adapter
 Adapter that handles the storage for this device. More...
 
std::string m_devid
 Unique identifier for this device. More...
 
DeviceInfo m_devinfo
 Internal structure of this device. More...
 

Detailed Description

The CDevice class provides the universal interface for how modules in the DGI interact with physical hardware. Each device object has an internal DeviceInfo structure that specifies which types, states, and commands the device object recognizes. If the device object tries to access a state or command not defined by its structure, it will throw a runtime exception. The device structure must be defined when a device object is created and cannot be changed after construction.

The storage for devices is handled by a separate IAdapter member variable. A device object queries its associated adapter each time it needs to read a state variable or update a command value. An adapter must be defined at device construction and cannot be changed later.

Limitations:
None.

Member Typedef Documentation

Constructor & Destructor Documentation

freedm::broker::device::CDevice::CDevice ( std::string  id,
DeviceInfo  info,
IAdapter::Pointer  adapter 
)

Constructor for device objects.

Precondition:
The adapter must be configured to store the new device object.
Postcondition:
Constructs a device object.
Parameters
idThe unique identifier for this device object.
infoThe structure that defines the type of this device object.
adapterThe adapter that handles storage for this device object.
Limitations:
None.

Member Function Documentation

std::set< std::string > freedm::broker::device::CDevice::GetCommandSet ( ) const

Accessor for the set of recognized command signals.

Precondition:
None.
Postcondition:
Returns m_devinfo.s_command.
Returns
The set of recognized command signals.
Limitations:
None.
std::string freedm::broker::device::CDevice::GetID ( ) const

Accessor for the unique device identifier.

Precondition:
None.
Postcondition:
Returns m_devid.
Returns
The unique device identifier.
Limitations:
None.
SignalValue freedm::broker::device::CDevice::GetState ( std::string  signal) const

Gets the value of a device state from the adapter.

Error Handling:
Throws a std::runtime_error if CDevice::HasState returns false for the passed string identifier.
Precondition:
The device must recognize the passed signal.
Postcondition:
m_adapter is queried for the value of the passed signal.
Parameters
signalThe string identifier for the state signal to retrieve.
Returns
The current value of the specified state signal.
Limitations:
This function can still fail even if CDevice::HasState returns true. This case happens when m_adapter is not configured to store all the data required for this device.
std::set< std::string > freedm::broker::device::CDevice::GetStateSet ( ) const

Accessor for the set of recognized state signals.

Precondition:
None.
Postcondition:
Returns m_devinfo.s_state.
Returns
The set of recognized state signals.
Limitations:
None.
bool freedm::broker::device::CDevice::HasCommand ( std::string  signal) const

Checks if the device has some specified command.

Precondition:
None.
Postcondition:
Returns true if m_devinfo.s_command contains the passed value.
Parameters
signalThe string identifier of some command signal.
Returns
True if this device has the specified command.
Limitations:
None.
bool freedm::broker::device::CDevice::HasState ( std::string  signal) const

Checks if the device has some specified state.

Precondition:
None.
Postcondition:
Returns true if m_devinfo.s_state contains the passed value.
Parameters
signalThe string identifier of some state signal.
Returns
True if this device has the specified state.
Limitations:
None.
bool freedm::broker::device::CDevice::HasType ( std::string  type) const

Checks if the device can be used as a specific type.

Precondition:
None.
Postcondition:
Returns true if m_devinfo.s_type contains the passed value.
Parameters
typeThe string identifier of some device type.
Returns
True if this device can be used as the specified type.
Limitations:
None.
void freedm::broker::device::CDevice::SetCommand ( std::string  signal,
SignalValue  value 
)

Sets the value of a device command in the adapter.

Error Handling:
Throws a std::runtime_error if CDevice::HasCommand returns false for the passed string identifier.
Precondition:
The device must recognize the passed signal.
Postcondition:
m_adapter is queried to set the value of the passed signal.
Parameters
signalThe string identifier for the command signal to set.
valueThe value to set for the command signal.
Limitations:
This function can fail even if CDevice::HasCommand returns true. This case happens when m_adapter is not configured to store all the data required for this device.

Member Data Documentation

IAdapter::Pointer freedm::broker::device::CDevice::m_adapter
private
std::string freedm::broker::device::CDevice::m_devid
private
DeviceInfo freedm::broker::device::CDevice::m_devinfo
private

The documentation for this class was generated from the following files: