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

Generated on Tue Apr 9 13:53:07 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001