aboutsummaryrefslogtreecommitdiffstats
path: root/src/state.h
blob: 0a09023f962a8dcdfc2956a1600f9141cb303379 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
 * coopgammad -- Cooperative gamma server
 * Copyright (C) 2016  Mattias Andrée (maandree@kth.se)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#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 disconnct, 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 libgamma_site_state_t site;

/**
 * The libgamma partition states
 */
extern libgamma_partition_state_t* restrict partitions;

/**
 * The libgamma CRTC states
 */
extern libgamma_crtc_state_t* restrict crtcs;



/**
 * 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