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