diff --git a/src/libei.c b/src/libei.c index 73d432e..2381fc9 100644 --- a/src/libei.c +++ b/src/libei.c @@ -355,8 +355,10 @@ ei_added(struct ei *ei, uint32_t deviceid, uint32_t capabilities) } } - /* FIXME: could be a device since removed by the client */ - return -EBADMSG; + /* Wrong device id or a device already removed by the client but we + * won't know which unless we keep some device ID table. Not worth + * it, so just silently ignore */ + return 0; } static int diff --git a/test/test-eis.c b/test/test-eis.c index 98e3e66..1554206 100644 --- a/test/test-eis.c +++ b/test/test-eis.c @@ -250,6 +250,55 @@ MUNIT_TEST(eistest_device_ignore_suspended) return MUNIT_OK; } +MUNIT_TEST(eistest_device_late_connect) +{ + _cleanup_peck_ struct peck *peck = peck_new(); + _cleanup_eis_device_ struct eis_device *eis_device = NULL; + _cleanup_ei_device_ struct ei_device *ei_device = NULL; + + peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_CLIENT); + peck_dispatch_until_stable(peck); + + with_client(peck) { + ei_device = ei_device_new(ei); + ei_device_configure_capability(ei_device, EI_DEVICE_CAP_POINTER); + ei_device_add(ei_device); + } + + peck_dispatch_until_stable(peck); + + with_server(peck) { + _cleanup_eis_event_ struct eis_event *added = + peck_eis_next_event(eis, EIS_EVENT_DEVICE_ADDED); + eis_device = eis_device_ref(eis_event_get_device(added)); + /* Do not connect here */ + } + + peck_dispatch_until_stable(peck); + + with_client(peck) { + ei_device_remove(ei_device); + } + + peck_dispatch_until_stable(peck); + + with_server(peck) { + eis_device_connect(eis_device); + } + + peck_dispatch_until_stable(peck); + + with_server(peck) { + peck_assert_no_eis_events(eis); + } + + with_client(peck) { + peck_assert_no_ei_events(ei); + } + + return MUNIT_OK; +} + int main(int argc, char **argv) {