GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_proxy_cli.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2/*
3
4 Copyright (c) 2019-2020 Cyril Hrubis <metan@ucw.cz>
5
6 */
7
8#ifndef GP_PROXY_CLI_H
9#define GP_PROXY_CLI_H
10
11#include <utils/gp_list.h>
12#include <utils/gp_poll.h>
13#include <backends/gp_proxy_proto.h>
14
15struct gp_event;
16
17typedef struct gp_proxy_cli {
18 gp_fd fd;
19
20 char *name;
21
22 gp_dlist_head head;
23
24 /* Connection buffer */
25 gp_proxy_buf buf;
26} gp_proxy_cli;
27
28static inline void gp_proxy_cli_show(gp_proxy_cli *self)
29{
30 if (!self)
31 return;
32
33 gp_proxy_send(self->fd.fd, GP_PROXY_SHOW, NULL);
34}
35
36static inline void gp_proxy_cli_hide(gp_proxy_cli *self)
37{
38 if (!self)
39 return;
40
41 gp_proxy_send(self->fd.fd, GP_PROXY_HIDE, NULL);
42}
43
44static inline void gp_proxy_cli_event(gp_proxy_cli *self, gp_event *ev)
45{
46 if (gp_proxy_send(self->fd.fd, GP_PROXY_EVENT, ev))
47 GP_WARN("Dropping event");
48}
49
50static inline int gp_proxy_cli_send(gp_proxy_cli *self,
51 enum gp_proxy_msg_types type,
52 void *payload)
53{
54 return gp_proxy_send(self->fd.fd, type, payload);
55}
56
57struct gp_proxy_cli_ops {
58 void (*update)(gp_proxy_cli *self, gp_coord x, gp_coord y, gp_size w, gp_size h);
59 void (*on_unmap)(gp_proxy_cli *self);
60 void (*on_map)(gp_proxy_cli *self);
61 void (*on_hide)(gp_proxy_cli *self);
62 void (*on_show)(gp_proxy_cli *self);
63};
64
65/*
66 * Has to be called when there are data ready at cli->fd.
67 *
68 * @self Pointer to a client.
69 * @return Zero on success, non-zero otherwise.
70 */
71int gp_proxy_cli_read(gp_proxy_cli *self, struct gp_proxy_cli_ops *ops);
72
73/*
74 * Adds a new client to the clients list pointed by root pointer.
75 *
76 * @root Root of double linked list of connected clients.
77 * @cli_fd Client file descriptor.
78 * @return A pointer to a newly allocated client.
79 */
80gp_proxy_cli *gp_proxy_cli_add(gp_dlist *clients, int cli_fd);
81
82/*
83 * Removes client from a list of clients.
84 *
85 * @root Root of double linked list of connected clients.
86 * @self A client to be removed.
87 */
88void gp_proxy_cli_rem(gp_dlist *clients, gp_proxy_cli *self);
89
90#endif /* GP_PROXY_CLI_H */
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
unsigned int gp_size
Integer type for sizes i.e. w, h, ...
Definition gp_types.h:24
#define GP_WARN(...)
A debug WARN printf-like macro.
Definition gp_debug.h:104
A linked list implementation.
A simple epoll wrapper.
An epoll file descriptor.
Definition gp_poll.h:70