FreeRDP
TestPubSub.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/thread.h>
4 #include <winpr/collections.h>
5 
6 DEFINE_EVENT_BEGIN(MouseMotion)
7 int x;
8 int y;
9 DEFINE_EVENT_END(MouseMotion)
10 
11 DEFINE_EVENT_BEGIN(MouseButton)
12 int x;
13 int y;
14 int flags;
15 int button;
16 DEFINE_EVENT_END(MouseButton)
17 
18 static void MouseMotionEventHandler(void* context, const MouseMotionEventArgs* e)
19 {
20  printf("MouseMotionEvent: x: %d y: %d\n", e->x, e->y);
21 }
22 
23 static 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 
28 static wEventType Node_Events[] = { DEFINE_EVENT_ENTRY(MouseMotion),
29  DEFINE_EVENT_ENTRY(MouseButton) };
30 
31 #define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEventType))
32 
33 int 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 }