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

Device.cpp

Go to the documentation of this file.
00001 #include "Device.h"
00002 namespace rwil {
00003 
00004   Device::Device(const std::string &name, MessageList& output) : m_output(output),  m_name(name), m_retries(2), m_currentRetry(0) {}
00005 
00006   Device::~Device()
00007   {
00008   }
00009   const std::string &Device::GetName() const
00010   {
00011     return m_name;
00012   }
00013 
00014   void Device::AddToQueue(const Message &msg)
00015   {
00016     //assert that the message is associated with this device
00017     assert(msg.GetDevice() == GetName());
00018         
00019     m_queue.push(msg);
00020   }
00021 
00022   //Execute the top message in the queue
00023   //Return true if anything is attempted
00024   bool Device::Tick()
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   }
00082 }

Generated on Thu Jan 17 15:51:19 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001