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
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@wxheader{msgqueue.h}
|
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
|
|
|
|
threads. The main thread calls wxMessageQueue::Post and
|
|
|
|
the worker thread calls wxMessageQueue::Receive.
|
|
|
|
|
|
|
|
For this class a message is an object of arbitrary type T. Notice that
|
|
|
|
often there is a some special message indicating that the thread
|
|
|
|
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
|
|
|
|
@category{FIXME}
|
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
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxMessageQueue<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
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-03-08 08:52:38 -05:00
|
|
|
This method is safe to call from multiple threads in parallel.
|
|
|
|
*/
|
|
|
|
wxMessageQueueError Post(T const& msg);
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Block until a message becomes available in the queue. Waits indefinitely long
|
|
|
|
or until an error occurs.
|
2008-03-08 08:52:38 -05:00
|
|
|
The message is returned in @e msg.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
If no message is available after @a timeout milliseconds then returns
|
2008-03-08 09:43:31 -05:00
|
|
|
@b wxMSGQUEUE_TIMEOUT.
|
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
|
|
|
The message is returned in @e msg.
|
|
|
|
*/
|
|
|
|
wxMessageQueueError ReceiveTimeout(long timeout, T& msg);
|
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Default and only constructor. Use wxMessageQueue::IsOk to check
|
2008-03-08 08:52:38 -05:00
|
|
|
if the object was successfully initialized.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMessageQueue();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|