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

Provides an interface for communicating with an MQTT broker. More...

#include <CMqttAdapter.hpp>

Inheritance diagram for freedm::broker::device::CMqttAdapter:
freedm::broker::device::IAdapter

Classes

struct  DeviceData
 

Public Types

typedef boost::shared_ptr< CMqttAdapterPointer
 Pointer to a CMqttAdapater object. More...
 

Public Member Functions

 ~CMqttAdapter ()
 Destructor. More...
 
std::set< std::string > GetDevices () const
 Get the list of registered device names. More...
 
SignalValue GetState (const std::string device, const std::string key) const
 Retrieves a value from a device. More...
 
void RegisterDevice (const std::string devid)
 Register a device name with the adapter. More...
 
void SetCommand (const std::string device, const std::string key, const SignalValue value)
 Sets a value on a device. More...
 
void Start ()
 Start the MQTT client. More...
 
void Stop ()
 Stop the MQTT client. More...
 

Static Public Member Functions

static IAdapter::Pointer Create (std::string id, std::string address)
 Create a CMqttAdapter object and return a point to it. More...
 

Protected Member Functions

void RevealDevices ()
 Reveals devices in the device manager. More...
 

Private Types

typedef std::map< std::string, DeviceDataTDeviceToData
 Map from a device name to its stored signal values. More...
 

Private Member Functions

 CMqttAdapter (std::string id, std::string address)
 Constructor. More...
 
void AddSignals (std::string device, boost::property_tree::ptree::value_type &ptree, std::set< std::string > &sigset, std::set< std::string > &type)
 
void CreateDevice (std::string deviceName, std::string json)
 Create a CDevice object from a JSON specification. More...
 
void HandleMessage (std::string topic, std::string message)
 Handles messages received from subscribed topics. More...
 
void Publish (std::string topic, std::string content)
 Publish a message on a topic to the MQTT broker. More...
 
void SubscribeAll (std::string deviceName)
 does a full Subscribe More...
 
void UnsubscribeAll (std::string deviceName)
 does a full UnSubscribe More...
 

Static Private Member Functions

static void ConnectionLost (void *id, char *reason)
 Callback function when the client cannot reach the broker. More...
 
static void DeliveryComplete (void *id, MQTTClient_deliveryToken token)
 Callback function when a message has been delivered to the broker. More...
 
static int HandleMessage (void *id, char *topic, int topicLen, MQTTClient_message *msg)
 Callback function when the client receives a message about a subscribed topic. More...
 

Private Attributes

MQTTClient m_Client
 MQTT client object. More...
 
TDeviceToData m_DeviceData
 Map of device data expected over MQTT. More...
 
boost::mutex m_DeviceDataLock
 Protect the device data map. More...
 
char m_ID [24]
 MQTT client identifier. More...
 
std::list< CMqttMessage::Pointerm_MessageQueue
 Storage for MQTT messages. More...
 
MQTTClient_message pubmsg
 
MQTTClient_deliveryToken token
 

Detailed Description

This class handles communication with physical devices through MQTT. It implements an asynchronous MQTT client that subscribes to a join channel to listen for the appearance of new plug-and-play devices. When a new device joins, the adapter subscribes to that device to receive its state changes.

Interaction Peers:
The MQTT client will communicate with the MQTT broker specified in the adapter configuration file. Through the broker, the client will send and receive data with physical devices.
Limitations:
None.

Member Typedef Documentation

typedef std::map<std::string, DeviceData> freedm::broker::device::CMqttAdapter::TDeviceToData
private

Constructor & Destructor Documentation

freedm::broker::device::CMqttAdapter::~CMqttAdapter ( )
freedm::broker::device::CMqttAdapter::CMqttAdapter ( std::string  id,
std::string  address 
)
private

Member Function Documentation

void freedm::broker::device::CMqttAdapter::AddSignals ( std::string  device,
boost::property_tree::ptree::value_type &  ptree,
std::set< std::string > &  sigset,
std::set< std::string > &  type 
)
private
void freedm::broker::device::CMqttAdapter::ConnectionLost ( void *  id,
char *  reason 
)
staticprivate
IAdapter::Pointer freedm::broker::device::CMqttAdapter::Create ( std::string  id,
std::string  address 
)
static
void freedm::broker::device::CMqttAdapter::CreateDevice ( std::string  deviceName,
std::string  json 
)
private
void freedm::broker::device::CMqttAdapter::DeliveryComplete ( void *  id,
MQTTClient_deliveryToken  token 
)
staticprivate
std::set< std::string > freedm::broker::device::IAdapter::GetDevices ( ) const
inherited

Accessor function for the registered device set.

Precondition:
None.
Postcondition:
Returns m_devices.
Returns
A set of device identifiers.
Limitations:
None.
SignalValue freedm::broker::device::CMqttAdapter::GetState ( const std::string  device,
const std::string  key 
) const
virtual
int freedm::broker::device::CMqttAdapter::HandleMessage ( void *  id,
char *  topic,
int  topicLen,
MQTTClient_message *  msg 
)
staticprivate
void freedm::broker::device::CMqttAdapter::HandleMessage ( std::string  topic,
std::string  message 
)
private
void freedm::broker::device::CMqttAdapter::Publish ( std::string  topic,
std::string  content 
)
private
void freedm::broker::device::IAdapter::RegisterDevice ( const std::string  devid)
inherited

Adds a device name to the registered device set.

Precondition:
None.
Postcondition:
Inserts the device name into m_devices.
Parameters
devidThe name of the device to register.
Limitations:
None.
void freedm::broker::device::IAdapter::RevealDevices ( )
protectedinherited

Reveals the associated devices in the device manager.

Precondition:
No prior call has been made to this function.
Postcondition:
Calls CDeviceManger::RevealDevice for each known device.
Limitations:
This function can be called at most once.
void freedm::broker::device::CMqttAdapter::SetCommand ( const std::string  device,
const std::string  key,
const SignalValue  value 
)
virtual
void freedm::broker::device::CMqttAdapter::Start ( )
virtual
void freedm::broker::device::CMqttAdapter::Stop ( )
virtual
void freedm::broker::device::CMqttAdapter::SubscribeAll ( std::string  deviceName)
private
void freedm::broker::device::CMqttAdapter::UnsubscribeAll ( std::string  deviceName)
private

Member Data Documentation

MQTTClient freedm::broker::device::CMqttAdapter::m_Client
private
TDeviceToData freedm::broker::device::CMqttAdapter::m_DeviceData
private
boost::mutex freedm::broker::device::CMqttAdapter::m_DeviceDataLock
mutableprivate
char freedm::broker::device::CMqttAdapter::m_ID[24]
private
std::list<CMqttMessage::Pointer> freedm::broker::device::CMqttAdapter::m_MessageQueue
private
MQTTClient_message freedm::broker::device::CMqttAdapter::pubmsg
private
MQTTClient_deliveryToken freedm::broker::device::CMqttAdapter::token
private

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