FreeRDP
TestMessageQueue.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/thread.h>
4 #include <winpr/collections.h>
5 
6 static DWORD WINAPI message_queue_consumer_thread(LPVOID arg)
7 {
8  wMessage message = { 0 };
9  wMessageQueue* queue = (wMessageQueue*)arg;
10 
11  while (MessageQueue_Wait(queue))
12  {
13  if (MessageQueue_Peek(queue, &message, TRUE))
14  {
15  if (message.id == WMQ_QUIT)
16  break;
17 
18  printf("Message.Type: %" PRIu32 "\n", message.id);
19  }
20  }
21 
22  return 0;
23 }
24 
25 int TestMessageQueue(int argc, char* argv[])
26 {
27  HANDLE thread = NULL;
28  wMessageQueue* queue = NULL;
29 
30  WINPR_UNUSED(argc);
31  WINPR_UNUSED(argv);
32 
33  if (!(queue = MessageQueue_New(NULL)))
34  {
35  printf("failed to create message queue\n");
36  return 1;
37  }
38 
39  if (!(thread = CreateThread(NULL, 0, message_queue_consumer_thread, (void*)queue, 0, NULL)))
40  {
41  printf("failed to create thread\n");
42  MessageQueue_Free(queue);
43  return 1;
44  }
45 
46  if (!MessageQueue_Post(queue, NULL, 123, NULL, NULL) ||
47  !MessageQueue_Post(queue, NULL, 456, NULL, NULL) ||
48  !MessageQueue_Post(queue, NULL, 789, NULL, NULL) || !MessageQueue_PostQuit(queue, 0) ||
49  WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0)
50  return -1;
51 
52  MessageQueue_Free(queue);
53  (void)CloseHandle(thread);
54 
55  return 0;
56 }