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

Handles construction of all device objects used by the DGI. More...

#include <CDeviceBuilder.hpp>

Classes

struct  BuildVars
 Stores the variables required to populate the device information map. More...
 

Public Member Functions

 CDeviceBuilder ()
 Default constructor. More...
 
 CDeviceBuilder (std::string filename)
 Constructor that populates the device information using an XML file. More...
 
CDevice::Pointer CreateDevice (std::string id, std::string type, IAdapter::Pointer adapter)
 Builds and returns a shared pointer to a new device object. More...
 
DeviceInfo GetDeviceInfo (std::string type)
 Accessor that returns the device information for a device type. More...
 

Private Member Functions

void ExpandInfo (std::string target, std::set< std::string > path, BuildVars &vars)
 Recursive function to populate the device information map. More...
 

Private Attributes

std::map< std::string, DeviceInfom_type_to_info
 Map from device type to its associated device information. More...
 

Detailed Description

The device builder class handles the assignment of device type information to new device objects. It stores a map of device types and their associated DeviceInfo structures that is populated when the builder is constructed. Each new device receives a copy of some DeviceInfo stored by the builder which restricts how the device can be used by the DGI.

Limitations:
None.

Constructor & Destructor Documentation

freedm::broker::device::CDeviceBuilder::CDeviceBuilder ( )
inline
freedm::broker::device::CDeviceBuilder::CDeviceBuilder ( std::string  filename)

The CDeviceBuilder constructor populates the m_type_to_info variable using data read from the passed XML file. Each device specification in the XML is converted to a DeviceInfo structure that is stored in m_type_to_info. Then the ExpandInfo member function is called on each type.

Error Handling:
Throws a std::runtime_error if there is a problem with the XML specification.
Precondition:
None.
Postcondition:
Calls ExpandInfo once for each device type read from the XML.
Parameters
filenameThe name of the XML file for the device specification.
Limitations:
None.

Member Function Documentation

CDevice::Pointer freedm::broker::device::CDeviceBuilder::CreateDevice ( std::string  id,
std::string  type,
IAdapter::Pointer  adapter 
)

Creates a new device object with the device information for the given type.

Error Handling:
Throws a std::exception if the builder does not recognize the specified device type.
Precondition:
The passed type must be a valid key for the m_type_to_info map.
Postcondition:
Creates a new CDevice instance and returns a shared pointer to it.
Parameters
idThe unique identifier for the new device.
typeThe device type to assign to the new device.
adapterThe adapter that handles data for the new device.
Returns
A shared pointer to the new device instance.
Limitations:
None.
void freedm::broker::device::CDeviceBuilder::ExpandInfo ( std::string  target,
std::set< std::string >  path,
BuildVars vars 
)
private

Generates and stores device information for a target over a series of recursive calls. This function should always be called with an empty set for the path variable.

Error Handling:
Throws a std::runtime_error if the specification file has either a cyclic extend or duplicate signal names.
Precondition:
path must be empty for the initial call to the recursive function.
Postcondition:
Device information is assigned to m_type_to_info[target].
Postcondition:
Makes a recursive call to each device type the target extends from.
Parameters
targetThe device type to construct device information for.
pathAn empty set that will be populated over recursive calls.
varsThe build variables used during construction of the builder.
Limitations:
None.
DeviceInfo freedm::broker::device::CDeviceBuilder::GetDeviceInfo ( std::string  type)

Gets the device information structure for some device type.

Error Handling:
Throws a std::out_of_range exception if the builder does not recognize the specified device type.
Precondition:
The passed string must be a valid key for the m_type_to_info map.
Postcondition:
Returns the device information structure mapped to the passed string.
Parameters
typeThe string identifier for a device type.
Returns
m_type_to_info[type]
Limitations:
None.

Member Data Documentation

std::map<std::string, DeviceInfo> freedm::broker::device::CDeviceBuilder::m_type_to_info
private

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