| 248 | } |
| 249 | |
| 250 | static struct command_result *json_wait(struct command *cmd, |
| 251 | const char *buffer, |
| 252 | const jsmntok_t *obj UNNEEDED, |
| 253 | const jsmntok_t *params) |
| 254 | { |
| 255 | struct waiter *waiter = tal(cmd, struct waiter); |
| 256 | u64 val; |
| 257 | |
| 258 | if (!param(cmd, buffer, params, |
| 259 | p_req("subsystem", param_subsystem, |
| 260 | &waiter->subsystem), |
| 261 | p_req("indexname", param_index, &waiter->index), |
| 262 | p_req("nextvalue", param_u64, &waiter->nextval), |
| 263 | NULL)) |
| 264 | return command_param_failed(); |
| 265 | |
| 266 | /* Are we there already? Return immediately. */ |
| 267 | val = *wait_index_ptr(cmd->ld, *waiter->subsystem, *waiter->index); |
| 268 | if (val >= *waiter->nextval) { |
| 269 | struct json_stream *response; |
| 270 | |
| 271 | response = json_stream_success(cmd); |
| 272 | json_add_index(cmd, response, |
| 273 | *waiter->subsystem, |
| 274 | *waiter->index, |
| 275 | val, NULL); |
| 276 | return command_success(cmd, response); |
| 277 | } |
| 278 | |
| 279 | waiter->cmd = cmd; |
| 280 | list_add_tail(&cmd->ld->wait_commands, &waiter->list); |
| 281 | log_trace(cmd->ld->log, "waiting on %s %s %"PRIu64, |
| 282 | wait_subsystem_name(*waiter->subsystem), |
| 283 | wait_index_name(*waiter->index), |
| 284 | *waiter->nextval); |
| 285 | return command_still_pending(cmd); |
| 286 | } |
| 287 | |
| 288 | static const struct json_command wait_command = { |
| 289 | "wait", |
nothing calls this directly
no test coverage detected