#include <Device.h>
Inheritance diagram for rwil::Device::
Public Methods | |
Device (const std::string &name, MessageList &output) | |
Create a device with a specified name and linked to a specific output queue. More... | |
virtual | ~Device () |
virtual std::string | GetStatus () const=0 |
Return a device-type dependent value representing the status of the device. More... | |
const std::string & | GetName () const |
Get the name of the device. More... | |
void | AddToQueue (const Message &msg) |
Add a message to the execute queue for this device. More... | |
bool | Tick () |
Execute the top message in the queue. More... | |
Protected Methods | |
virtual ExecuteReturns::Returns | ExecuteMessage (const Message &msg)=0 |
The function which performs the messages. More... | |
Protected Attributes | |
MessageList & | m_output |
The output MessageList, this is where success and failure messages are sent. More... | |
Private Attributes | |
const std::string | m_name |
The string name of the device. More... | |
std::queue< Message > | m_queue |
The execution queue of messages. More... | |
unsigned | m_retries |
The number of retries to perform. More... | |
unsigned | m_currentRetry |
The number of retries that have been performed on the current message. More... |
A Device is an abstract class representing the concept of a device that can accept messages and act upon them.
Definition at line 19 of file Device.h.
|
Create a device with a specified name and linked to a specific output queue.
Definition at line 4 of file Device.cpp.
00004 : m_output(output), m_name(name), m_retries(2), m_currentRetry(0) {} |
|
Definition at line 6 of file Device.cpp.
00007 { 00008 } |
|
Add a message to the execute queue for this device.
Definition at line 14 of file Device.cpp. References GetName(), and m_queue.
|
|
The function which performs the messages. This function is written so that it returns PleaseRetry if it wants the message to be sent to it again. Messages are only repeated a certain number of times(default: 3). This can be changed by send a SetRetriesMessage to the device.
Reimplemented in rwil::X10Device. Referenced by Tick(). |
|
Get the name of the device.
Definition at line 9 of file Device.cpp. References m_name. Referenced by AddToQueue().
00010 { 00011 return m_name; 00012 } |
|
Return a device-type dependent value representing the status of the device.
Reimplemented in rwil::X10Device. |
|
Execute the top message in the queue.
Definition at line 24 of file Device.cpp. References ExecuteMessage(), m_currentRetry, m_output, m_queue, m_retries, and rwil::StringToInt().
00025 { 00026 if(m_queue.empty()) return false; 00027 00028 if(m_queue.front().GetCommand() == "SetRetries") 00029 { 00030 try 00031 { 00032 m_retries = StringToInt(m_queue.front().GetParam("retries")); 00033 } 00034 catch(const char * e) 00035 { 00036 cout << e << endl; 00037 } 00038 m_queue.pop(); 00039 return true; 00040 } 00041 else 00042 { 00043 ExecuteReturns::Returns retval; 00044 try 00045 { 00046 retval = ExecuteMessage(m_queue.front()); 00047 } 00048 catch (const char *e) 00049 { 00050 m_output.Add(EncapsulatingMessage(e, m_queue.front())); 00051 00052 m_queue.pop(); 00053 m_currentRetry = 0; 00054 return true; 00055 } 00056 catch (...) 00057 { 00058 m_output.Add(EncapsulatingMessage("Failed", m_queue.front())); 00059 00060 m_queue.pop(); 00061 m_currentRetry = 0; 00062 return true; 00063 } 00064 if(retval==ExecuteReturns::DontRetry) 00065 { 00066 m_queue.pop(); 00067 m_currentRetry = 0; 00068 } 00069 else 00070 { 00071 m_currentRetry++; 00072 if(m_currentRetry>(m_retries+1)) 00073 { 00074 m_output.Add(FailedAfterRetryingMessage(m_queue.front())); 00075 m_queue.pop(); 00076 m_currentRetry = 0; 00077 } 00078 } 00079 } 00080 return true; 00081 } |
|
The number of retries that have been performed on the current message.
Definition at line 78 of file Device.h. Referenced by Tick(). |
|
The string name of the device.
Definition at line 72 of file Device.h. Referenced by GetName(). |
|
The output MessageList, this is where success and failure messages are sent.
Definition at line 58 of file Device.h. Referenced by rwil::X10Device::ExecuteMessage(), and Tick(). |
|
The execution queue of messages.
Definition at line 74 of file Device.h. Referenced by AddToQueue(), and Tick(). |
|
The number of retries to perform.
Definition at line 76 of file Device.h. Referenced by Tick(). |