From 1fdb7e6d1cf0709b1079b2d9990c0d53d8740461 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Fri, 4 Jun 2021 12:46:15 +0200 Subject: #915 Add commands and procedures to procedure creation Adds the possibility to create a procedure with commands and other procedures integrated as steps. Note: "steps" parameter is optional and "steps" array object order defines execution order. Request: POST /procedure/add { "center": "1", "name": "procedure", "description": "My procedure", "steps": [ { "command": "wol", "params": { "type": "broadcast" } }, { "procedure": 22 }, { "command": "poweroff", "params": {} } ] } Response: 200 OK This commit also updates unit tests for /procedure/add POST method to include steps. --- src/json.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/json.h') diff --git a/src/json.h b/src/json.h index 08a78d0..0e98a6e 100644 --- a/src/json.h +++ b/src/json.h @@ -98,4 +98,31 @@ struct og_cmd_json { uint32_t flags; }; +enum og_procedure_step_type { + OG_STEP_COMMAND = 0, + OG_STEP_PROCEDURE, +}; + +#define OG_PROCEDURE_STEPS_MAX 256 + +struct og_procedure_step { + enum og_procedure_step_type type; + uint32_t position; + + union { + struct og_cmd_json cmd; + struct { + uint64_t id; + } procedure; + }; +}; + +struct og_procedure { + uint64_t id; + struct og_procedure_step steps[OG_PROCEDURE_STEPS_MAX]; + uint32_t num_steps; +}; + +int og_json_parse_procedure(json_t *element, struct og_procedure *proc); + #endif -- cgit v1.2.3-18-g5258