aboutsummaryrefslogtreecommitdiffstats
path: root/state.h
blob: 6273bdb06af279dac4b3f6683ab94b87926b7f7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* See LICENSE file for copyright and license details. */
#ifndef STATE_H
#define STATE_H

#include "types-message.h"
#include "types-ring.h"
#include "types-output.h"

#include <libgamma.h>

#include <stddef.h>
#include <signal.h>

#ifndef GCC_ONLY
# if defined(__GNUC__) && !defined(__clang__)
#  define GCC_ONLY(...) __VA_ARGS__
# else
#  define GCC_ONLY(...) /* nothing */
# endif
#endif

/**
 * The name of the process
 */
extern char *restrict argv0;

/**
 * The real pathname of the process's binary,
 * `NULL` if `argv0` is satisfactory
 */
extern char *restrict argv0_real;

/**
 * Array of all outputs
 */
extern struct output *restrict outputs;

/**
 * The nubmer of elements in `outputs`
 */
extern size_t outputs_n;

/**
 * The server socket's file descriptor
 */
extern int socketfd;

/**
 * Has the process receive a signal
 * telling it to re-execute?
 */
extern volatile sig_atomic_t reexec;

/**
 * Has the process receive a signal
 * telling it to terminate?
 */
extern volatile sig_atomic_t terminate;

/**
 * Has the process receive a to
 * disconnect from or reconnect to
 * the site? 1 if disconnect, 2 if
 * reconnect, 0 otherwise.
 */
extern volatile sig_atomic_t connection;

/**
 * List of all client's file descriptors
 * 
 * Unused slots, with index less than `connections_used`,
 * should have the value -1 (negative)
 */
extern int *restrict connections;

/**
 * The number of elements allocated for `connections`
 */
extern size_t connections_alloc;

/**
 * The index of the first unused slot in `connections`
 */
extern size_t connections_ptr;

/**
 * The index of the last used slot in `connections`, plus 1
 */
extern size_t connections_used;

/**
 * The clients' connections' inbound-message buffers
 */
extern struct message *restrict inbound;

/**
 * The clients' connections' outbound-message buffers
 */
extern struct ring *restrict outbound;

/**
 * Is the server connect to the display?
 * 
 * Set to true before the initial connection
 */
extern int connected;

/**
 * The adjustment method, -1 for automatic
 */
extern int method;

/**
 * The site's name, may be `NULL`
 */
extern char *restrict sitename;

/**
 * The libgamma site state
 */
extern struct libgamma_site_state site;

/**
 * The libgamma partition states
 */
extern struct libgamma_partition_state *restrict partitions;

/**
 * The libgamma CRTC states
 */
extern struct libgamma_crtc_state *restrict crtcs;

/**
 * Preserve gamma ramps at priority 0?
 */
extern int preserve;

/**
 * Dump the state to stderr
 */
void state_dump(void);

/**
 * Destroy the state
 */
void state_destroy(void);

/**
 * Marshal the state
 * 
 * @param   buf  Output buffer for the marshalled data,
 *               `NULL` to only measure how many bytes
 *               this buffer needs
 * @return       The number of marshalled bytes
 */
size_t state_marshal(void *restrict buf);

/**
 * Unmarshal the state
 * 
 * @param   buf  Buffer for the marshalled data
 * @return       The number of unmarshalled bytes, 0 on error
 */
GCC_ONLY(__attribute__((__nonnull__)))
size_t state_unmarshal(const void *restrict buf);

#endif