Commit graph

74 commits

Author SHA1 Message Date
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
Peter Hutterer
68fe48c02f README: make a note about the Xwayland PoC and short-lived apps
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 14:02:33 +10:00
Peter Hutterer
9f851bcccb Replace the custom message parsing with protobuf
Plain-text was useful for the initial implementation where the counterpart was
netcat but now that both parts are in place, protobuf is a much more
convenient system to handle a frequently-changing protocol.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 13:05:11 +10:00
Peter Hutterer
f94a7bae85 test: add a test for the util-io helpers
Using munit via a wrap file, let's see if that test suite is scalable to what
we want.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 13:05:11 +10:00
Peter Hutterer
0426c99278 util: add some documentation for the iobuf helpers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 13:05:11 +10:00
Peter Hutterer
2931f0fd13 util: fix the fd reading
buf is the iobuf pointer, we need to check whether we read sizeof(data) bytes
before looping around to fetch more.

And fix the return value for a zero read, because that could either be EAGAIN
or EOF.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 13:05:11 +10:00
Peter Hutterer
81b82fcbd4 meson.build: drop spaces before colon
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-31 09:41:29 +10:00
Peter Hutterer
3c7820baca libeis: only remove the source on disconnect, don't destroy it
Removed sources will be cleaned up at the end of dispatch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 21:17:54 +10:00
Peter Hutterer
708ad85dd4 util: remove the source from the removed_list on destroy
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 21:17:49 +10:00
Peter Hutterer
6a0f25e72a utils: update the buffer length when appending data
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 21:02:07 +10:00
Peter Hutterer
8ec0f4bf7c Send the trailing null byte for composed string messages
The iobuf treats this as binary data but then we're using it as strings in the
message parsing code. So make sure all messages have a trailing null byte.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 21:01:09 +10:00
Peter Hutterer
1817071b5a tools: default to the LIBEI_SOCKET if present
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 15:38:40 +10:00
Peter Hutterer
1bdca21772 libeis: remove the socket on exit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 15:38:40 +10:00
Peter Hutterer
6062a0f676 libei: take the LIBEI_SOCKET variable if the socket path is NULL
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 15:38:40 +10:00
Peter Hutterer
b1231dfa1f libei: add a hook to configure the client name
Better than the current "myclient". Lacks safety and whatnot so long-term it
will have to get replaced with something else.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-30 15:38:40 +10:00
Peter Hutterer
f228927b1f README: add some clarification for why libei
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 20:56:47 +10:00