FreeRDP
Loading...
Searching...
No Matches
TestPubSub.c
1
2#include <winpr/crt.h>
3#include <winpr/thread.h>
4#include <winpr/collections.h>
5
6DEFINE_EVENT_BEGIN(MouseMotion)
7int x;
8int y;
9DEFINE_EVENT_END(MouseMotion)
10
11DEFINE_EVENT_BEGIN(MouseButton)
12int x;
13int y;
14int flags;
15int button;
16DEFINE_EVENT_END(MouseButton)
17
18static void MouseMotionEventHandler(void* context, const MouseMotionEventArgs* e)
19{
20 printf("MouseMotionEvent: x: %d y: %d\n", e->x, e->y);
21}
22
23static void MouseButtonEventHandler(void* context, const MouseButtonEventArgs* e)
24{
25 printf("MouseButtonEvent: x: %d y: %d flags: %d button: %d\n", e->x, e->y, e->flags, e->button);
26}
27
28static wEventType Node_Events[] = { DEFINE_EVENT_ENTRY(MouseMotion),
29 DEFINE_EVENT_ENTRY(MouseButton) };
30
31#define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEventType))
32
33int TestPubSub(int argc, char* argv[])
34{
35 wPubSub* node = nullptr;
36
37 WINPR_UNUSED(argc);
38 WINPR_UNUSED(argv);
39
40 node = PubSub_New(TRUE);
41 if (!node)
42 return -1;
43
44 PubSub_AddEventTypes(node, Node_Events, NODE_EVENT_COUNT);
45
46 if (PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler) < 0)
47 return -1;
48 if (PubSub_SubscribeMouseButton(node, MouseButtonEventHandler) < 0)
49 return -1;
50
51 /* Call Event Handler */
52 {
53 MouseMotionEventArgs e;
54
55 e.x = 64;
56 e.y = 128;
57
58 PubSub_OnMouseMotion(node, nullptr, &e);
59 }
60
61 {
62 MouseButtonEventArgs e;
63
64 e.x = 23;
65 e.y = 56;
66 e.flags = 7;
67 e.button = 1;
68
69 PubSub_OnMouseButton(node, nullptr, &e);
70 }
71
72 PubSub_Free(node);
73
74 return 0;
75}