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

rwil::MessageList Class Reference

Maintains a thread-safe list of messages. More...

#include <MessageList.h>

List of all members.

Public Methods

void Add (const Message &msg)
 Adds a single message to the list. More...

void Add (list< Message > &messages)
 Adds several messages to the list. More...

void SetAddCallback (rwil_MessageList_AddCallback_t callback)
 Sets a Callback that is called before an add takes place. The callback function must be of type void(*func)(const list<Message&). More...

list< Message *> Query (time_t start, time_t end)
 Query for a list of messages that are timestamped between start and end inclusive. More...

list< Message *> Query (std::string paramname, std::string value)
 Query for all messages that have a parameter with a specific value. More...

void Destroy (list< Message *> messages)
 Removes a list of Messages from the list. More...

void Lock ()
 Locks the List. More...

void Release ()
 Unlocks the list. More...

bool Wait (int milli)
 Waits for a message to be added. More...

void Wait ()
 Waits for a message to be added. More...

 MessageList ()

Private Attributes

list< Messagem_messages
 The list of messages inside the MessageList. More...

Mutex m_op
 The mutex that ensures thread-safety. More...

Mutex m_lock
Semaphore m_count
 The semaphore used to implement the waiting functions. More...

rwil_MessageList_AddCallback_t m_addcallback
 The add callback. More...


Detailed Description

Maintains a thread-safe list of messages.

Definition at line 10 of file MessageList.h.


Constructor & Destructor Documentation

rwil::MessageList::MessageList   [inline]
 

Definition at line 73 of file MessageList.h.

References m_addcallback, and NULL.

00073 : m_addcallback(NULL) {}


Member Function Documentation

void rwil::MessageList::Add list< Message > &    messages
 

Adds several messages to the list.

Parameters:
messages  Messages to add to the list. The callback is called before any messages are added.

Definition at line 11 of file MessageList.cpp.

References m_addcallback, m_count, m_messages, and m_op.

00012   {
00013     if(m_addcallback)
00014       m_addcallback(messages);
00015     ScopedMutex scope(m_op);
00016     messages.sort();
00017     m_messages.merge(messages);
00018     m_count.Signal();
00019   }

void rwil::MessageList::Add const Message   msg
 

Adds a single message to the list.

Parameters:
msg  Message to add to the list. The callback is called before the message is added.

Definition at line 4 of file MessageList.cpp.

00005   {
00006     list<Message> lst;
00007 
00008     lst.push_back(msg);
00009     Add(lst);
00010   }

void rwil::MessageList::Destroy list< Message *>    messages
 

Removes a list of Messages from the list.

The list of messages to remove must be acquired from the Query functions in some way.

Parameters:
messages  The list of messages to remove from the list.

Definition at line 65 of file MessageList.cpp.

References m_messages, and m_op.

00066   {
00067     ScopedMutex scope(m_op);
00068     list<Message *>::iterator piter;
00069     list<Message>::iterator miter;
00070     piter = messages.begin();
00071     while(piter != messages.end())
00072       {
00073         miter = m_messages.begin();
00074         while(miter != m_messages.end())
00075           {
00076             if(&(*miter) == *piter)
00077               {
00078                 m_messages.erase(miter);
00079                 break;
00080               }
00081           }
00082         piter++;
00083       }
00084   }

void rwil::MessageList::Lock  
 

Locks the List.

This function is designed to be used so that modifications to the list that use more than one function can be executed without interference from other threads.

Definition at line 86 of file MessageList.cpp.

References m_lock.

00087   {
00088     m_lock.Wait();
00089   }

list< Message *> rwil::MessageList::Query std::string    paramname,
std::string    value
 

Query for all messages that have a parameter with a specific value.

Parameters:
paramname  The name of the parameter to examine.
value  The value of paramname to match.
Returns:
A list of pointers to Message's that fit the query.

Definition at line 45 of file MessageList.cpp.

References m_messages, m_op, and value.

00046   {
00047     ScopedMutex scope(m_op);
00048     list<Message>::iterator iter;
00049     list<Message *> retval;
00050 
00051     iter = m_messages.begin();
00052 
00053     while(iter != m_messages.end())
00054       {
00055         if((*iter).GetParam(paramname) == value)
00056           {
00057             retval.push_back(&(*iter));
00058           }
00059         iter++;
00060       }
00061     return retval;
00062   }

list< Message *> rwil::MessageList::Query time_t    start,
time_t    end
 

Query for a list of messages that are timestamped between start and end inclusive.

Parameters:
start  The start of the span of time to query in.
end  The end of the span of time to query in.
Returns:
A list of pointers to Message's that fit the query.

Definition at line 25 of file MessageList.cpp.

References m_messages, and m_op.

00026   {
00027     ScopedMutex scope(m_op);
00028     list<Message>::iterator iter;
00029     list<Message *> retval;
00030 
00031     iter = m_messages.begin();
00032     while(iter != m_messages.end())
00033       {
00034         time_t when = (*iter).GetWhen();
00035         if((when >= start) && ( when <=end))
00036           {
00037             retval.push_back(&(*iter));
00038           }
00039 
00040         iter++;
00041       }
00042     return retval;
00043   }

void rwil::MessageList::Release  
 

Unlocks the list.

This function is designed to be used so that modifications to the list that use more than one function can be executed without interference from other threads.

Definition at line 90 of file MessageList.cpp.

References m_lock.

00091   {
00092     m_lock.Release();
00093   }

void rwil::MessageList::SetAddCallback rwil_MessageList_AddCallback_t    callback
 

Sets a Callback that is called before an add takes place. The callback function must be of type void(*func)(const list<Message&).

Parameters:
callback  The callback that is called before an add takes place. The callback recieves a parameter of type const list<Message&> which represents the messages that are about to be added.

Definition at line 21 of file MessageList.cpp.

References m_addcallback, and rwil::rwil_MessageList_AddCallback_t.

00022   {
00023     m_addcallback = callback;
00024   }

void rwil::MessageList::Wait  
 

Waits for a message to be added.

This may return immediately if an item was added to the list and not waited on previously.

Definition at line 100 of file MessageList.cpp.

References m_count.

00101   {
00102     return m_count.Wait();
00103   }

bool rwil::MessageList::Wait int    milli
 

Waits for a message to be added.

This may return immediately if an item was added to the list and not waited on previously. This function has a timeout measure in milliseconds.

Parameters:
milli  number of milliseconds to wait

Definition at line 95 of file MessageList.cpp.

References m_count.

00096   {
00097     return m_count.Wait(milli);
00098   }


Member Data Documentation

rwil_MessageList_AddCallback_t rwil::MessageList::m_addcallback [private]
 

The add callback.

Definition at line 83 of file MessageList.h.

Referenced by Add(), MessageList(), and SetAddCallback().

Semaphore rwil::MessageList::m_count [private]
 

The semaphore used to implement the waiting functions.

Definition at line 81 of file MessageList.h.

Referenced by Add(), and Wait().

Mutex rwil::MessageList::m_lock [private]
 

Definition at line 79 of file MessageList.h.

Referenced by Lock(), and Release().

list<Message> rwil::MessageList::m_messages [private]
 

The list of messages inside the MessageList.

Definition at line 76 of file MessageList.h.

Referenced by Add(), Destroy(), and Query().

Mutex rwil::MessageList::m_op [private]
 

The mutex that ensures thread-safety.

Definition at line 78 of file MessageList.h.

Referenced by Add(), Destroy(), and Query().


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