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

The interface between broker modules and the device architecture. More...

#include <CDeviceManager.hpp>

Inheritance diagram for freedm::broker::device::CDeviceManager:

Public Member Functions

std::size_t DeviceCount () const
 Counts the number of managed devices. More...
 
bool DeviceExists (std::string devid) const
 Tests to see if a device exists. More...
 
CDevice::Pointer GetDevice (std::string devid)
 Gets a device by its identifier. More...
 
std::set< CDevice::PointerGetDevicesOfType (std::string type)
 Retrieves all the stored devices of a specified type. More...
 
SignalValue GetNetValue (std::string type, std::string signal)
 Returns the result of a binary operation on a set of device signals. More...
 
std::multiset< SignalValueGetValues (std::string type, std::string signal)
 Retrieves a multiset of stored values for the given device signal. More...
 

Static Public Member Functions

static CDeviceManagerInstance ()
 Gets the instance of the device manager. More...
 

Private Types

typedef PhysicalDeviceSet::const_iterator const_iterator
 A typedef providing a const iterator for this object. More...
 
typedef PhysicalDeviceSet::iterator iterator
 A typedef providing an iterator for this object. More...
 
typedef std::map< std::string, CDevice::PointerPhysicalDeviceSet
 A typedef for the mapping of identifier to device pointers. More...
 

Private Member Functions

 CDeviceManager ()
 Private constructor. More...
 
void AddDevice (CDevice::Pointer device)
 Add a pointer to the hidden device set. More...
 
bool RemoveDevice (std::string devid)
 Remove a device by its identifier. More...
 
void RevealDevice (std::string devid)
 Move a pointer to the visible device set. More...
 

Private Attributes

PhysicalDeviceSet m_devices
 Mapping from identifiers to device pointers. More...
 
PhysicalDeviceSet m_hidden_devices
 Set of uninitialized device objects. More...
 
boost::shared_mutex m_mutex
 Mutex for the device map. More...
 

Friends

class CAdapterFactory
 CAdapterFactory can add/remove devices. More...
 
class CMqttAdapter
 CMqttAdapter can add/remove PnP devices. More...
 
class IAdapter
 IAdapter can reveal devices. More...
 

Detailed Description

CDeviceManager is a singleton class used by broker modules to interface with the device architecture. This class is used to access devices attached to the DGI.

Devices are "stored" here after they are constructed by CAdapterFactory.

Limitations:
None directly, but be aware of the important limitations specificed in the IDevice class.

Member Typedef Documentation

typedef PhysicalDeviceSet::const_iterator freedm::broker::device::CDeviceManager::const_iterator
private
typedef PhysicalDeviceSet::iterator freedm::broker::device::CDeviceManager::iterator
private

Constructor & Destructor Documentation

freedm::broker::device::CDeviceManager::CDeviceManager ( )
private

Constructor for the device manager

Precondition:
None
Postcondition:
DeviceManager is ready to accept & distribute devices.
Limitations:
None.

Member Function Documentation

void freedm::broker::device::CDeviceManager::AddDevice ( CDevice::Pointer  device)
private

Registers a device with the physical device manager.

Error Handling:
Throws a std::runtime_error of another device has been registered with the same device identifier.
Shared Memory Blocks:
Stores a shared pointer to the given device.
Precondition:
There must not be a device registered with the same identifier.
Postcondition:
The device is stored in the device set m_devices.
Parameters
deviceThe device pointer to store in the manager.
Limitations:
None.
std::size_t freedm::broker::device::CDeviceManager::DeviceCount ( ) const

Returns a count of the number of devices stored by the device manager.

Precondition:
None
Postcondition:
Returns the size of m_devices.
Returns
The number of devices currently stored.
Limitations:
None.
bool freedm::broker::device::CDeviceManager::DeviceExists ( std::string  devid) const

Tests to see if the device exists in the devices manager.

Precondition:
None
Postcondition:
Searches m_device for the device.
Parameters
devidThe identifier of the device to find.
Returns
True if the device is in the device manager, false otherwise
Limitations:
None.
CDevice::Pointer freedm::broker::device::CDeviceManager::GetDevice ( std::string  devid)

Returns a shared pointer to the requested device.

Error Handling:
Will output a warning if the device cannot be found.
Precondition:
The device must be stored in the device manager.
Postcondition:
Searches m_devices for a device with the passed identifier.
Parameters
devidthe ID of the device to get.
Returns
A shared pointer to the device, or NULL if it wasn't found.
Limitations:
We cannot implement a const version of this function unless we provide a boost::shared_ptr<const DeviceType> typedef for each device class. The previous implementation of const IDevice::Pointer was incorrect because the syntax made the pointer, not the shared object, constant.
std::set< CDevice::Pointer > freedm::broker::device::CDeviceManager::GetDevicesOfType ( std::string  type)

Creates a set that contains the stored devices of the given type.

Precondition:
None.
Postcondition:
Places each device that recognizes the type in the result set.
Parameters
typeThe string identifier for the type of device to retrieve.
Returns
A set that contains the matching subset of m_devices.
Limitations:
None.
SignalValue freedm::broker::device::CDeviceManager::GetNetValue ( std::string  type,
std::string  signal 
)

Aggregates a set of device signals using the given binary operation.

Precondition:
The devices of the specified type must recognize the given signal.
Postcondition:
Performs a binary mathematical operation on a subset of m_devices.
Parameters
typeThe device type that should perform the operation.
signalThe signal of the device to aggregate.
Returns
The aggregate value obtained by applying the binary operation.
Limitations:
None.
std::multiset< SignalValue > freedm::broker::device::CDeviceManager::GetValues ( std::string  type,
std::string  signal 
)

Retrieves a multiset of values for the specified device signal.

Precondition:
The signal must be recognized by the specified device.
Postcondition:
Iterates through the devices collecting device signals.
Parameters
typeThe type of the device to collect signals from.
signalThe signal of the device to collect.
Returns
A multiset of values that contains each matching device signal.
Limitations:
None.
CDeviceManager & freedm::broker::device::CDeviceManager::Instance ( )
static

Retrieves the singleton device manager instance.

Precondition:
None.
Postcondition:
Creates a new device manager on the first call.
Returns
The global instance of CDeviceManager.
Limitations:
None.
bool freedm::broker::device::CDeviceManager::RemoveDevice ( std::string  devid)
private

Removes a device from the manager.

Error Handling:
Will output a warning if the device cannot be found.
Precondition:
None.
Postcondition:
The device with the matching identifier is removed from m_devices.
Parameters
devidThe identifier of the device to remove.
Returns
True if a device has been removed, false otherwise.
Limitations:
None.
void freedm::broker::device::CDeviceManager::RevealDevice ( std::string  devid)
private

Reveals a hidden device.

Error Handling:
Throws a std::runtime_error if no such device exists.
Precondition:
m_hidden_devices stores the passed identifier.
Postcondition:
Moves a pointer from m_hidden_devices into m_devices.
Parameters
devidThe identifier of the device pointer to move.
Limitations:
None.

Friends And Related Function Documentation

friend class CAdapterFactory
friend
friend class CMqttAdapter
friend
friend class IAdapter
friend

Member Data Documentation

PhysicalDeviceSet freedm::broker::device::CDeviceManager::m_devices
private
PhysicalDeviceSet freedm::broker::device::CDeviceManager::m_hidden_devices
private
boost::shared_mutex freedm::broker::device::CDeviceManager::m_mutex
mutableprivate

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