Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotplug: allow button timeout actions to trigger a subsequent timeout #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion plug/hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ static struct cmd_handler {
},
};

/* This is a non-public handler used when a button event
* return a non-zero value, which is used as a timeout
* to subsequently call the same script.
*/
static struct cmd_handler BUTTON_TIMEOUT_HANDLER = {
.name = "button_timeout",
.handler = handle_exec,
.complete = handle_button_complete,
};


static void queue_next(void)
{
struct cmd_queue *c;
Expand Down Expand Up @@ -441,13 +452,15 @@ static void handle_button_timeout(struct uloop_timeout *t)
blobmsg_add_string(&button_buf, "ACTION", "timeout");
snprintf(seen, sizeof(seen), "%d", b->seen);
blobmsg_add_string(&button_buf, "SEEN", seen);
queue_add(&handlers[HANDLER_EXEC], button_buf.head, b->data);
queue_add(&BUTTON_TIMEOUT_HANDLER, button_buf.head, b->data);
button_free(b);
}

static void handle_button_complete(struct blob_attr *msg, struct blob_attr *data, int ret)
{
char *name = hotplug_msg_find_var(msg, "BUTTON");
char *action = hotplug_msg_find_var(msg, "ACTION");
char *seen = hotplug_msg_find_var(msg, "SEEN");
struct button_timeout *b;
int timeout = ret >> 8;

Expand All @@ -465,6 +478,13 @@ static void handle_button_complete(struct blob_attr *msg, struct blob_attr *data
b->name = strdup(name);
b->seen = timeout;

if (action && seen && (!strcmp(action, "timeout") || !strcmp(action, "released"))) {
/* If this happening due to a previous timeout or a released action,
* then we should add on the previous SEEN time.
*/
b->seen += atoi(seen);
}

memcpy(b->data, data, blob_pad_len(data));
b->timeout.cb = handle_button_timeout;

Expand Down