]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/msgqueue.h
Remove identic implementations of wxDir::Exists from platform-specific files and...
[wxWidgets.git] / interface / wx / msgqueue.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgqueue.h
e54c96f1 3// Purpose: interface of wxMessageQueue<T>
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
7c913512
FM
10 wxMessageQueue allows passing messages between threads.
11
12 This class should be typically used to communicate between the main and worker
ba1d7a6c
FM
13 threads. The main thread calls wxMessageQueue::Post and the worker thread
14 calls wxMessageQueue::Receive.
7c913512 15
3c99e2fd
FM
16 @tparam T
17 For this class a message is an object of arbitrary type T.
18
ba1d7a6c 19 Notice that often there is a some special message indicating that the thread
7c913512
FM
20 should terminate as there is no other way to gracefully shutdown a thread
21 waiting on the message queue.
22
d25a864d
VZ
23 @since 2.9.0
24
23324ae1 25 @nolibrary
3c99e2fd 26 @category{threading}
7c913512 27
e54c96f1 28 @see wxThread
23324ae1 29*/
3c99e2fd 30template <typename T>
7c913512 31class wxMessageQueue<T>
23324ae1
FM
32{
33public:
ba1d7a6c
FM
34 /**
35 Default and only constructor.
36 Use wxMessageQueue::IsOk to check if the object was successfully initialized.
37 */
38 wxMessageQueue();
39
d25a864d
VZ
40 /**
41 Remove all messages from the queue.
42
43 This method is meant to be called from the same thread(s) that call
44 Post() to discard any still pending requests if they became
45 unnecessary.
46
47 @since 2.9.1
48 */
49 wxMessageQueueError Clear();
50
23324ae1 51 /**
7c913512 52 Returns @true if the object had been initialized successfully, @false
23324ae1
FM
53 if an error occurred.
54 */
328f5751 55 bool IsOk() const;
23324ae1
FM
56
57 /**
7c913512
FM
58 Add a message to this queue and signal the threads waiting for messages
59 (i.e. the threads which called wxMessageQueue::Receive or
60 wxMessageQueue::ReceiveTimeout).
ba1d7a6c 61
23324ae1
FM
62 This method is safe to call from multiple threads in parallel.
63 */
64 wxMessageQueueError Post(T const& msg);
65
66 /**
ba1d7a6c
FM
67 Block until a message becomes available in the queue.
68 Waits indefinitely long or until an error occurs.
69
70 The message is returned in @a msg.
23324ae1
FM
71 */
72 wxMessageQueueError Receive(T& msg);
73
74 /**
7c913512 75 Block until a message becomes available in the queue, but no more than
4cc4bfaf 76 @a timeout milliseconds has elapsed.
ba1d7a6c 77
4cc4bfaf 78 If no message is available after @a timeout milliseconds then returns
7c913512 79 @b wxMSGQUEUE_TIMEOUT.
ba1d7a6c 80
4cc4bfaf 81 If @a timeout is 0 then checks for any messages present in the queue
7c913512 82 and returns immediately without waiting.
23324ae1 83
ba1d7a6c 84 The message is returned in @a msg.
23324ae1 85 */
ba1d7a6c 86 wxMessageQueueError ReceiveTimeout(long timeout, T& msg);
23324ae1 87};
e54c96f1 88