Commit graph

107 commits

Author SHA1 Message Date
Peter Hutterer
3db476930b Add a bunch of log_debug messages
We can remove those when we have a working implementation, for now it's too
painful to debug when an exchange doesn't  work for some reason.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
57a9892f5d eis: send the removed deviceid down the wire
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:13:14 +10:00
Peter Hutterer
2a98906b32 util: add name lookup to tristate handling
And make it more obvious that _val isn't something you should access directly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:06:34 +10:00
Peter Hutterer
b717837b14 Downgrade the ECANCELED warning to a mere info
ECANCELED is used for any time the other end disconnects, so it's not really
an error.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:06:07 +10:00
Peter Hutterer
ce51392241 test: fix the device add test
Check that we're actually adding the device and getting the message back

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 10:51:30 +10:00
Peter Hutterer
55246512f0 Add capabilities to the Added event
This makes it possible for the server to limit capabilities.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 19:32:34 +10:00
Peter Hutterer
fb707a3395 Add a prefix to the logger
Makes it easier to distinguish between ei and eis when everything in the tests
is just printed to stderr anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 13:50:13 +10:00
Peter Hutterer
6f75463261 Rename "accepted" to "added" for consistency with the public API
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:49:22 +10:00
Peter Hutterer
2631854dbb libreis: update the API docs a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:42:25 +10:00
Peter Hutterer
12a04fa657 libei: update the API docs a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:40:53 +10:00
Peter Hutterer
fe22b9b5a5 proto: specify that the protocol isn't batch-compatible after all
The protocol itself could work like originally described here but there's a
stumbling block: the decision on whether to accept a device is made by the
caller through EIS_EVENT_DEVICE_ADDED and the following eis_device_connect()
call. We cannot process any events from that device until that call is
complete and that effectively disallows batch submission of requests.

To allow batching we'd have to pause the protocol but that means missing out
on other devices (and their events) and disconnect events. The alternative to
that would be for libeis to peek at incoming requests and sort them by device
ID so we only pause one device's stream but now we're also mangling the device
event order and potentially triggering all sorts of side-effects.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:04:05 +10:00
Peter Hutterer
626a13268e test: switch to SOCK_STREAM for the test sockets
SOCK_DGRAM gives us free message framing but the sockets we'll likely deal
with (or at least *have* to handle) are stream. This was a leftover anyway
from some debug testing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:56:10 +10:00
Peter Hutterer
427d58a664 util: add a missing include to util-io.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:06:23 +10:00
Peter Hutterer
4cfa6e6225 Add configuration messages to the protocol
For the Portal case, we'll have the portal open the sockets for us and then
(depending on policy) restrict what the client can do. Then the socket can be
passed to the client with e.g. keyboards disabled and the client is none the
wiser (other than that the server will reject any keyboard caps).

Since the portal doesn't need a EI context, the configuration is a separate
small library.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:05:57 +10:00
Peter Hutterer
5d99d858bf libeis: a device in NEW state must be disconnected too
NEW means "client has sent request" which means we have a ref to it internally
and we have to disconnect it accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 15:05:40 +10:00
Peter Hutterer
2f855c568c Drop the "hello" message
The main purpose of that was for (plain-text protocol) debugging. With the
current intentions to "preload" a connection with restrictions, having the
server initiate a connection is not useful.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
92737f7762 libeis: fix a crasher if the socket is removed before a listener starts
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
9c2c912353 util: change the sources API to source_new and sink_add_source
This is a more explicit API that makes it more obvious where the ref/unref
calls need to go. The sink now has two refs to the sources as well (epoll data
pointer and the list) which means a caller cannot just source_unref() anymore
without removing a source. Since this is how we've been using it anyway - meh.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
9d18f04e9b libeis: drain events before destroying the context
Avoid valgrind complaining about memleaks - disconnecting the clients on the
final unref queues emulated events so let's make sure we get rid of those.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
69546a4802 libei: discard all events on the final unref
ei_disconnect() may queue an event during destroy, so let's get rid of that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
e6b410a56a test: drain all events before exiting
We don't want valgrind to complain about leaks when we only handle a portion
of the events on the socket.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
1c5d6c1e2b libei: free all devices on context removal
This requires a new state so we can differ between having a connection and not
having one.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
11be8c7a2f libeis: disconnect clients on context destroy
Less important to properly disconnect them, more important that the client
structs are freed when we do this.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 11:37:51 +10:00
Peter Hutterer
e754c75ef2 test: fix a leaking client name in the unit tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 11:37:51 +10:00
Peter Hutterer
35d676e7f7 libeis: fix the client ref handling and move the list to the eis context
Let the context take care of adding the device so we have better separation
here. Removal isn't handled in a special way because any list node can remove
itself safel anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 11:37:51 +10:00
Peter Hutterer
119b9c74b0 test: fix a memleak in the unit tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 11:37:51 +10:00
Peter Hutterer
6d46c55df3 More source ref fixes
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 11:37:51 +10:00
Peter Hutterer
bc9b129e95 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>
2020-08-07 11:37:51 +10:00
Peter Hutterer
f0a65b3a0f test: add a test for the sources utility functions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 09:42:37 +10:00
Peter Hutterer
89408c9e2e util: add a realloc helper
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 09:42:08 +10:00
Peter Hutterer
d017eb1a91 Fix the sources ref handling again
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 09:41:37 +10:00
Peter Hutterer
e860d24763 Add a test suite 2020-08-06 16:20:35 +10:00
Peter Hutterer
ebd41833cb util: add a tristate helper
Yet another crazy macro that allows to define a logical tristate.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:49:06 +10:00
Peter Hutterer
42546acf3f libei: fix the source ref handling
Plugs a memleak in libeis where we don't care about the return value of the
source_add_autoclose().

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
ba9b0bb903 eis: implement an fd backend
Caller opens the socket, passes it to eis, done.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
ad721d342a util: fix the example for DEFINE_TRIVIAL_CLEANUP_FUNC
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
9ee00ada3a eis: implement eis_peek_event() and eis_next_event_type()
Motivation for peek is the same as for libei - the upcoming test suite needs
to check a few things before actually dequeuing the event.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
5631abfc77 util: add flag_set and flag_clear helpers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
2e4ce7008b libei: implement ei_peek_event()
At least for the test suite, I'll need something that allows me to look at an
event without removing it from the event queue. Just the event type isn't
enough, I need things like "what are the caps on the device". Simplest way to
allow this is a peek function that doesn't remove the event from the queue.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
fb03ac78a2 libei: implement device_get_name()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:19:03 +10:00
Peter Hutterer
69448e247c libeis: rename to eis_setup_backend_socket()
Now that the backend is more of an implementation detail, namespace for
eis_setup_backend_foo()

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
cb976a2f95 tools: fix a few memleaks on errors
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
261f8c910b utils: rename the sources close behavior for extra clarity
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
8a0bec7b87 libei: fix source removal on ei_disconnect
The sink dispatch() loop gets the source from the epollfd data pointer, so
unref'ing the source would cause it to be destroyed when we may try to access
it later. Fix the whole source ownership properly, the first ref is owned by
the epollfd and moves to the list of removed sources, the caller gets the
second ref.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
15cf73ad11 libei: remove unused connection field
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
d2ecf43abd libeis: switch to a single eis_new() function
The main reason for having different functions to create the initial context
was so we can nest the eis struct inside the context-specific struct. That
shouldn't leak into the API though.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
bc5be06549 libei: add a backend to work off a single fd
For the case where someone else opens the sockets for us - like a test suite
or eventually the portal.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
48cbc48a38 tools: stop immediately on a disconnect event
We shouldn't get any events after this anyway, so the real-world impact here
is limited.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
e98e931615 libeis: don't ref the event on return
We're removing it from our own list when returning the event, so increasing
the refcount isn't required.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00
Peter Hutterer
562f2b4579 libeis: handle other events during unref
Refcounting error means we never hit this code, so let's fix it before we fix
the refcounting.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 15:12:19 +10:00