From c1dc7137ba11cb56f4e725d1b0e60be7c09a8dbd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:41:46 +1030 Subject: [PATCH] names: generate names for command_status and state_peercond. Signed-off-by: Rusty Russell --- names.c | 20 ++++++++++++++++++++ names.h | 2 ++ state.h | 22 ---------------------- state_types.h | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/names.c b/names.c index c382818c7..f4926692c 100644 --- a/names.c +++ b/names.c @@ -21,3 +21,23 @@ const char *input_name(enum state_input in) return enum_state_input_names[i].name; return "unknown"; } + +const char *cstatus_name(enum command_status cstatus) +{ + size_t i; + + for (i = 0; enum_command_status_names[i].name; i++) + if (enum_command_status_names[i].v == cstatus) + return enum_command_status_names[i].name; + return "unknown"; +} + +const char *peercond_name(enum state_peercond peercond) +{ + size_t i; + + for (i = 0; enum_state_peercond_names[i].name; i++) + if (enum_state_peercond_names[i].v == peercond) + return enum_state_peercond_names[i].name; + return "unknown"; +} diff --git a/names.h b/names.h index 60c06cf7f..b102ef4ca 100644 --- a/names.h +++ b/names.h @@ -5,4 +5,6 @@ const char *state_name(enum state s); const char *input_name(enum state_input in); +const char *cstatus_name(enum command_status cstatus); +const char *peercond_name(enum state_peercond peercond); #endif /* LIGHTNING_NAMES_H */ diff --git a/state.h b/state.h index ef54f5ecc..7682f63d2 100644 --- a/state.h +++ b/state.h @@ -6,17 +6,6 @@ #include #include -enum state_peercond { - /* Ready to accept a new command. */ - PEER_CMD_OK, - /* Don't send me commands, I'm busy. */ - PEER_BUSY, - /* No more commands, I'm closing. */ - PEER_CLOSING, - /* No more packets, I'm closed. */ - PEER_CLOSED -}; - enum state_effect_type { STATE_EFFECT_broadcast_tx, STATE_EFFECT_send_pkt, @@ -111,17 +100,6 @@ union input { struct htlc_progress *htlc_prog; }; -enum command_status { - /* Nothing changed. */ - CMD_NONE, - /* Command succeeded. */ - CMD_SUCCESS, - /* HTLC-command needs re-issuing (theirs takes preference) */ - CMD_REQUEUE, - /* Failed. */ - CMD_FAIL -}; - enum command_status state(const tal_t *ctx, struct peer *peer, const enum state_input input, diff --git a/state_types.h b/state_types.h index 36f7d1af4..cf15f1e5c 100644 --- a/state_types.h +++ b/state_types.h @@ -279,4 +279,27 @@ enum state_input { INPUT_MAX }; + +enum state_peercond { + /* Ready to accept a new command. */ + PEER_CMD_OK, + /* Don't send me commands, I'm busy. */ + PEER_BUSY, + /* No more commands, I'm closing. */ + PEER_CLOSING, + /* No more packets, I'm closed. */ + PEER_CLOSED +}; + +enum command_status { + /* Nothing changed. */ + CMD_NONE, + /* Command succeeded. */ + CMD_SUCCESS, + /* HTLC-command needs re-issuing (theirs takes preference) */ + CMD_REQUEUE, + /* Failed. */ + CMD_FAIL +}; + #endif /* LIGHTNING_STATE_TYPES_H */