2013-01-25 00:08:49 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/thread.h>
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
static DWORD WINAPI message_queue_consumer_thread(LPVOID arg)
|
2013-01-25 00:08:49 +04:00
|
|
|
{
|
|
|
|
wMessage message;
|
|
|
|
wMessageQueue* queue;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
queue = (wMessageQueue*)arg;
|
2013-01-25 00:08:49 +04:00
|
|
|
|
|
|
|
while (MessageQueue_Wait(queue))
|
|
|
|
{
|
|
|
|
if (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
2013-02-04 23:56:54 +04:00
|
|
|
if (message.id == WMQ_QUIT)
|
2013-01-25 00:08:49 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("Message.Type: %" PRIu32 "\n", message.id);
|
2013-01-25 00:08:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
return 0;
|
2013-01-25 00:08:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int TestMessageQueue(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
HANDLE thread;
|
|
|
|
wMessageQueue* queue;
|
|
|
|
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
if (!(queue = MessageQueue_New(NULL)))
|
|
|
|
{
|
|
|
|
printf("failed to create message queue\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-25 00:08:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(thread = CreateThread(NULL, 0, message_queue_consumer_thread, (void*)queue, 0, NULL)))
|
2015-05-05 14:55:48 +03:00
|
|
|
{
|
|
|
|
printf("failed to create thread\n");
|
|
|
|
MessageQueue_Free(queue);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-25 00:08:49 +04:00
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
if (!MessageQueue_Post(queue, NULL, 123, NULL, NULL) ||
|
2019-11-06 17:24:51 +03:00
|
|
|
!MessageQueue_Post(queue, NULL, 456, NULL, NULL) ||
|
|
|
|
!MessageQueue_Post(queue, NULL, 789, NULL, NULL) || !MessageQueue_PostQuit(queue, 0) ||
|
|
|
|
WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0)
|
2015-05-23 23:47:18 +03:00
|
|
|
return -1;
|
2013-01-25 00:08:49 +04:00
|
|
|
|
|
|
|
MessageQueue_Free(queue);
|
2015-05-05 14:55:48 +03:00
|
|
|
CloseHandle(thread);
|
2013-01-25 00:08:49 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|