aboutsummaryrefslogtreecommitdiffstats
path: root/libradharc.h
blob: ee00b09a9871192f92d99977ce30c84bdd272d90 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
/* See LICENSE file for copyright and license details. */
#ifndef LIBRADHARC_H
#define LIBRADHARC_H

#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <time.h>


enum libradharc_property {
	LIBRADHARC_PROPERTY_FADE_IN,
	LIBRADHARC_PROPERTY_FADE_OUT,
	LIBRADHARC_PROPERTY_HIGH_TEMPERATURE,
	LIBRADHARC_PROPERTY_LOW_TEMPERATURE,
	LIBRADHARC_PROPERTY_HIGH_ELEVATION,
	LIBRADHARC_PROPERTY_LOW_ELEVATION,
	LIBRADHARC_PROPERTY_LOCATION,
	LIBRADHARC_PROPERTY_OPERATION_MODE,
	LIBRADHARC_PROPERTY_TEMPERATURE,
	LIBRADHARC_PROPERTY_PRIORITY,
	LIBRADHARC_PROPERTY_VENDOR_OPTION,
	LIBRADHARC_PROPERTY_STATUS
};

enum libradharc_request_type {
	LIBRADHARC_REQUEST_GET,
	LIBRADHARC_REQUEST_SET,
	LIBRADHARC_REQUEST_UNSET,
	LIBRADHARC_REQUEST_SIGNAL
};

/**
 * How radharc determines which colour temperature to apply
 */
enum libradharc_operation_mode {
	/**
	 * A specific colour temperature has been selected
	 */
	LIBRADHARC_OPERATION_STATIC,

	/**
	 * A colour temperature range has been selected
	 * along with a range of solar elevations and the
	 * user's location. The temperature is changed
	 * gradually by mapping to current solar elevation's
	 * position in the range of solar elevations
	 * (clips to the range's boundaries) to a colour
	 * temperature, in corresponding position, the
	 * colour temperature range.
	 */
	LIBRADHARC_OPERATION_BY_SOLAR_ELEVATION
};

/**
 * Request response type
 */
enum libradharc_response_type {
	/**
	 * The made request was invalid
	 */
	LIBRADHARC_RESPONSE_INVALID_REQUEST,

	/**
	 * Value sent with the request was unsupported
	 */
	LIBRADHARC_RESPONSE_UNSUPPORTED,

	/**
	 * Action performed
	 */
	LIBRADHARC_RESPONSE_ACK,

	/**
	 * No action to perform
	 */
	LIBRADHARC_RESPONSE_ACK_NOOP,

	/**
	 * The requested property is not set
	 */
	LIBRADHARC_RESPONSE_UNSET,

	/**
	 * The requested property is set to the true boolean value
	 */
	LIBRADHARC_RESPONSE_YES,

	/**
	 * The requested property is set to the false boolean value
	 */
	LIBRADHARC_RESPONSE_NO,

	/**
	 * A server-side error was encountered
	 */
	LIBRADHARC_RESPONSE_ERROR_STRING,

	/**
	 * The requested property is set, and has a string value
	 */
	LIBRADHARC_RESPONSE_SET_STRING,

	/**
	 * The requested property is set, and has a time duration
	 */
	LIBRADHARC_RESPONSE_SET_TIME,

	/**
	 * The requested property is set, and has a real value
	 */
	LIBRADHARC_RESPONSE_SET_REAL,

	/**
	 * The requested property is set, and has two real values
	 * 
	 * For the geographical location, this would be the the
	 * latitude as the first value, and a the longitude as
	 * the second value
	 */
	LIBRADHARC_RESPONSE_SET_REAL_PAIR,

	/**
	 * The requested property is set, and has a signed
	 * 64-bit integer value
	 */
	LIBRADHARC_RESPONSE_SET_SIGNED64,

	/**
	 * The requested property is set, and has a named value
	 */
	LIBRADHARC_RESPONSE_SET_ENUM
};

/**
 * Response from radharc
 */
struct libradharc_response {
	/**
	 * Response from radharc or indicate of
	 * type used for the response
	 */
	enum libradharc_response_type type;

	/**
	 * Value send back by radharc
	 * 
	 * Only set if `.type` has one of the values
	 * listed the union member fields. The following
	 * values of `.type` do not have an associated
	 * value:
	 * -  `LIBRADHARC_RESPONSE_INVALID_REQUEST`
	 * -  `LIBRADHARC_RESPONSE_UNSUPPORTED`
	 * -  `LIBRADHARC_RESPONSE_ACK`
	 * -  `LIBRADHARC_RESPONSE_ACK_NOOP`
	 * -  `LIBRADHARC_RESPONSE_UNSET`
	 * -  `LIBRADHARC_RESPONSE_YES`
	 * -  `LIBRADHARC_RESPONSE_NO`
	 */
	union {
		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_STRING` or
		 * `LIBRADHARC_RESPONSE_ERROR_STRING`
		 */
		const char *string;

		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_TIME`
		 */
		struct timespec time;

		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_REAL`
		 */
		double real;

		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_REAL_PAIR`
		 */
		double real_pair[2];

		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_SIGNED64`
		 */
		int64_t signed64;

		/**
		 * Use if `.type` is `LIBRADHARC_RESPONSE_SET_ENUM`,
		 * and the response is for a get-request for radharc's
		 * operation mode
		 */
		enum libradharc_operation_mode operation_mode;
	} value;
};


/**
 * Parse a response from radharc
 * 
 * All requests generate a response, which are sent in order
 * 
 * @param   msg           The received message
 * @param   msglen        The length of the message
 * @param   response_out  Output parameter for the prased message
 * @return                0 on success, -1 on failure
 * 
 * @throws  EINVAL   `msglen` is 0
 * @throws  EINVAL   `msg` is `NULL`
 * @throws  EINVAL   `response_out` is `NULL`
 * @throws  EBADMSG  The received message is invalid
 */
int libradharc_parse_response(const void *msg, size_t msglen, struct libradharc_response *response_out);


size_t libradharc_format_request__n__(void *buffer, enum libradharc_request_type type, int what, size_t n, ...);

inline size_t
libradharc_format_request__0__(void *buffer, enum libradharc_request_type type, int what)
{
	return libradharc_format_request__n__(buffer, type, what, 0);
}

inline size_t
libradharc_format_request__1__(void *buffer, enum libradharc_request_type type, int what,
                               const void *value1, size_t size1)
{
	return libradharc_format_request__n__(buffer, type, what, 1, value1, size1);
}

inline size_t
libradharc_format_request__2__(void *buffer, enum libradharc_request_type type, int what,
                               const void *value1, size_t size1,
                               const void *value2, size_t size2)
{
	return libradharc_format_request__n__(buffer, type, what, 2, value1, size1, value2, size2);
}

inline size_t
libradharc_format_request__3__(void *buffer, enum libradharc_request_type type, int what,
                               const void *value1, size_t size1,
                               const void *value2, size_t size2,
                               const void *value3, size_t size3)
{
	return libradharc_format_request__n__(buffer, type, what, 3, value1, size1, value2, size2, value3, size3);
}

inline size_t
libradharc_format_get_request__0__(void *buffer, enum libradharc_property property)
{
	return libradharc_format_request__0__(buffer, LIBRADHARC_REQUEST_GET, (int)property);
}

inline size_t
libradharc_format_get_request__s__(void *buffer, enum libradharc_property property, const char *arg1)
{
	if (!arg1) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__1__(buffer, LIBRADHARC_REQUEST_GET, (int)property, arg1, strlen(arg1) + 1U);
}

inline size_t
libradharc_format_set_request__64i__(void *buffer, enum libradharc_property property, int64_t arg1)
{
	return libradharc_format_request__1__(buffer, LIBRADHARC_REQUEST_SET, (int)property, &arg1, sizeof(arg1));
}

inline size_t
libradharc_format_set_request__i__(void *buffer, enum libradharc_property property, int arg1)
{
	return libradharc_format_request__1__(buffer, LIBRADHARC_REQUEST_SET, (int)property, &arg1, sizeof(arg1));
}

inline size_t
libradharc_format_set_request__r__(void *buffer, enum libradharc_property property, double arg1)
{
	return libradharc_format_request__1__(buffer, LIBRADHARC_REQUEST_SET, (int)property, &arg1, sizeof(arg1));
}

inline size_t
libradharc_format_set_request__rt__(void *buffer, enum libradharc_property property, double arg1, const struct timespec *arg2)
{
	if (!arg2 || arg2->tv_sec < 0 || arg2->tv_nsec < 0 || arg2->tv_nsec >= 1000000000L) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__3__(buffer, LIBRADHARC_REQUEST_SET, property,
	                                      &arg1, sizeof(arg1),
	                                      &arg2->tv_sec, sizeof(arg2->tv_sec),
	                                      &arg2->tv_nsec, sizeof(arg2->tv_nsec));
}

inline size_t
libradharc_format_set_request__rr__(void *buffer, enum libradharc_property property, double arg1, double arg2)
{
	return libradharc_format_request__2__(buffer, LIBRADHARC_REQUEST_SET, (int)property,
	                                      &arg1, sizeof(arg1), &arg2, sizeof(arg2));
}

inline size_t
libradharc_format_set_request__s__(void *buffer, enum libradharc_property property, const char *arg1)
{
	if (!arg1) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__1__(buffer, LIBRADHARC_REQUEST_SET, (int)property,
	                                      arg1, strlen(arg1) + 1U);
}

inline size_t
libradharc_format_set_request__ss__(void *buffer, enum libradharc_property property, const char *arg1, const char *arg2)
{
	if (!arg1 || !arg2) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__2__(buffer, LIBRADHARC_REQUEST_SET, (int)property,
	                                      arg1, strlen(arg1) + 1U, arg2, strlen(arg2) + 1U);
}

inline size_t
libradharc_format_set_request__t__(void *buffer, enum libradharc_property property, const struct timespec *arg1)
{
	if (!arg1 || arg1->tv_sec < 0 || arg1->tv_nsec < 0 || arg1->tv_nsec >= 1000000000L) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__2__(buffer, LIBRADHARC_REQUEST_SET, (int)property,
	                                      &arg1->tv_sec, sizeof(arg1->tv_sec),
	                                      &arg1->tv_nsec, sizeof(arg1->tv_nsec));
}

inline size_t
libradharc_format_unset_request__0__(void *buffer, enum libradharc_property property)
{
	return libradharc_format_request__0__(buffer, LIBRADHARC_REQUEST_UNSET, (int)property);
}

inline size_t
libradharc_format_signal_request__0__(void *buffer, int signal)
{
	return libradharc_format_request__0__(buffer, LIBRADHARC_REQUEST_SIGNAL, signal);
}

inline size_t
libradharc_format_signal_request__t__(void *buffer, int signal, const struct timespec *arg1)
{
	if (!arg1 || arg1->tv_sec < 0 || arg1->tv_nsec < 0 || arg1->tv_nsec >= 1000000000L) {
		errno = EINVAL;
		return 0;
	}
	return libradharc_format_request__2__(buffer, LIBRADHARC_REQUEST_SIGNAL, signal,
	                                      &arg1->tv_sec, sizeof(arg1->tv_sec),
	                                      &arg1->tv_nsec, sizeof(arg1->tv_nsec));
}


inline size_t
libradharc_format_set_request__rnt__(void *buffer, enum libradharc_property property, double arg1, const struct timespec *arg2)
{
	if (arg2)
		return libradharc_format_set_request__rt__(buffer, property, arg1, arg2);
	else
		return libradharc_format_set_request__r__(buffer, property, arg1);
}

inline size_t
libradharc_format_set_request__sns__(void *buffer, enum libradharc_property property, const char *arg1, const char *arg2)
{
	if (arg2)
		return libradharc_format_set_request__ss__(buffer, property, arg1, arg2);
	else
		return libradharc_format_set_request__s__(buffer, property, arg1);
}

inline size_t
libradharc_format_signal_request__nt__(void *buffer, int signal, const struct timespec *arg1)
{
	if (arg1)
		return libradharc_format_signal_request__t__(buffer, signal, arg1);
	else
		return libradharc_format_signal_request__0__(buffer, signal);
}


/**
 * Format a message that instructs radharc to reconfigure
 * its effect fade-in time
 * 
 * It is unspecified how this effects any ongoing fade-in
 * 
 * @param   buffer    Output buffer for the message, or `NULL` to measure the required size
 * @param   duration  The new fade duration
 * @return            The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `duration` is `NULL`
 * @throws  EINVAL  `duration->tv_nsec` is invalid
 * @throws  EINVAL  `duration->tv_sec` is negative
 */
inline size_t
libradharc_format_set_fade_in(void *buffer, const struct timespec *duration)
{ return libradharc_format_set_request__t__(buffer, LIBRADHARC_PROPERTY_FADE_IN, duration); }

/**
 * Format a message that instructs radharc to send back
 * its currently configured effect fade-in time
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_fade_in(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_FADE_IN); }


/**
 * Format a message that instructs radharc to reconfigure
 * its effect fade-out time
 * 
 * It is unspecified how this effects any ongoing fade-out
 * 
 * @param   buffer    Output buffer for the message, or `NULL` to measure the required size
 * @param   duration  The new fade duration
 * @return            The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `duration` is `NULL`
 * @throws  EINVAL  `duration->tv_nsec` is invalid
 * @throws  EINVAL  `duration->tv_sec` is negative
 */
inline size_t
libradharc_format_set_fade_out(void *buffer, const struct timespec *duration)
{ return libradharc_format_set_request__t__(buffer, LIBRADHARC_PROPERTY_FADE_OUT, duration); }

/**
 * Format a message that instructs radharc to send back
 * its currently configured effect fade-out time
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_fade_out(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_FADE_OUT); }


/**
 * Format a message that instructs radharc to configure
 * the colour temperature that shall be applied
 * when the Sun's elevation at least at the configured
 * upper threshold of twilight, that at daytime after
 * daybreak
 * 
 * @param   buffer       Output buffer for the message, or `NULL` to measure the required size
 * @param   temperature  The colour temperature, in Kelvins, must be at least 1000
 * @return               The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_high_temperature(void *buffer, double temperature)
{ return libradharc_format_set_request__r__(buffer, LIBRADHARC_PROPERTY_HIGH_TEMPERATURE, temperature); }

/**
 * Format a message that instructs radharc to send back
 * its configured colour temperature that shall be applied
 * when the Sun's elevation at least at the configured
 * upper threshold of twilight, that at daytime after
 * daybreak
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_high_temperature(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_HIGH_TEMPERATURE); }


/**
 * Format a message that instructs radharc to configure
 * the colour temperature that shall be applied
 * when the Sun's elevation at most at the configured
 * lower threshold of twilight, that at nighttime after
 * nightfall
 * 
 * @param   buffer       Output buffer for the message, or `NULL` to measure the required size
 * @param   temperature  The colour temperature, in Kelvins, must be at least 1000
 * @return               The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_low_temperature(void *buffer, double temperature)
{ return libradharc_format_set_request__r__(buffer, LIBRADHARC_PROPERTY_LOW_TEMPERATURE, temperature); }

/**
 * Format a message that instructs radharc to send back
 * its configured colour temperature that shall be applied
 * when the Sun's elevation at most at the configured
 * lower threshold of twilight, that at nighttime after
 * nightfall
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_low_temperature(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_LOW_TEMPERATURE); }


/**
 * Format a message that instructs radharc to configure
 * the upper theshold of twilight, that is, the solar
 * elevation that marks the end of daybreak and the
 * beginning of nightfall
 * 
 * @param   buffer   Output buffer for the message, or `NULL` to measure the required size
 * @param   degrees  The solar elevation, in degrees
 * @return           The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_high_elevation(void *buffer, double degrees)
{ return libradharc_format_set_request__r__(buffer, LIBRADHARC_PROPERTY_HIGH_ELEVATION, degrees); }

/**
 * Format a message that instructs radharc to send back
 * its configured upper theshold of twilight, that is,
 * the solar elevation that marks the end of daybreak
 * and the beginning of nightfall
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_high_elevation(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_HIGH_ELEVATION); }


/**
 * Format a message that instructs radharc to configure
 * the lower theshold of twilight, that is, the solar
 * elevation that marks the end of nightfall and the
 * beginning of daybreak
 * 
 * @param   buffer   Output buffer for the message, or `NULL` to measure the required size
 * @param   degrees  The solar elevation, in degrees
 * @return           The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_low_elevation(void *buffer, double degrees)
{ return libradharc_format_set_request__r__(buffer, LIBRADHARC_PROPERTY_LOW_ELEVATION, degrees); }

/**
 * Format a message that instructs radharc to send back
 * its configured lower theshold of twilight, that is,
 * the solar elevation that marks the end of nightfall
 * and the beginning of daybreak
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_low_elevation(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_LOW_ELEVATION); }


/**
 * Format a message that instructs radharc to reconfigured
 * the geographical location
 * 
 * @param   buffer     Output buffer for the message, or `NULL` to measure the required size
 * @param   latitude   The new latitude, in degrees north of the equator according to GPS
 * @param   longitude  The new longitude, in degrees east of the prime meridian according to GPS
 * @return             The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_location(void *buffer, double latitude, double longitude)
{ return libradharc_format_set_request__rr__(buffer, LIBRADHARC_PROPERTY_LOCATION, latitude, longitude); }

/**
 * Format a message that instructs radharc to send back
 * its currently configured geographical location
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_location(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_LOCATION); }

/**
 * Format a message that instructs radharc remove its
 * currently configured geolocation, causing it to
 * freeze at the current temperature, until modified
 * or a new location is set, unless another operation
 * mode that doesn't need the user's location is being
 * used
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_unset_location(void *buffer)
{ return libradharc_format_unset_request__0__(buffer, LIBRADHARC_PROPERTY_LOCATION); }


/**
 * Format a message that instructs radharc to use another
 * operation mode
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @param   mode    The new operation mode
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_operation_mode(void *buffer, enum libradharc_operation_mode mode)
{ return libradharc_format_set_request__i__(buffer, LIBRADHARC_PROPERTY_OPERATION_MODE, (int)mode); }

/**
 * Format a message that instructs radharc to send back
 * its currently configured operation mode
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_operation_mode(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_OPERATION_MODE); }


/**
 * Format a message that instructs radharc to apply
 * a specific colour temperature
 * 
 * @param   buffer               Output buffer for the message, or `NULL` to measure the required size
 * @param   temperature          The temperature to apply, in Kelvins, must be at least 1000
 * @param   transition_duration  The transition time, or `NULL` to use the configured fade time
 *                               (it's implementation specific how it is defined)
 * @return                       The size of the message, 0 on failure
 * 
 * Implementations of radharc need not implement support for
 * smooth temperature transitions, so `transition_duration`
 * may be ignored
 */
inline size_t
libradharc_format_set_temperature(void *buffer, double temperature, const struct timespec *transition_duration)
{ return libradharc_format_set_request__rnt__(buffer, LIBRADHARC_PROPERTY_TEMPERATURE, temperature, transition_duration); }

/**
 * Format a message that instructs radharc to send back
 * its currently applied temperature
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_temperature(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_TEMPERATURE); }


/**
 * Format a message that instructs radharc to reconfigure
 * its effect priority
 * 
 * @param   buffer    Output buffer for the message, or `NULL` to measure the required size
 * @param   priority  The new priority
 * @return            The size of the message, 0 on failure
 */
inline size_t
libradharc_format_set_priority(void *buffer, int64_t priority)
{ return libradharc_format_set_request__64i__(buffer, LIBRADHARC_PROPERTY_PRIORITY, priority); }

/**
 * Format a message that instructs radharc to send back
 * its currently configured effect priority
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_priority(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_PRIORITY); }


/**
 * Format a message that instructs radharc to apply
 * or modify an implemenation specific setting
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @param   option  The name of the option
 * @param   value   The value for the option, or `NULL` if there is none
 * @return          The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `option` is `NULL`
 */
inline size_t
libradharc_format_set_vendor_option(void *buffer, const char *option, const char *value)
{ return libradharc_format_set_request__sns__(buffer, LIBRADHARC_PROPERTY_VENDOR_OPTION, option, value); }

/**
 * Format a message that instructs radharc to send
 * back the value of a implemenation specific setting
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @param   option  The name of the option
 * @return          The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `option` is `NULL`
 */
inline size_t
libradharc_format_get_vendor_option(void *buffer, const char *option)
{ return libradharc_format_get_request__s__(buffer, LIBRADHARC_PROPERTY_VENDOR_OPTION, option); }


/**
 * Format a message that instructs radharc to send back
 * its current status
 * 
 * radharc will respond with an with a single-line string,
 * but it's content is implementation defined
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_get_status(void *buffer)
{ return libradharc_format_get_request__0__(buffer, LIBRADHARC_PROPERTY_STATUS); }


/**
 * Format a message that instructs radharc to fade out its
 * effect and terminate
 * 
 * Sending this message is equivalent to sending SIGINT once,
 * except the transition duration can be overridden ad hoc,
 * or twice if `transition_duration` is `{0, 0}`
 * 
 * @param   buffer               Output buffer for the message, or `NULL` to measure the required size
 * @param   transition_duration  The transition time, or `NULL` to use the configured fade out time
 * @return                       The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `transition_duration->tv_nsec` is invalid
 * @throws  EINVAL  `transition_duration->tv_sec` is negative
 */
inline size_t
libradharc_format_smooth_terminate(void *buffer, const struct timespec *transition_duration)
{ return libradharc_format_signal_request__nt__(buffer, SIGINT, transition_duration); }

/**
 * Format a message that instructs radharc to, once any
 * current transition has take place, terminate without
 * restoring the colour temperature
 * 
 * Sending this message is equivalent to sending SIGHUP
 * 
 * @param   buffer  Output buffer for the message, or `NULL` to measure the required size
 * @return          The size of the message, 0 on failure
 */
inline size_t
libradharc_format_freeze_terminate(void *buffer)
{ return libradharc_format_signal_request__0__(buffer, SIGHUP); }

/**
 * Format a message that instructs radharc to disable itself
 * 
 * Sending this message is equivalent to sending SIGUSR1,
 * except the transition duration can be overridden ad hoc
 * 
 * @param   buffer               Output buffer for the message, or `NULL` to measure the required size
 * @param   transition_duration  The transition time, or `NULL` to use the configured fade out time
 * @return                       The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `transition_duration->tv_nsec` is invalid
 * @throws  EINVAL  `transition_duration->tv_sec` is negative
 */
inline size_t
libradharc_format_disable(void *buffer, const struct timespec *transition_duration)
{ return libradharc_format_signal_request__nt__(buffer, SIGUSR1, transition_duration); }

/**
 * Format a message that instructs radharc to enable itself
 * 
 * Sending this message is equivalent to sending SIGUSR2,
 * except the transition duration can be overridden ad hoc
 * 
 * @param   buffer               Output buffer for the message, or `NULL` to measure the required size
 * @param   transition_duration  The transition time, or `NULL` to use the configured fade in time
 * @return                       The size of the message, 0 on failure
 * 
 * @throws  EINVAL  `transition_duration->tv_nsec` is invalid
 * @throws  EINVAL  `transition_duration->tv_sec` is negative
 */
inline size_t
libradharc_format_enable(void *buffer, const struct timespec *transition_duration)
{ return libradharc_format_signal_request__nt__(buffer, SIGUSR2, transition_duration); }

#endif