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 rwil::X10Recv 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...

virtual 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 5 of file Device.cpp.

Referenced by rwil::X10Recv::X10Recv().

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

rwil::Device::~Device   [virtual]
 

Definition at line 7 of file Device.cpp.

00008   {
00009   }


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 15 of file Device.cpp.

References GetName(), and m_queue.

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

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, and rwil::X10Recv.

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 10 of file Device.cpp.

References m_name.

Referenced by AddToQueue(), and rwil::X10Recv::Tick().

00011   {
00012     return m_name;
00013   }

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, and rwil::X10Recv.

bool rwil::Device::Tick   [virtual]
 

Execute the top message in the queue.

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

Reimplemented in rwil::X10Recv.

Definition at line 25 of file Device.cpp.

References ExecuteMessage(), m_currentRetry, m_output, m_queue, m_retries, and rwil::StringToInt().

00026   {
00027     if(m_queue.empty()) return false;
00028 
00029     if(m_queue.front().GetCommand() == "SetRetries")
00030       {
00031         try
00032           {
00033             m_retries = StringToInt(m_queue.front().GetParam("retries"));
00034           }
00035         catch(const char * e)
00036           {
00037             cout << e << endl;
00038           }
00039         m_queue.pop();
00040         return true;
00041       }
00042     else
00043       {
00044         ExecuteReturns::Returns retval;
00045         try
00046           {
00047             retval = ExecuteMessage(m_queue.front());
00048           }
00049         catch (const char *e)
00050           {
00051             m_output.Add(EncapsulatingMessage(e, m_queue.front()));
00052 
00053             m_queue.pop();
00054             m_currentRetry = 0;
00055             return true;
00056           }
00057         catch (...)
00058           {
00059             m_output.Add(EncapsulatingMessage("Failed", m_queue.front()));
00060 
00061             m_queue.pop();
00062             m_currentRetry = 0;
00063             return true;
00064           }
00065         if(retval==ExecuteReturns::DontRetry)
00066           {
00067             m_queue.pop();
00068             m_currentRetry = 0;
00069           }
00070         else 
00071           {
00072             m_currentRetry++;
00073             if(m_currentRetry>(m_retries+1))
00074               {
00075                 m_output.Add(FailedAfterRetryingMessage(m_queue.front()));
00076                 m_queue.pop();
00077                 m_currentRetry = 0;
00078               }
00079           }
00080       }
00081     return true;
00082   }


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(), rwil::X10Recv::Tick(), 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 Tue Apr 9 13:53:08 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001