2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: msgqueue.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxMessageQueue<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMessageQueue allows passing messages between threads.
|
|
|
|
|
|
|
|
This class should be typically used to communicate between the main and worker
|
2008-10-11 09:10:48 -04:00
|
|
|
threads. The main thread calls wxMessageQueue::Post and the worker thread
|
|
|
|
calls wxMessageQueue::Receive.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-02-20 06:34:52 -05:00
|
|
|
@tparam T
|
|
|
|
For this class a message is an object of arbitrary type T.
|
|
|
|
|
2008-10-11 09:10:48 -04:00
|
|
|
Notice that often there is a some special message indicating that the thread
|
2008-03-08 09:43:31 -05:00
|
|
|
should terminate as there is no other way to gracefully shutdown a thread
|
|
|
|
waiting on the message queue.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@nolibrary
|
2009-02-20 06:34:52 -05:00
|
|
|
@category{threading}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxThread
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-02-20 06:34:52 -05:00
|
|
|
template <typename T>
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxMessageQueue<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-10-11 09:10:48 -04:00
|
|
|
/**
|
|
|
|
Default and only constructor.
|
|
|
|
Use wxMessageQueue::IsOk to check if the object was successfully initialized.
|
|
|
|
*/
|
|
|
|
wxMessageQueue();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Returns @true if the object had been initialized successfully, @false
|
2008-03-08 08:52:38 -05:00
|
|
|
if an error occurred.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Add a message to this queue and signal the threads waiting for messages
|
|
|
|
(i.e. the threads which called wxMessageQueue::Receive or
|
|
|
|
wxMessageQueue::ReceiveTimeout).
|
2008-10-11 09:10:48 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is safe to call from multiple threads in parallel.
|
|
|
|
*/
|
|
|
|
wxMessageQueueError Post(T const& msg);
|
|
|
|
|
|
|
|
/**
|
2008-10-11 09:10:48 -04:00
|
|
|
Block until a message becomes available in the queue.
|
|
|
|
Waits indefinitely long or until an error occurs.
|
|
|
|
|
|
|
|
The message is returned in @a msg.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxMessageQueueError Receive(T& msg);
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Block until a message becomes available in the queue, but no more than
|
2008-03-09 08:33:59 -04:00
|
|
|
@a timeout milliseconds has elapsed.
|
2008-10-11 09:10:48 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
If no message is available after @a timeout milliseconds then returns
|
2008-03-08 09:43:31 -05:00
|
|
|
@b wxMSGQUEUE_TIMEOUT.
|
2008-10-11 09:10:48 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
If @a timeout is 0 then checks for any messages present in the queue
|
2008-03-08 09:43:31 -05:00
|
|
|
and returns immediately without waiting.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-10-11 09:10:48 -04:00
|
|
|
The message is returned in @a msg.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-11 09:10:48 -04:00
|
|
|
wxMessageQueueError ReceiveTimeout(long timeout, T& msg);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|