Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C++

Create Cross-platform Thread-Independent Event Loops

Rate me:
Please Sign up or sign in to vote.
4.89/5 (5 votes)
12 May 20076 min read 45.8K   687   28  
This article discloses what is behind the GetMessage() and PostThreadMessage() Windows API, and implements them on Linux and Windows platforms using basic operation system functions.
11:35:28	
11:35:28	Start realtime state tracking ...
11:35:28	Trace Test
11:35:28	APPLICATION     SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
11:35:28	Player1                         PowerDown                 0         Activated                     
11:35:28	SingleState1                    SingleState               0         Activated                     
11:35:29	SingleState1    SingleState     SingleState     1         0         Not Matched                   
11:35:29	Player1         PowerDown       Pause           1         0         Hit                           
11:35:32	SingleState1    SingleState     SingleState     2         0         Not Matched                   
11:35:32	
11:35:32	Catching the current active application states ... 
11:35:32	APPLICATION     STATE           
11:35:32	SingleState1    SingleState     
11:35:32	Player1         Playing         
11:35:32	
11:35:32	Player1         Pause           Playing         2         47        Hit                           
11:35:33	Player1         Playing         Playing         Timeout   0         Not Matched                   
10:58:39	
10:58:39	Trace Test
10:58:39	Start realtime state tracking ...
10:58:39	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
10:58:39	Player1         Player                          PowerDown                 0         Activated                     
10:58:39	SingleState1    SingleState                     SingleState               0         Activated                     
10:58:41	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
10:58:41	Player1         Player          PowerDown       Pause           1         0         Hit                           
10:58:43	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
10:58:43	
10:58:43	Catching the current active application states ... 
10:58:43	APPLICATION     STATE           
10:58:43	SingleState1    SingleState     
10:58:43	Player1         Playing         
10:58:43	
10:58:43	Player1         Player          Pause           Playing         2         47        Hit                           
10:58:44	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
10:59:02	
10:59:02	Trace Test
10:59:02	Start realtime state tracking ...
10:59:02	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
10:59:02	Player1         Player                          PowerDown                 0         Activated                     
10:59:03	
10:59:03	Catching the current active application states ... 
10:59:03	APPLICATION     STATE           
10:59:03	Player1         Playing         
10:59:03	
10:59:03	SingleState1    SingleState                     SingleState               0         Activated                     
10:59:03	Player1         Player          Cond1           Playing         1         15        Hit                           
10:59:04	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
10:59:05	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
10:59:05	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
10:59:06	SingleState1    SingleState                                               0         De-activated                  
10:59:06	Player1         Player          Playing         Pause           2         203       Hit                           
14:07:01	
14:07:01	Trace Test
14:07:01	Start realtime state tracking ...
14:07:01	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
14:07:01	Player1         Player                          PowerDown                 0         Activated                     
14:07:01	SingleState1    SingleState                     SingleState               0         Activated                     
14:07:02	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
14:07:02	Player1         Player          PowerDown       Pause           1         0         Hit                           
14:07:15	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
14:07:15	
14:07:15	Catching the current active application states ... 
14:07:15	APPLICATION     STATE           
14:07:15	SingleState1    SingleState     
14:07:15	Player1         Playing         
14:07:15	
14:07:15	Player1         Player          Pause           Playing         2         63        Hit                           
14:07:16	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
14:07:17	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
14:07:17	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
14:07:17	Player1         Player          Playing         PowerDown       1         172       Hit                           
21:12:51	Trace Test
21:12:51	Start realtime state tracking ...
21:12:51	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
21:12:51	Player1         Player                          PowerDown                 0         Activated                     
21:12:51	SingleState1    SingleState                     SingleState               0         Activated                     
21:12:54	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:14:52	
21:14:52	Start realtime state tracking ...
21:14:52	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
21:14:52	Player1         Player                          PowerDown                 0         Activated                     
21:15:11	SingleState1    SingleState                     SingleState               0         Activated                     
21:15:15	Trace Test
21:15:22	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:20:57	
21:20:57	Trace Test
21:20:57	Start realtime state tracking ...
21:20:57	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
21:20:57	Player1         Player                          PowerDown                 0         Activated                     
21:20:57	SingleState1    SingleState                     SingleState               0         Activated                     
21:20:59	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:21:06	Player1         Player          PowerDown       Pause           1         6766      Hit                           
21:21:08	
21:21:08	Start realtime state tracking ...
21:21:08	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
21:21:08	Player1         Player                          PowerDown                 0         Activated                     
21:21:08	SingleState1    SingleState                     SingleState               0         Activated                     
21:21:09	Trace Test
21:21:10	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:21:10	Player1         Player          PowerDown       Pause           1         0         Hit                           
21:21:11	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:21:11	
21:21:11	Catching the current active application states ... 
21:21:11	APPLICATION     STATE           
21:21:11	SingleState1    SingleState     
21:21:11	Player1         Playing         
21:21:11	
21:21:11	Player1         Player          Pause           Playing         2         15        Hit                           
21:21:12	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:21:13	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:21:14	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:21:15	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:21:15	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:21:15	Player1         Player          Playing         Pause           2         0         Hit                           
21:21:17	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:21:17	Player1         Player          Pause           Pause           1         0         Not Matched                   
21:21:19	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:21:19	Player1         Player          Pause           Pause           1         0         Not Matched                   
21:21:22	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:21:22	
21:21:22	Catching the current active application states ... 
21:21:22	APPLICATION     STATE           
21:21:22	SingleState1    SingleState     
21:21:22	Player1         Playing         
21:21:22	
21:21:22	Player1         Player          Pause           Playing         2         15        Hit                           
21:21:23	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:21:23	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:21:23	Player1         Player          Playing         PowerDown       1         0         Hit                           
21:15:26	
21:15:27	Trace Test
21:15:27	Start realtime state tracking ...
21:15:27	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
21:15:27	Player1         Player                          PowerDown                 0         Activated                     
21:15:27	Error. No initial child state in a composite state. 
21:15:27	SingleState1    SingleState                     SingleState               0         Activated                     
21:15:28	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:15:28	Player1         Player          PowerDown       Pause           1         0         Hit                           
21:15:32	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:15:32	
21:15:32	Catching the current active application states ... 
21:15:32	APPLICATION     STATE           
21:15:32	SingleState1    SingleState     
21:15:32	Player1         Playing         
21:15:32	
21:15:32	Player1         Player          Pause           Playing         2         16        Hit                           
21:15:33	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:34	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:35	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:36	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:37	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:38	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:39	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:40	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:41	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:42	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:43	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:43	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:15:43	Player1         Player          Playing         Pause           2         0         Hit                           
21:15:45	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:15:45	Player1         Player          Pause           Pause           1         0         Not Matched                   
21:15:49	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
21:15:49	
21:15:49	Catching the current active application states ... 
21:15:49	APPLICATION     STATE           
21:15:49	SingleState1    SingleState     
21:15:49	Player1         Playing         
21:15:49	
21:15:49	Player1         Player          Pause           Playing         2         16        Hit                           
21:15:50	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:51	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:52	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:53	Player1         Player          Playing         Playing         Timeout   0         Not Matched                   
21:15:54	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
21:15:54	Player1         Player          Playing         PowerDown       1         0         Hit                           
22:10:53	
22:10:53	Trace Test
22:10:53	Start realtime state tracking ...
22:10:53	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
22:10:53	Player1         Player                          PowerDown                 0         Activated                     
22:10:53	Error. No initial child state in a composite state. 
22:10:53	SingleState1    SingleState                     SingleState               0         Activated                     
22:11:04	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
22:11:04	Player1         Player          PowerDown       Pause           1         0         Hit                           
22:12:12	
22:12:12	Start realtime state tracking ...
22:12:12	Trace Test
22:12:12	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
22:12:12	Player1         Player                          PowerDown                 0         Activated                     
22:12:12	Error. No initial child state in a composite state. 
22:12:12	SingleState1    SingleState                     SingleState               0         Activated                     
22:12:15	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
22:12:15	Player1         Player          PowerDown       Pause           1         0         Hit                           
22:12:16	SingleState1    SingleState     SingleState     SingleState     2         0         Not Matched                   
22:12:16	
22:12:16	Catching the current active application states ... 
22:12:16	APPLICATION     STATE           
22:12:16	SingleState1    SingleState     
22:12:16	Player1         Playing         
22:12:16	
22:12:16	Player1         Player          Pause           Playing         2         16        Hit                           
22:12:59	
22:12:59	Start realtime state tracking ...
22:12:59	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
22:12:59	Player1         Player                          PowerDown                 0         Activated                     
22:21:03	Trace Test
22:21:03	
22:21:03	Start realtime state tracking ...
22:21:03	APPLICATION     ROOT            SRC STATE       DEST STATE      EVENT     TIME(ms)  REASON                        
22:21:03	Player1         Player                          PowerDown                 0         Activated                     
22:21:19	Error. No initial child state in a composite state. 
22:21:19	SingleState1    SingleState                     SingleState               0         Activated                     
22:21:31	SingleState1    SingleState     SingleState     SingleState     1         0         Not Matched                   
22:21:31	Player1         Player          PowerDown       Pause           1         0         Hit                           

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
Alex "Question is more important than the answer."

Comments and Discussions