aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-colour.h
blob: 703fe5e67bf7c9814effe2c3f617cf057b48e2d5 (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
/**
 * mds — A micro-display server
 * Copyright © 2014, 2015  Mattias Andrée (maandree@member.fsf.org)
 * 
 * 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 MDS_MDS_COLOUR_H
#define MDS_MDS_COLOUR_H


#include "mds-base.h"

#include <libmdsserver/hash-list.h>

#include <stdint.h>



/**
 * Data structure for colour
 */
typedef struct colour
{
  /**
   * The value of the red channel
   */
  uint64_t red;
  
  /**
   * The value of the green channel
   */
  uint64_t green;
  
  /**
   * The value of the blue channel
   */
  uint64_t blue;
  
  /**
   * The number of bytes with which
   * each channel is encoded
   */
  int bytes;
  
} colour_t;



/**
 * Handle the received message
 * 
 * @return  Zero on success, -1 on error
 */
int handle_message(void);

/**
 * Handle the received message after it has been
 * identified to contain `Command: list-colours`
 * 
 * @param   recv_client_id       The value of the `Client ID`-header, "0:0" if omitted
 * @param   recv_message_id      The value of the `Message ID`-header
 * @param   recv_include_values  The value of the `Include values`-header, `NULL` if omitted
 * @return                       Zero on success, -1 on error
 */
int handle_list_colours(const char* recv_client_id, const char* recv_message_id,
			const char* recv_include_values);

/**
 * Handle the received message after it has been
 * identified to contain `Command: get-colour`
 * 
 * @param   recv_client_id   The value of the `Client ID`-header, "0:0" if omitted
 * @param   recv_message_id  The value of the `Message ID`-header
 * @param   recv_name        The value of the `Name`-header, `NULL` if omitted
 * @return                   Zero on success, -1 on error
 */
int handle_get_colour(const char* recv_client_id, const char* recv_message_id, const char* recv_name);

/**
 * Handle the received message after it has been
 * identified to contain `Command: set-colour`
 * 
 * @param   recv_name    The value of the `Name`-header, `NULL` if omitted
 * @param   recv_remove  The value of the `Remove`-header, `NULL` if omitted
 * @param   recv_bytes   The value of the `Bytes`-header, `NULL` if omitted
 * @param   recv_red     The value of the `Red`-header, `NULL` if omitted
 * @param   recv_green   The value of the `Green`-header, `NULL` if omitted
 * @param   recv_blue    The value of the `Blue`-header, `NULL` if omitted
 * @return               Zero on success, -1 on error
 */
int handle_set_colour(const char* recv_name, const char* recv_remove, const char* recv_bytes,
		      const char* recv_red, const char* recv_green, const char* recv_blue);

/**
 * Add, remove or modify a colour
 * 
 * @param   name    The name of the colour, must not be `NULL`
 * @param   colour  The colour, `NULL` to remove
 * @return          Zero on success, -1 on error, removal of
 *                  non-existent colour does not constitute an error
 */
int set_colour(const char* name, const colour_t* colour) __attribute__((nonnull(1)));

/**
 * Broadcast a colour list update event
 * 
 * @param   event        The event, that is, the value for the `Command`-header, must not be `NULL`
 * @param   name         The name of the colour, must not be `NULL`
 * @param   colour       The new colour, `NULL` if and only if removed
 * @param   last_update  The value on the `Last update`-header
 * @return               Zero on success, -1 on error
 */
int broadcast_update(const char* event, const char* name, const colour_t* colour,
		     const char* last_update) __attribute__((nonnull(1, 2, 4)));


CREATE_HASH_LIST_SUBCLASS(colour_list, char* restrict, const char* restrict, colour_t)


/**
 * Free the key and value of an entry in a colour list
 * 
 * @param  entry  The entry
 */
void colour_list_entry_free(colour_list_entry_t* entry);


#endif