soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SMsgLoop.h
1#ifndef __SMSGLOOP__H__
2#define __SMSGLOOP__H__
3
4#include <soui_exp.h>
5#include <helper/obj-ref-impl.hpp>
6#include <interface/SMsgLoop-i.h>
7
8SNSBEGIN
9
10// Forward declarations
11class SMessageLoopPriv;
12
13/**
14 * @brief Message loop class for handling window messages and idle processing.
15 * This class implements the IMessageLoop interface and manages the message loop for a window.
16 */
17class SOUI_EXP SMessageLoop : public TObjRefImpl<IMessageLoop> {
18 public:
19 /**
20 * @brief Constructor for SMessageLoop.
21 * @param pParentLoop Pointer to the parent message loop.
22 */
23 SMessageLoop(IMessageLoop *pParentLoop);
24
25 /**
26 * @brief Destructor for SMessageLoop.
27 */
28 virtual ~SMessageLoop();
29
30 public:
31 /**
32 * @brief Adds a message filter to the message loop.
33 * @param pMessageFilter Pointer to the message filter to add.
34 * @return TRUE if the filter is added successfully, FALSE otherwise.
35 */
36 STDMETHOD_(BOOL, AddMessageFilter)(THIS_ IMsgFilter *pMessageFilter) OVERRIDE;
37
38 /**
39 * @brief Removes a message filter from the message loop.
40 * @param pMessageFilter Pointer to the message filter to remove.
41 * @return TRUE if the filter is removed successfully, FALSE otherwise.
42 */
43 STDMETHOD_(BOOL, RemoveMessageFilter)(THIS_ IMsgFilter *pMessageFilter) OVERRIDE;
44
45 /**
46 * @brief Adds an idle handler to the message loop.
47 * @param pIdleHandler Pointer to the idle handler to add.
48 * @return TRUE if the handler is added successfully, FALSE otherwise.
49 */
50 STDMETHOD_(BOOL, AddIdleHandler)(THIS_ IIdleHandler *pIdleHandler) OVERRIDE;
51
52 /**
53 * @brief Removes an idle handler from the message loop.
54 * @param pIdleHandler Pointer to the idle handler to remove.
55 * @return TRUE if the handler is removed successfully, FALSE otherwise.
56 */
57 STDMETHOD_(BOOL, RemoveIdleHandler)(THIS_ IIdleHandler *pIdleHandler) OVERRIDE;
58
59 /**
60 * @brief Pre-translates a message before it is dispatched.
61 * @param pMsg Pointer to the message to translate.
62 * @return TRUE if the message is translated and should not be dispatched further, FALSE otherwise.
63 */
64 STDMETHOD_(BOOL, PreTranslateMessage)(THIS_ MSG *pMsg) OVERRIDE;
65
66 /**
67 * @brief Handles idle processing.
68 * @param nIdleCount Idle count.
69 * @return TRUE if more idle processing is needed, FALSE otherwise.
70 */
71 STDMETHOD_(BOOL, OnIdle)(THIS_ int nIdleCount) OVERRIDE;
72
73 /**
74 * @brief Runs the message loop.
75 * @return Exit code of the message loop.
76 */
77 STDMETHOD_(int, Run)(THIS) OVERRIDE;
78
79 /**
80 * @brief Checks if the message loop is running.
81 * @return TRUE if the message loop is running, FALSE otherwise.
82 */
83 STDMETHOD_(BOOL, IsRunning)(THIS) const OVERRIDE;
84
85 /**
86 * @brief Processes a single message.
87 * @param pMsg Pointer to the message to process.
88 */
89 STDMETHOD_(void, OnMsg)(THIS_ LPMSG pMsg) OVERRIDE;
90
91 /**
92 * @brief Quits the message loop.
93 * @param exitCode Exit code for the message loop.
94 */
95 STDMETHOD_(void, Quit)(THIS_ int exitCode) OVERRIDE;
96
97 /**
98 * @brief Posts a task to the message loop.
99 * @param runable Pointer to the task to post.
100 * @return TRUE if the task is posted successfully, FALSE otherwise.
101 */
102 STDMETHOD_(BOOL, PostTask)(THIS_ IRunnable *runable) OVERRIDE;
103
104 /**
105 * @brief Removes all tasks associated with a specific object.
106 * @param pObj Pointer to the object whose tasks should be removed.
107 * @return Number of tasks removed.
108 */
109 STDMETHOD_(int, RemoveTasksForObject)(THIS_ void *pObj) OVERRIDE;
110
111 /**
112 * @brief Executes all pending tasks.
113 */
114 STDMETHOD_(void, ExecutePendingTask)() OVERRIDE;
115
116 /**
117 * @brief Peeks at a message in the message queue without removing it.
118 * @param pMsg Pointer to the message to receive.
119 * @param wMsgFilterMin Minimum message value to peek.
120 * @param wMsgFilterMax Maximum message value to peek.
121 * @param bRemove TRUE to remove the message from the queue, FALSE otherwise.
122 * @return TRUE if a message is available, FALSE otherwise.
123 */
124 STDMETHOD_(BOOL, PeekMsg)(THIS_ LPMSG pMsg, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL bRemove) OVERRIDE;
125
126 /**
127 * @brief Waits for a message in the message queue.
128 * @return TRUE if a message is available, FALSE otherwise.
129 */
130 STDMETHOD_(BOOL, WaitMsg)(THIS) OVERRIDE;
131
132 /**
133 * @brief Handles a message from the message queue.
134 * @return Result of the message handling.
135 */
136 STDMETHOD_(int, HandleMsg)(THIS) OVERRIDE;
137
138 public:
139 /**
140 * @brief Checks if a message is an idle message.
141 * @param pMsg Pointer to the message to check.
142 * @return TRUE if the message is an idle message, FALSE otherwise.
143 */
144 static BOOL IsIdleMessage(MSG *pMsg);
145
146 protected:
147 /**
148 * @brief Runs idle processing.
149 */
150 void RunIdle();
151
152 protected:
153 // Flag indicating whether the message loop is running
154 BOOL m_bRunning;
155 // Flag indicating whether the message loop should quit
156 BOOL m_bQuit;
157 // Flag indicating whether idle processing should be done
158 BOOL m_bDoIdle;
159 // Idle count
160 int m_nIdleCount;
161
162 // Critical section for thread safety
163 SCriticalSection m_cs;
164 // Critical section for the running queue
165 SCriticalSection m_csRunningQueue;
166 // Thread ID of the message loop
167 tid_t m_tid;
168 // Pointer to the private implementation
169 SMessageLoopPriv *m_priv;
170};
171
172SNSEND
173
174#endif // __SMSGLOOP__H__
Wrapper class for a critical section.
BOOL PostTask(IRunnable *runable) OVERRIDE
Posts a task to the message loop.
Definition SMsgLoop.cpp:174
int HandleMsg() OVERRIDE
Handles a message from the message queue.
Definition SMsgLoop.cpp:269
static BOOL IsIdleMessage(MSG *pMsg)
Checks if a message is an idle message.
Definition SMsgLoop.cpp:133
BOOL PeekMsg(LPMSG pMsg, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL bRemove) OVERRIDE
Peeks at a message in the message queue without removing it.
Definition SMsgLoop.cpp:247
void ExecutePendingTask() OVERRIDE
Executes all pending tasks.
Definition SMsgLoop.cpp:226
void OnMsg(LPMSG pMsg) OVERRIDE
Processes a single message.
Definition SMsgLoop.cpp:48
BOOL RemoveMessageFilter(IMsgFilter *pMessageFilter) OVERRIDE
Removes a message filter from the message loop.
Definition SMsgLoop.cpp:163
BOOL PreTranslateMessage(MSG *pMsg) OVERRIDE
Pre-translates a message before it is dispatched.
Definition SMsgLoop.cpp:117
BOOL RemoveIdleHandler(IIdleHandler *pIdleHandler) OVERRIDE
Removes an idle handler from the message loop.
Definition SMsgLoop.cpp:148
BOOL OnIdle(int nIdleCount) OVERRIDE
Handles idle processing.
Definition SMsgLoop.cpp:99
void RunIdle()
Runs idle processing.
Definition SMsgLoop.cpp:252
int Run() OVERRIDE
Runs the message loop.
Definition SMsgLoop.cpp:64
BOOL AddIdleHandler(IIdleHandler *pIdleHandler) OVERRIDE
Adds an idle handler to the message loop.
Definition SMsgLoop.cpp:155
BOOL IsRunning() const OVERRIDE
Checks if the message loop is running.
Definition SMsgLoop.cpp:221
BOOL AddMessageFilter(IMsgFilter *pMessageFilter) OVERRIDE
Adds a message filter to the message loop.
Definition SMsgLoop.cpp:168
BOOL WaitMsg() OVERRIDE
Waits for a message in the message queue.
Definition SMsgLoop.cpp:261
int RemoveTasksForObject(void *pObj) OVERRIDE
Removes all tasks associated with a specific object.
Definition SMsgLoop.cpp:189
void Quit(int exitCode) OVERRIDE
Quits the message loop.
Definition SMsgLoop.cpp:57
SMessageLoop(IMessageLoop *pParentLoop)
Constructor for SMessageLoop.
Definition SMsgLoop.cpp:33
Interface for handling idle time.
Definition SMsgLoop-i.h:29
Interface for message loops.
Definition SMsgLoop-i.h:42
Interface for message filtering.
Definition SMsgLoop-i.h:15