1/*
2 * Copyright (c) 2014 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include <stdint.h>
27#include <unistd.h>
28
29#include "wayland-server.h"
30#include "wayland-client.h"
31
32/* info about a client on server side */
33struct client_info {
34 struct display *display;
35 struct wl_client *wl_client;
36 struct wl_listener destroy_listener;
37 const char *name; /* for debugging */
38
39 int pipe;
40 pid_t pid;
41 int exit_code;
42
43 struct wl_list link;
44 void *data; /* for arbitrary use */
45};
46
47struct display {
48 struct wl_display *wl_display;
49 struct wl_global *test_global;
50
51 struct wl_list clients;
52 uint32_t clients_no;
53 uint32_t clients_terminated_no;
54
55 /* list of clients waiting for display_resumed event */
56 struct wl_list waiting_for_resume;
57 uint32_t wfr_num;
58};
59
60/* This is a helper structure for clients.
61 * Instead of calling wl_display_connect() and all the other stuff,
62 * client can use client_connect and it will return this structure
63 * filled. */
64struct client {
65 struct wl_display *wl_display;
66 struct test_compositor *tc;
67
68 int display_stopped;
69};
70
71struct client *client_connect(void);
72void client_disconnect(struct client *);
73int stop_display(struct client *, int);
74void noop_request(struct client *);
75
76/**
77 * Usual workflow:
78 *
79 * d = display_create();
80 *
81 * wl_global_create(d->wl_display, ...);
82 * ... other setups ...
83 *
84 * client_create(d, client_main, data);
85 * client_create(d, client_main2, data);
86 *
87 * display_run(d);
88 * display_destroy(d);
89 */
90struct display *display_create(void);
91void display_destroy(struct display *d);
92void display_run(struct display *d);
93
94/* This function posts the display_resumed event to all waiting clients,
95 * so that after flushing events the clients will stop waiting and continue.
96 *
97 * (Calling `display_run` after this function will resume the display loop.)
98 */
99void display_post_resume_events(struct display *d);
100/* After n clients called stop_display(..., n), the display
101 * is stopped and can process the code after display_run().
102 *
103 * This function posts the display_resumed event to the waiting
104 * clients, so that the clients will stop waiting and continue;
105 * it then reruns the display. */
106void display_resume(struct display *d);
107
108
109struct client_info *client_create_with_name(struct display *d,
110 void (*client_main)(void *data),
111 void *data,
112 const char *name);
113#define client_create(d, c, data) client_create_with_name((d), (c), data, (#c))
114#define client_create_noarg(d, c) \
115 client_create_with_name((d), (void(*)(void *)) (c), NULL, (#c))
116

source code of gtk/subprojects/wayland/tests/test-compositor.h