libei: rename _NEW state to _HELLO

We need a state for *before* we connected to a server (i.e. after ei_new() but
before a backend was successfully set up), so let's rename the current NEW
state to HELLO and then, later, add a NEW state for that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-07 10:52:16 +10:00
parent f0a65b3a0f
commit bc9b129e95
2 changed files with 7 additions and 7 deletions

View file

@ -34,7 +34,7 @@ struct ei_backend_interface {
};
enum ei_state {
EI_STATE_NEW, /* just connected, server sent hello */
EI_STATE_BACKEND, /* We have a backend */
EI_STATE_CONNECTING, /* client requested connect */
EI_STATE_CONNECTED, /* server has sent connect */
EI_STATE_DISCONNECTED,

View file

@ -134,7 +134,7 @@ ei_new(void *user_data)
{
_cleanup_ei_ struct ei *ei = ei_create(NULL);
ei->state = EI_STATE_NEW;
ei->state = EI_STATE_BACKEND;
list_init(&ei->event_queue);
list_init(&ei->devices);
@ -669,7 +669,7 @@ connection_dispatch(struct source *source, void *userdata)
idx += len;
switch (ei->state) {
case EI_STATE_NEW:
case EI_STATE_BACKEND:
rc = connection_new_handle_msg(ei, msg);
break;
case EI_STATE_CONNECTING:
@ -688,7 +688,7 @@ error:
ei_disconnect(ei);
static const char *states[] = {
"NEW",
"BACKEND",
"CONNECTING",
"CONNECTED",
"DISCONNECTED",
@ -714,7 +714,7 @@ ei_set_connection(struct ei *ei, int fd)
_public_ void
ei_configure_name(struct ei *ei, const char *name)
{
if (ei->state != EI_STATE_NEW)
if (ei->state != EI_STATE_BACKEND)
return;
if (strlen(name) > 1024)
@ -733,7 +733,7 @@ test_init_unref(const MunitParameter params[], void *user_data)
/* need to alloc here so unref can free */
struct ei *ei = ei_new(NULL);
munit_assert_int(ei->state, ==, EI_STATE_NEW);
munit_assert_int(ei->state, ==, EI_STATE_BACKEND);
munit_assert(list_empty(&ei->event_queue));
munit_assert(list_empty(&ei->devices));
@ -773,7 +773,7 @@ test_configure_name(const MunitParameter params[], void *user_data)
munit_assert_string_equal(ei.name, "bar");
/* ignore names in all other states */
for (enum ei_state state = EI_STATE_NEW + 1;
for (enum ei_state state = EI_STATE_HELLO + 1;
state <= EI_STATE_DISCONNECTED;
state++) {
ei.state = state;