Mercurial > louis > mq > lightsd
changeset 229:1a2bd9fc41b1
a couple new patches
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Sat, 08 Aug 2015 14:37:39 -0700 |
parents | a655a3b88d62 |
children | dae19f5f6e44 |
files | add_toggle.patch fix_a_snprintf_return_value_check.patch series |
diffstat | 3 files changed, 120 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_toggle.patch Sat Aug 08 14:37:39 2015 -0700 @@ -0,0 +1,99 @@ +# HG changeset patch +# Parent f53e8ce62db97a7c4f33e370bab4c0b243d91311 +Add the toggle command: turn on a bulb if it's off and vice-versa + +This lets you change the state of a bulb without having to query its +state first, super useful with the command pipe. + +diff --git a/core/jsonrpc.c b/core/jsonrpc.c +--- a/core/jsonrpc.c ++++ b/core/jsonrpc.c +@@ -965,6 +965,19 @@ + } + + static void ++lgtd_jsonrpc_check_and_call_toggle(struct lgtd_client *client) ++{ ++ struct lgtd_proto_target_list targets = SLIST_HEAD_INITIALIZER(&targets); ++ bool ok = lgtd_jsonrpc_extract_target_list(&targets, client); ++ if (!ok) { ++ return; ++ } ++ ++ lgtd_proto_toggle(client, &targets); ++ lgtd_proto_target_list_clear(&targets); ++} ++ ++static void + lgtd_jsonrpc_check_and_call_get_light_state(struct lgtd_client *client) + { + struct lgtd_proto_target_list targets = SLIST_HEAD_INITIALIZER(&targets); +@@ -1074,6 +1087,10 @@ + lgtd_jsonrpc_check_and_call_power_off + ), + LGTD_JSONRPC_METHOD( ++ "toggle", 1, // t ++ lgtd_jsonrpc_check_and_call_toggle ++ ), ++ LGTD_JSONRPC_METHOD( + "set_light_from_hsbk", 6, // t, h, s, b, k, t + lgtd_jsonrpc_check_and_call_set_light_from_hsbk + ), +diff --git a/core/proto.c b/core/proto.c +--- a/core/proto.c ++++ b/core/proto.c +@@ -71,6 +71,35 @@ + } + + void ++lgtd_proto_toggle(struct lgtd_client *client, ++ const struct lgtd_proto_target_list *targets) ++{ ++ assert(targets); ++ ++ struct lgtd_router_device_list *devices = NULL; ++ devices = lgtd_router_targets_to_devices(targets); ++ if (!devices) { ++ lgtd_client_send_error( ++ client, LGTD_CLIENT_INTERNAL_ERROR, "couldn't allocate memory" ++ ); ++ return; ++ } ++ ++ struct lgtd_router_device *device; ++ SLIST_FOREACH(device, devices, link) { ++ struct lgtd_lifx_bulb *bulb = device->device; ++ struct lgtd_lifx_packet_power_state pkt = { ++ .power = ~bulb->state.power ++ }; ++ lgtd_router_send_to_device(bulb, LGTD_LIFX_SET_POWER_STATE, &pkt); ++ } ++ ++ SEND_RESULT(client, true); ++ ++ lgtd_router_device_list_free(devices); ++} ++ ++void + lgtd_proto_power_off(struct lgtd_client *client, + const struct lgtd_proto_target_list *targets) + { +@@ -329,7 +358,6 @@ + ); + fini: + lgtd_router_device_list_free(devices); +- return; + } + + void +diff --git a/core/proto.h b/core/proto.h +--- a/core/proto.h ++++ b/core/proto.h +@@ -38,6 +38,7 @@ + int, float, int, bool); + void lgtd_proto_power_on(struct lgtd_client *, const struct lgtd_proto_target_list *); + void lgtd_proto_power_off(struct lgtd_client *, const struct lgtd_proto_target_list *); ++void lgtd_proto_toggle(struct lgtd_client *, const struct lgtd_proto_target_list *); + void lgtd_proto_get_light_state(struct lgtd_client *, const struct lgtd_proto_target_list *); + void lgtd_proto_tag(struct lgtd_client *, const struct lgtd_proto_target_list *, const char *); + void lgtd_proto_untag(struct lgtd_client *, const struct lgtd_proto_target_list *, const char *);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fix_a_snprintf_return_value_check.patch Sat Aug 08 14:37:39 2015 -0700 @@ -0,0 +1,19 @@ +# HG changeset patch +# Parent c2a45e03f05e05e7c31723254ca63b82df551bda +Fix an incorrectly check snprintf return value. + +In this case we would have returned some invalid output instead of +skipping one bulb. + +diff --git a/core/proto.c b/core/proto.c +--- a/core/proto.c ++++ b/core/proto.c +@@ -195,7 +195,7 @@ + bulb->state.power == LGTD_LIFX_POWER_ON ? "true" : "false", + bulb->state.label + ); +- if (written == sizeof(buf)) { ++ if (written >= sizeof(buf)) { + lgtd_warnx( + "can't send state of bulb %s (%s) to client " + "[%s]:%hu: output buffer to small",