Commit graph

65 commits

Author SHA1 Message Date
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
Peter Hutterer
7e6afe2373 tools: make the socket server example take a socket path
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 16:18:24 +10:00
Peter Hutterer
8078424c14 meson: fix header installation and pkgconfig libraries
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 16:18:24 +10:00
Peter Hutterer
31581eb110 tools: terminate the example server correctly on SIGINT
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 16:18:24 +10:00
Peter Hutterer
802dfd4ca6 Add the minimal implementation for a UNIX socket libei client
This is the minimum framework to support connecting to a libeis server, adding
a device and sending relative pointer motion events.It's missing a bunch of
checks and verifications, many of the hooks are still missing, etc.

See the tools/ directory for an example. The protocol is as outlined in
commit f7a24b2fbd.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 16:18:24 +10:00
Peter Hutterer
27670000e4 libeis: only log client state transitions if they changed
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 11:52:23 +10:00
Peter Hutterer
247b6d0dcb libeis: fix wrong message field assignment
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 10:59:07 +10:00
Peter Hutterer
b79f309a6c libeis: whitespace fix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 09:59:11 +10:00
Peter Hutterer
90722a12ce tools: handle multiple events after a single dispatch()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 09:44:45 +10:00
Peter Hutterer
693b3767f2 tools: handle device removal
Well, print it, anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 09:43:06 +10:00