Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

rwil::Device Class Reference

Represents an abstract device capable of accepting messages. More...

#include <Device.h>

Inheritance diagram for rwil::Device::

rwil::X10Device List of all members.

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

MessageListm_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< Messagem_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...


Detailed Description

Represents an abstract device capable of accepting messages.

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.


Constructor & Destructor Documentation

rwil::Device::Device const std::string &    name,
MessageList   output
 

Create a device with a specified name and linked to a specific output queue.

Parameters:
name  The name of the device. This can be anything
output  The output MessageList that the device is linked to. This MessageList will recieve all error and success messages from the device.

Definition at line 4 of file Device.cpp.

00004 : m_output(output),  m_name(name), m_retries(2), m_currentRetry(0) {}

rwil::Device::~Device   [virtual]
 

Definition at line 6 of file Device.cpp.

00007   {
00008   }


Member Function Documentation

void rwil::Device::AddToQueue const Message   msg
 

Add a message to the execute queue for this device.

Parameters:
msg  The message to add to this device. This message MUST be associated with this device.

Definition at line 14 of file Device.cpp.

References GetName(), and m_queue.

00015   {
00016     //assert that the message is associated with this device
00017     assert(msg.GetDevice() == GetName());
00018         
00019     m_queue.push(msg);
00020   }

virtual ExecuteReturns::Returns rwil::Device::ExecuteMessage const Message   msg [protected, pure virtual]
 

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.

Parameters:
msg  Message to execute
Returns:
Whether or not the message should be retried

Reimplemented in rwil::X10Device.

Referenced by Tick().

const std::string & rwil::Device::GetName   const
 

Get the name of the device.

Returns:
The string name of the device specified in the constructor

Definition at line 9 of file Device.cpp.

References m_name.

Referenced by AddToQueue().

00010   {
00011     return m_name;
00012   }

virtual std::string rwil::Device::GetStatus   const [pure virtual]
 

Return a device-type dependent value representing the status of the device.

Returns:
The status in a string form.

Reimplemented in rwil::X10Device.

bool rwil::Device::Tick  
 

Execute the top message in the queue.

Returns:
A boolean value representing whether or not ANY action is attempted

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   }


Member Data Documentation

unsigned rwil::Device::m_currentRetry [private]
 

The number of retries that have been performed on the current message.

Definition at line 78 of file Device.h.

Referenced by Tick().

const std::string rwil::Device::m_name [private]
 

The string name of the device.

Definition at line 72 of file Device.h.

Referenced by GetName().

MessageList& rwil::Device::m_output [protected]
 

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().

std::queue<Message> rwil::Device::m_queue [private]
 

The execution queue of messages.

Definition at line 74 of file Device.h.

Referenced by AddToQueue(), and Tick().

unsigned rwil::Device::m_retries [private]
 

The number of retries to perform.

Definition at line 76 of file Device.h.

Referenced by Tick().


The documentation for this class was generated from the following files:
Generated on Thu Jan 17 15:51:20 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001