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 = NULL;
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 PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler);
47 PubSub_SubscribeMouseButton(node, MouseButtonEventHandler);
48
49 /* Call Event Handler */
50 {
51 MouseMotionEventArgs e;
52
53 e.x = 64;
54 e.y = 128;
55
56 PubSub_OnMouseMotion(node, NULL, &e);
57 }
58
59 {
60 MouseButtonEventArgs e;
61
62 e.x = 23;
63 e.y = 56;
64 e.flags = 7;
65 e.button = 1;
66
67 PubSub_OnMouseButton(node, NULL, &e);
68 }
69
70 PubSub_Free(node);
71
72 return 0;
73}