Commit graph

89 commits

Author SHA1 Message Date
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
Peter Hutterer
48f2f5e4c7 libei: 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 14:53:08 +10:00
Peter Hutterer
311bc6b4fc libei: rename to ei_setup_backend_socket()
Now that the backend is more of an implementation detail, namespace for
ei_setup_backend_foo()

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:52:54 +10:00
Peter Hutterer
283cc87416 libei: switch to a single ei_new() function
The main reason for having different functions to create the initial context
was so we can nest the ei struct inside the context-specific struct. That
shouldn't leak into the API though and our use-case is probably one where we
create one context, then iterate through possible backends until one succeds -
having different contexts here doesn't help then.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00
Peter Hutterer
6a164dfb3a test: remove an unnecssary arg for the iotest
That's what copy/pasting does... this argument is the user_data pointer which
we don't care about here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00
Peter Hutterer
0ab1458241 test: add some internal unit-tests to libei
Similar in style to Rust where the unit tests are in the same file. Let's see
how far we can get with that in C. Auto-discovery of tests by forcing the
respective suites into a special test section so we can collect it later from
our unit runner.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00
Peter Hutterer
b4552374ca libei: documentation updates
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00
Peter Hutterer
6dc848b2c3 libei: add a few comments and extra checks
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00
Peter Hutterer
b5f1082419 libei: implement a few missing functions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-04 10:53:38 +10:00
Peter Hutterer
4f0637f726 libei: switch to passive naming for accepted/removed messages
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-04 10:29:33 +10:00
Peter Hutterer
cb192945d2 Make the button events carry event codes, not indices
Brings this more in line with libinput and, well, everything on linux, really.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 20:46:13 +10:00
Peter Hutterer
39fcf16ec8 tools: add key events to the example client
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 12:04:00 +10:00
Peter Hutterer
a9f07368a5 Implement pointer button and keyboard key events
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 12:00:31 +10:00
Peter Hutterer
81d4556dcc proto: add a fixed-length frame message
protobuf relies on external framing and exact buffer lengths to parse things
correctly. So let's provide that by sending a fixed-length Frame message
before every real message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 11:59:05 +10:00
Peter Hutterer
cf6dec8e15 proto: add a protocol specification
Just so it's a bit more obvious what sequences we expect

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 07:55:25 +10:00
Peter Hutterer
718beb926e utils: Rename OBJECT_DECLARE... to OBJECT_IMPLEMENT
More technically correct since that's what all these crazy macros do.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 07:34:52 +10:00
Peter Hutterer
6610319832 Add a missing empty line
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-03 07:32:32 +10:00
Peter Hutterer
40682a0420 Use send() instead of write() to prevent SIGPIPE
We're in a library here, so expecting the caller to handle SIGPIPE just in
case we get it is a bit demanding. Let's use send() instead so we can just
prevent that altogether.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 14:27:18 +10:00
Peter Hutterer
9f4827135d Process multiple messages in one dispatch
We may get more than one message per dispatch so let's make sure we iterate
through all the available data.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 14:14:21 +10:00