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

rwil.cpp

Go to the documentation of this file.
00001 #include "rwil.h"
00002 namespace rwil {
00003   RWIL::RWIL() : m_die(false) {}
00004   void RWIL::AddDevice(Device *dev)
00005   {
00006     ScopedMutex scpm(m_mutex);
00007     m_devices.push_back(dev);
00008   }
00009        
00010   Device *RWIL::GetDevice(std::string name)
00011   {
00012 
00013     ScopedMutex scpm(m_mutex);
00014 
00015     std::list<Device*>::iterator iter = m_devices.begin();
00016 
00017     while((iter != m_devices.end()) && !m_devices.empty())
00018       {
00019         if((*iter)->GetName() == name)
00020           {
00021             return *iter;
00022           }
00023         iter++;
00024       }
00025     return NULL;
00026   }
00027 
00028   void RWIL::RemoveDevice(std::string name)
00029   {
00030 
00031     ScopedMutex scpm(m_mutex);  
00032     std::list<Device*>::iterator iter = m_devices.begin();
00033     while(iter != m_devices.end())
00034       {
00035         if((*iter)->GetName() == name)
00036           {
00037                         
00038             m_devices.erase(iter);
00039             break;
00040           }
00041         iter++;
00042       }
00043   }
00044 
00045   void RWIL::Function()
00046   {
00047     bool temp;
00048                 
00049     while(m_mutex.Wait(), temp = m_die, m_mutex.Release(), temp == false)
00050       {
00051         input.Lock();
00052         std::list<Message*> moving(input.Query(0, time(NULL)));
00053         std::list<Message*>::iterator movingIter = moving.begin();
00054         std::list<Message*> removed;
00055                         
00056         //Move all messages into the appropriate devices
00057         while(movingIter != moving.end())
00058           {
00059             std::list<Device*>::iterator deviceIter = m_devices.begin();
00060             while(deviceIter != m_devices.end())
00061               {
00062                 if((*deviceIter)->GetName() == ((*movingIter)->GetDevice()))
00063                   {
00064                     (*deviceIter)->AddToQueue(**movingIter);
00065                     removed.push_back(*movingIter);
00066                   }
00067                 deviceIter++;
00068               }
00069             movingIter++;
00070           }
00071 
00072         input.Destroy(removed);
00073         input.Release();
00074         //Iterate through all the devices and tell them to work their magic
00075         std::list<Device*>::iterator deviceIter = m_devices.begin();
00076         while(deviceIter != m_devices.end())
00077           {
00078             (*deviceIter)->Tick();
00079             deviceIter++;
00080           }                     
00081       }
00082     m_die = false;
00083     return;
00084   }
00085         
00086   void RWIL::Kill()
00087   {
00088     ScopedMutex scpm(m_mutex);
00089     m_die = true;
00090   }
00091 }

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