#include <MessageList.h>
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< Message > | m_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... |
Definition at line 10 of file MessageList.h.
|
Definition at line 73 of file MessageList.h. References m_addcallback, and NULL.
00073 : m_addcallback(NULL) {} |
|
Adds several messages to the list.
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 } |
|
Adds a single message to the list.
Definition at line 4 of file MessageList.cpp.
00005 { 00006 list<Message> lst; 00007 00008 lst.push_back(msg); 00009 Add(lst); 00010 } |
|
Removes a list of Messages from the list. The list of messages to remove must be acquired from the Query functions in some way.
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 } |
|
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 } |
|
Query for all messages that have a parameter with a specific value.
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 } |
|
Query for a list of messages that are timestamped between start and end inclusive.
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 } |
|
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 } |
|
Sets a Callback that is called before an add takes place. The callback function must be of type void(*func)(const list<Message&).
Definition at line 21 of file MessageList.cpp. References m_addcallback, and rwil::rwil_MessageList_AddCallback_t.
00022 { 00023 m_addcallback = callback; 00024 } |
|
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 } |
|
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.
Definition at line 95 of file MessageList.cpp. References m_count.
00096 { 00097 return m_count.Wait(milli); 00098 } |
|
The add callback.
Definition at line 83 of file MessageList.h. Referenced by Add(), MessageList(), and SetAddCallback(). |
|
The semaphore used to implement the waiting functions.
Definition at line 81 of file MessageList.h. |
|
Definition at line 79 of file MessageList.h. |
|
The list of messages inside the MessageList.
Definition at line 76 of file MessageList.h. |
|
The mutex that ensures thread-safety.
Definition at line 78 of file MessageList.h. |