diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-08-23 21:47:27 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-08-23 21:47:27 +0200 |
commit | 664d0f4af1ae7dae85b64a9b23f5759186412e0a (patch) | |
tree | 046ea9b2833690aef77a1526dbf82b4c580bd91f | |
parent | info: features (diff) | |
download | mds-664d0f4af1ae7dae85b64a9b23f5759186412e0a.tar.gz mds-664d0f4af1ae7dae85b64a9b23f5759186412e0a.tar.bz2 mds-664d0f4af1ae7dae85b64a9b23f5759186412e0a.tar.xz |
mds-colour: marshal colour list + implement set-colour
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-colour.c | 43 | ||||
-rw-r--r-- | src/mds-colour.h | 11 |
2 files changed, 49 insertions, 5 deletions
diff --git a/src/mds-colour.c b/src/mds-colour.c index b4b166d..bfeed41 100644 --- a/src/mds-colour.c +++ b/src/mds-colour.c @@ -178,6 +178,7 @@ size_t marshal_server_size(void) { size_t rc = 2 * sizeof(int) + sizeof(uint32_t); rc += mds_message_marshal_size(&received); + rc += colour_list_marshal_size(&colours); return rc; } @@ -197,7 +198,10 @@ int marshal_server(char* state_buf) mds_message_marshal(&received, state_buf); state_buf += mds_message_marshal_size(&received) / sizeof(char*); + colour_list_marshal(&colours, state_buf); + mds_message_destroy(&received); + colour_list_destroy(&colours); return 0; } @@ -214,15 +218,24 @@ int marshal_server(char* state_buf) */ int unmarshal_server(char* state_buf) { + int stage = 0; + /* buf_get_next(state_buf, int, MDS_COLOUR_VARS_VERSION); */ buf_next(state_buf, int, 1); buf_get_next(state_buf, int, connected); buf_get_next(state_buf, uint32_t, message_id); + fail_if (mds_message_unmarshal(&received, state_buf)); + state_buf += mds_message_marshal_size(&received) / sizeof(char*); + stage++; + + fail_if (colour_list_unmarshal(&colours, state_buf)); + return 0; fail: xperror(*argv); - mds_message_destroy(&received); + if (stage >= 0) mds_message_destroy(&received); + if (stage >= 1) colour_list_destroy(&colours); return -1; } @@ -457,18 +470,38 @@ int handle_set_colour(const char* recv_name, const char* recv_remove, const char if (strict_atou64(recv_blue, &(colour.blue), 0, limit)) return eprint("got an invalid value on the Blue-header, ignoring."), 0; - /* TODO set colour */ + return set_colour(recv_name, &colour); } else - { - /* TODO remove colour */ - } + colour_list_remove(&colours, recv_name); return 0; } /** + * Add or modify a colour + * + * @param name The name of the colour, must not be `NULL` + * @param colour The colour, must not be `NULL` + * @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) +{ + char* name_; + int r; + + if (xstrdup(name_, name)) + return -1; + r = colour_list_put(&colours, name_, colour); + if (r < 0) + free(name_); + return r; +} + + +/** * This function is called when a signal that * signals that the system to dump state information * and statistics has been received diff --git a/src/mds-colour.h b/src/mds-colour.h index c833c53..6ff0402 100644 --- a/src/mds-colour.h +++ b/src/mds-colour.h @@ -103,6 +103,17 @@ int handle_set_colour(const char* recv_name, const char* recv_remove, const char const char* recv_red, const char* recv_green, const char* recv_blue); +/** + * Add or modify a colour + * + * @param name The name of the colour, must not be `NULL` + * @param colour The colour, must not be `NULL` + * @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)); + + CREATE_HASH_LIST_SUBCLASS(colour_list, char* restrict, const char* restrict, colour_t) |