names: generate names for command_status and state_peercond.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-01-22 06:41:46 +10:30
parent f48adb097e
commit c1dc7137ba
4 changed files with 45 additions and 22 deletions

20
names.c
View File

@ -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";
}

View File

@ -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 */

22
state.h
View File

@ -6,17 +6,6 @@
#include <state_types.h>
#include <stdbool.h>
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,

View File

@ -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 */