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