FREEDM DGI
CDeviceManager.hpp
Go to the documentation of this file.
1 
25 #ifndef C_DEVICE_MANAGER_HPP
26 #define C_DEVICE_MANAGER_HPP
27 
28 #include "CDevice.hpp"
29 
30 #include <map>
31 #include <set>
32 #include <string>
33 
34 #include <boost/noncopyable.hpp>
35 #include <boost/thread/shared_mutex.hpp>
36 
37 namespace freedm {
38 namespace broker {
39 namespace device {
40 
53  : private boost::noncopyable
54 {
55 public:
57  static CDeviceManager & Instance();
58 
60  std::size_t DeviceCount() const;
61 
63  bool DeviceExists(std::string devid) const;
64 
66  CDevice::Pointer GetDevice(std::string devid);
67 
69  std::set<CDevice::Pointer> GetDevicesOfType(std::string type);
70 
72  std::multiset<SignalValue> GetValues(std::string type,
73  std::string signal);
74 
76  SignalValue GetNetValue(std::string type, std::string signal);
77 
78 private:
80  typedef std::map<std::string, CDevice::Pointer> PhysicalDeviceSet;
81 
83  typedef PhysicalDeviceSet::const_iterator const_iterator;
84 
86  typedef PhysicalDeviceSet::iterator iterator;
87 
89  friend class CAdapterFactory;
90 
92  friend class CMqttAdapter;
93 
95  friend class IAdapter;
96 
99 
101  void AddDevice(CDevice::Pointer device);
102 
104  void RevealDevice(std::string devid);
105 
107  bool RemoveDevice(std::string devid);
108 
110  PhysicalDeviceSet m_devices;
111 
113  PhysicalDeviceSet m_hidden_devices;
114 
116  mutable boost::shared_mutex m_mutex;
117 };
118 
119 } // namespace device
120 } // namespace broker
121 } // namespace freedm
122 
123 #endif // C_DEVICE_MANAGER_HPP
Physical adapter device interface.
Definition: IAdapter.hpp:67
The interface between broker modules and the device architecture.
Definition: CDeviceManager.hpp:52
boost::shared_mutex m_mutex
Mutex for the device map.
Definition: CDeviceManager.hpp:116
bool DeviceExists(std::string devid) const
Tests to see if a device exists.
Definition: CDeviceManager.cpp:175
PhysicalDeviceSet::const_iterator const_iterator
A typedef providing a const iterator for this object.
Definition: CDeviceManager.hpp:83
CDevice::Pointer GetDevice(std::string devid)
Gets a device by its identifier.
Definition: CDeviceManager.cpp:196
void RevealDevice(std::string devid)
Move a pointer to the visible device set.
Definition: CDeviceManager.cpp:122
std::size_t DeviceCount() const
Counts the number of managed devices.
Definition: CDeviceManager.cpp:223
CDeviceManager()
Private constructor.
Definition: CDeviceManager.cpp:76
std::set< CDevice::Pointer > GetDevicesOfType(std::string type)
Retrieves all the stored devices of a specified type.
Definition: CDeviceManager.cpp:240
SignalValue GetNetValue(std::string type, std::string signal)
Returns the result of a binary operation on a set of device signals.
Definition: CDeviceManager.cpp:296
float SignalValue
Type of the value for device signals.
Definition: IAdapter.hpp:42
PhysicalDeviceSet m_devices
Mapping from identifiers to device pointers.
Definition: CDeviceManager.hpp:110
bool RemoveDevice(std::string devid)
Remove a device by its identifier.
Definition: CDeviceManager.cpp:150
boost::shared_ptr< CDevice > Pointer
Pointer to physical device interface.
Definition: CDevice.hpp:77
Handles the creation of adapters and their associated devices.
Definition: CAdapterFactory.hpp:54
std::map< std::string, CDevice::Pointer > PhysicalDeviceSet
A typedef for the mapping of identifier to device pointers.
Definition: CDeviceManager.hpp:80
General FREEDM Namespace.
Definition: CBroker.cpp:53
std::multiset< SignalValue > GetValues(std::string type, std::string signal)
Retrieves a multiset of stored values for the given device signal.
Definition: CDeviceManager.cpp:268
void AddDevice(CDevice::Pointer device)
Add a pointer to the hidden device set.
Definition: CDeviceManager.cpp:93
Provides an interface for communicating with an MQTT broker.
Definition: CMqttAdapter.hpp:56
PhysicalDeviceSet m_hidden_devices
Set of uninitialized device objects.
Definition: CDeviceManager.hpp:113
PhysicalDeviceSet::iterator iterator
A typedef providing an iterator for this object.
Definition: CDeviceManager.hpp:86
static CDeviceManager & Instance()
Gets the instance of the device manager.
Definition: CDeviceManager.cpp:61