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

rwil::RWIL Class Reference

The object that represents the rwil. To start the system, call Start(). More...

#include <rwil.h>

Inheritance diagram for rwil::RWIL::

rwil::Thread List of all members.

Public Methods

 RWIL ()
 Constructs a RWIL object. More...

void AddDevice (Device *dev)
 Add a device to this instance of the implementation. More...

DeviceGetDevice (std::string name)
 Get a device from its name. More...

void RemoveDevice (std::string name)
 Remove a device by name. More...

virtual void Function ()
 The overloaded function that implements the RWIL functionality. More...

void Kill ()
 Kill the thread. More...


Public Attributes

MessageList input
 Represents the input messages. More...

MessageList output
 Represents the output messages. More...


Private Attributes

std::list< Device *> m_devices
 The list of devices. More...

Mutex m_mutex
 The mutex that maintains thread safety. More...

bool m_die
 Indicates that it is time for the thread to die. More...


Detailed Description

The object that represents the rwil. To start the system, call Start().

Definition at line 5 of file rwil.h.


Constructor & Destructor Documentation

rwil::RWIL::RWIL  
 

Constructs a RWIL object.

Definition at line 3 of file rwil.cpp.

00003 : m_die(false) {}


Member Function Documentation

void rwil::RWIL::AddDevice Device   dev
 

Add a device to this instance of the implementation.

Device must have unique name

Parameters:
Pointer  to an instance of a class that derives from Device

Definition at line 4 of file rwil.cpp.

References m_devices, and m_mutex.

00005   {
00006     ScopedMutex scpm(m_mutex);
00007     m_devices.push_back(dev);
00008   }

void rwil::RWIL::Function   [virtual]
 

The overloaded function that implements the RWIL functionality.

Reimplemented from rwil::Thread.

Definition at line 45 of file rwil.cpp.

References input, m_devices, m_die, m_mutex, and NULL.

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   }

Device * rwil::RWIL::GetDevice std::string    name
 

Get a device from its name.

Parameters:
Name  of device to find in system
Returns:
A pointer to the device or, NULL if the device does not exist

Definition at line 10 of file rwil.cpp.

References m_devices, m_mutex, and NULL.

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   }

void rwil::RWIL::Kill  
 

Kill the thread.

This returns immediately, but thread actually takes a long time to die. It is recommended to Join this thread to determine when done.

Definition at line 86 of file rwil.cpp.

References m_die, and m_mutex.

00087   {
00088     ScopedMutex scpm(m_mutex);
00089     m_die = true;
00090   }

void rwil::RWIL::RemoveDevice std::string    name
 

Remove a device by name.

If the device does not exist, this call does nothing.

Parameters:
name  Name of device to remove.

Definition at line 28 of file rwil.cpp.

References m_devices, and m_mutex.

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   }


Member Data Documentation

MessageList rwil::RWIL::input
 

Represents the input messages.

Definition at line 11 of file rwil.h.

Referenced by Function().

std::list<Device *> rwil::RWIL::m_devices [private]
 

The list of devices.

Definition at line 43 of file rwil.h.

Referenced by AddDevice(), Function(), GetDevice(), and RemoveDevice().

bool rwil::RWIL::m_die [private]
 

Indicates that it is time for the thread to die.

Definition at line 47 of file rwil.h.

Referenced by Function(), and Kill().

Mutex rwil::RWIL::m_mutex [private]
 

The mutex that maintains thread safety.

Reimplemented from rwil::Thread.

Definition at line 45 of file rwil.h.

Referenced by AddDevice(), Function(), GetDevice(), Kill(), and RemoveDevice().

MessageList rwil::RWIL::output
 

Represents the output messages.

Definition at line 13 of file rwil.h.


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