proto: rename ei_connection_setup to ei_handshake

This is a better name for the initial handshake and easier to
distinguish from the ei_connection this way too.

Suggested by Jonas Ådahl.
This commit is contained in:
Peter Hutterer 2023-02-28 07:48:47 +10:00
parent f9446e8c02
commit 35f5fa102c
14 changed files with 372 additions and 372 deletions

View file

@ -89,7 +89,7 @@ src_libei = files(
'src/brei-shared.c',
'src/libei.c',
'src/libei-callback.c',
'src/libei-connection-setup.c',
'src/libei-handshake.c',
'src/libei-connection.c',
'src/libei-device.c',
'src/libei-event.c',
@ -144,7 +144,7 @@ src_libeis = files(
'src/libeis.c',
'src/libeis-callback.c',
'src/libeis-client.c',
'src/libeis-connection-setup.c',
'src/libeis-handshake.c',
'src/libeis-connection.c',
'src/libeis-device.c',
'src/libeis-event.c',

View file

@ -39,7 +39,7 @@
- all integers are in the EIS implementation's native byte order.
- length is the length of the message in bytes, including the 8 header bytes
- sender-id is the id of the object sending the request/event. The sender-id
0 is reserved for the special "ei_connection_setup" object.
0 is reserved for the special "ei_handshake" object.
- opcode is the event or request-specific opcode, starting at 0.
requests and events have overlapping opcode ranges, i.e. the first request
and the first event both have opcode 0.
@ -87,32 +87,32 @@
Initial Connection:
The initial connection is a two-step process:
An ei_connection_setup object with the special ID 0 is guaranteed to
An ei_handshake object with the special ID 0 is guaranteed to
exists. The client must send the appropriate requests to set up
its connection, followed by the .finish request. The server replies
by creating the ei_connection object with the client-requested version
(or any lower version) that is the connection for the remainder of this
client.
Version negotiation for interfaces is also handled in the ei_connection_setup
Version negotiation for interfaces is also handled in the ei_handshake
object. The client announces which interfaces are supported and their
respective version, future server-created objects will use that version or any
lower version.
In summary, a typical client connection does:
- connect to the socket
- read ei_connection_setup.version for object id 0
- send ei_connection_setup.interface for "ei_connection"
- send ei_connection_setup.interface for all other supported interfaces
- optionally: send ei_connection_setup.name and ei_connection_setup.context_type
- send ei_connection_setup.finish
- read ei_handshake.version for object id 0
- send ei_handshake.interface for "ei_connection"
- send ei_handshake.interface for all other supported interfaces
- optionally: send ei_handshake.name and ei_handshake.context_type
- send ei_handshake.finish
- receive the ei_connection.connection event and create that object
- receive ei_connection.seat (if any seats are available)
- ....
- receive ei_connection.disconnect and close the socket
As of version 1 for most interfaces, the typical object tree looks like this:
- ei_connection_setup (destroyed after .connection)
- ei_handshake (destroyed after .connection)
- ei_connection
- ei_seat
- ei_device
@ -127,14 +127,14 @@
- ei_callback (destroyed after .done)
-->
<interface name="ei_connection_setup" version="1">
<description summary="connection setup object">
<interface name="ei_handshake" version="1">
<description summary="handshake object">
This is a special interface to setup the client as seen by the EIS
implementation. The object for this interface has the fixed object
id 0 and only exists until the connection has been set up, see the
ei_connection_setup.connection event.
ei_handshake.connection event.
The ei_connection_setup version is 1 until:
The ei_handshake version is 1 until:
- the EIS implementation sends the interface_version event with
a version other than 1, and, in response,
- the client sends the interface_version request with a
@ -143,18 +143,18 @@
The EIS implementation must send the interface_version event immediately
once the physical connection has been established.
Once the ei_connection.connection event has been sent the connection setup
Once the ei_connection.connection event has been sent the handshake
is destroyed by the EIS implementation.
</description>
<!-- ei_connection_setup client requests version 1 -->
<!-- ei_handshake client requests version 1 -->
<request name="finish" since="1">
<description summary="setup completion request">
Notify the EIS implementation that configuration is complete.
In the future (and possibly after requiring user interaction),
the EIS implementation responds by sending the ei_connection_setup.connection event.
the EIS implementation responds by sending the ei_handshake.connection event.
</description>
</request>
@ -181,7 +181,7 @@
This request is optional, the default client type is context_type.receiver.
This request must not be sent more than once and must be sent before
ei_connection_setup.finish.
ei_handshake.finish.
</description>
<arg name="context_type" type="uint32" enum="context_type" summary="the client context type"/>
</request>
@ -201,7 +201,7 @@
This request is optional, the default client name is implementation-defined.
This request must not be sent more than once and must be sent before
ei_connection_setup.finish.
ei_handshake.finish.
</description>
<arg name="name" type="string" summary="the client name"/>
</request>
@ -216,13 +216,13 @@
This request must be sent for the "ei_connection" interface,
failing to do so will result in the EIS implementation disconnecting
the client on ei_connection_setup.finish.
the client on ei_handshake.finish.
If the "ei_connection_setup" version is given, the interface of this
If the "ei_handshake" version is given, the interface of this
object is upgraded to the given version. Otherwise, the
ei_connection_setup version defaults to 1.
ei_handshake version defaults to 1.
A client must not provide a "ei_connection_setup" version higher
A client must not provide a "ei_handshake" version higher
than the EIS implementation sent immediately after connection.
Note that an EIS implementation may consider some interfaces to
@ -230,13 +230,13 @@
not supporting those interfaces.
This request must not be sent more than once per interface and must be
sent before ei_connection_setup.finish.
sent before ei_handshake.finish.
</description>
<arg name="name" type="string" summary="the interface name"/>
<arg name="version" type="uint32" summary="the interface version"/>
</request>
<!-- ei_connection_setup events version 1 -->
<!-- ei_handshake events version 1 -->
<event name="interface_version" since="1">
<description summary="interface support event">
@ -244,20 +244,20 @@
the given named interface with the given maximum version number.
This event is sent immediately after connection to the EIS implementation
for the "ei_connection_setup" interface. In response, the client may
send the interface_version request for the "ei_connection_setup" interface
for the "ei_handshake" interface. In response, the client may
send the interface_version request for the "ei_handshake" interface
with any version up to including the version provided in that event.
Once the request has been sent, the client must assume the negotiated
version number for the ei_connection_setup interface and the server
version number for the ei_handshake interface and the server
may send events and process requests matching that version.
A client should not issue any requests until negotiating the version for
the "ei_connection_setup" interface.
the "ei_handshake" interface.
Note that the EIS implementation assumes that the supported
client version of the "ei_connection_setup" interface is 1 unless and
client version of the "ei_handshake" interface is 1 unless and
until the client announces a higher version of this interface in the
ei_connection_setup.interface_version request.
ei_handshake.interface_version request.
This event must be sent by the EIS implementation for any
interfaces that supports client-created objects (e.g. "ei_callback").
@ -266,7 +266,7 @@
This event may be sent by the EIS implementation for any
other supported interface (but not necessarily all supported
interfaces) before the ei_connection_setup.connection event.
interfaces) before the ei_handshake.connection event.
</description>
<arg name="name" type="string" summary="the interface name"/>
<arg name="version" type="uint32" summary="the interface version"/>
@ -278,14 +278,14 @@
object for all future requests and events.
This event is sent exactly once at some unspecified time after the client
sends the ei_connection_setup.finish request to the EIS implementation.
sends the ei_handshake.finish request to the EIS implementation.
The ei_connection_setup object will be destroyed by the
The ei_handshake object will be destroyed by the
EIS implementation immediately after this event has been sent, a
client must not attempt to use it after that point.
The version sent by the server is the version of the "ei_connection"
interface as announced by ei_connection_setup.interface_version, or any
interface as announced by ei_handshake.interface_version, or any
lower version.
The serial number is the start value of the EIS implementation's serial
@ -306,7 +306,7 @@
with the EIS implementation.
Note that for a client to receive this object, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_connection client requests version 1 -->
@ -328,7 +328,7 @@
The callback_data passed in the callback is always zero.
Note that for a client to use this request it must announce
support for the "ei_callback" interface in ei_connection_setup.interface.
support for the "ei_callback" interface in ei_handshake.interface.
It is a protocol violation to request sync without having announced the
"ei_callback" interface and the EIS implementation must disconnect
the client.
@ -409,9 +409,9 @@
A seat is a set of input devices that logically belong together.
This event is only sent if the client announced support for the
"ei_seat" interface in ei_connection_setup.interface.
"ei_seat" interface in ei_handshake.interface.
The interface version is equal or less to the client-supported
version in ei_connection_setup.interface for the "ei_seat"
version in ei_handshake.interface for the "ei_seat"
interface.
</description>
<arg name="seat" type="new_id" interface="ei_seat"/>
@ -452,7 +452,7 @@
such the client must not attempt to use it after that point.
Note that for a server to use this request the client must announce
support for this interface in ei_connection_setup.interface. It is
support for this interface in ei_handshake.interface. It is
a protocol violation to send this event to a client without the
"ei_pingpong" interface.
</description>
@ -469,7 +469,7 @@
the related request that created the ei_callback object is done.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_callback events version 1 -->
@ -491,7 +491,7 @@
the EIS implementation to enforce a roundtrip to the client.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_pingpong client requests version 1 -->
@ -523,7 +523,7 @@
ei_seat.done event.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_seat client requests version 1 -->
@ -605,9 +605,9 @@
Notification that a new device has been added.
This event is only sent if the client announced support for the
"ei_device" interface in ei_connection_setup.interface_version.
"ei_device" interface in ei_handshake.interface_version.
The interface version is equal or less to the client-supported
version in ei_connection_setup.interface for the "ei_device"
version in ei_handshake.interface for the "ei_device"
interface.
</description>
<arg name="device" type="new_id" interface="ei_device" summary="the new device"/>
@ -621,14 +621,14 @@
an ei_device may have multiple capabilities and may e.g. function as pointer
and keyboard.
Depending on the ei_connection_setup.context_type, an ei_device can
Depending on the ei_handshake.context_type, an ei_device can
emulate events via client requests or receive events. It is a protocol violation
to emulate certain events on a receiver device, or for the EIS implementation
to send certain events to the device. See the individual request/event documentation
for details.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_device client requests version 1 -->
@ -670,7 +670,7 @@
intermediate stop_emulating.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="last_serial" type="uint32" summary="the last serial sent by the EIS implementation"/>
<arg name="sequence" type="uint32"/>
@ -682,7 +682,7 @@
events. See ei_device.start_emulating for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="last_serial" type="uint32" summary="the last serial sent by the EIS implementation"/>
</request>
@ -702,7 +702,7 @@
The timestamp must be in microseconds of CLOCK_MONOTONIC.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="last_serial" type="uint32" summary="the last serial sent by the EIS implementation"/>
<arg name="timestamp" type="uint64" summary="timestamp in microseconds"/>
@ -842,9 +842,9 @@
ei_device.capabilities.pointer_absolute capability.
This event is only sent if the client announced support for the
"ei_pointer" interface in ei_connection_setup.interface.
"ei_pointer" interface in ei_handshake.interface.
The interface version is equal or less to the client-supported
version in ei_connection_setup.interface for the "ei_pointer"
version in ei_handshake.interface for the "ei_pointer"
interface.
This event is optional and sent immediately after object creation.
@ -862,9 +862,9 @@
ei_device.capabilities.keyboard.
This event is only sent if the client announced support for the
"ei_keyboard" interface in ei_connection_setup.interface.
"ei_keyboard" interface in ei_handshake.interface.
The interface version is equal or less to the client-supported
version in ei_connection_setup.interface for the "ei_keyboard"
version in ei_handshake.interface for the "ei_keyboard"
interface.
This event is optional and sent immediately after object creation.
@ -882,9 +882,9 @@
ei_device.capabilities.touchscreen.
This event is only sent if the client announced support for the
"ei_touchscreen" interface in ei_connection_setup.interface.
"ei_touchscreen" interface in ei_handshake.interface.
The interface version is equal or less to the client-supported
version in ei_connection_setup.interface for the "ei_touchscreen"
version in ei_handshake.interface for the "ei_touchscreen"
interface.
This event is optional and sent immediately after object creation.
@ -906,7 +906,7 @@
<event name="resumed" since="1">
<description summary="device resumed notification">
Notification that the device has been resumed by the EIS implementation
and (depending on the ei_connection_setup.context_type) the client may request
and (depending on the ei_handshake.context_type) the client may request
ei_device.start_emulating or the EIS implementation may
ei_device.start_emulating events.
@ -952,7 +952,7 @@
See the ei_device.start_emulating request for details.
It is a protocol violation to send this event for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="serial" type="uint32" summary="this event's serial number"/>
<arg name="sequence" type="uint32"/>
@ -963,7 +963,7 @@
See the ei_device.stop_emulating request for details.
It is a protocol violation to send this event for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="serial" type="uint32" summary="this event's serial number"/>
</event>
@ -973,7 +973,7 @@
See the ei_device.frame request for details.
It is a protocol violation to send this event for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="serial" type="uint32" summary="this event's serial number"/>
<arg name="timestamp" type="uint64" summary="timestamp in microseconds"/>
@ -991,7 +991,7 @@
the device) if the interface is releasd.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_pointer client requests version 1 -->
@ -1015,7 +1015,7 @@
the ei_device.capabilities.pointer capability.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="x" type="float" summary="the x movement in logical pixels"/>
<arg name="y" type="float" summary="the y movement in logical pixels"/>
@ -1034,7 +1034,7 @@
the ei_device.capabilities.pointer_absolute capability.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="x" type="float" summary="the x position in logical pixels"/>
<arg name="y" type="float" summary="the y position in logical pixels"/>
@ -1051,7 +1051,7 @@
within the same ei_device.frame.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="x" type="float" summary="the x movement in logical pixels"/>
<arg name="y" type="float" summary="the y movement in logical pixels"/>
@ -1072,7 +1072,7 @@
within the same ei_device.frame.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="x" type="int32" summary="the x movement in fractions or multiple of 120"/>
<arg name="y" type="int32" summary="the y movement in fractions or multiple of 120"/>
@ -1101,7 +1101,7 @@
in the current frame.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="x" type="uint32" summary="nonzero if this axis stopped scrolling"/>
<arg name="y" type="uint32" summary="nonzero if this axis stopped scrolling"/>
@ -1123,7 +1123,7 @@
within the same ei_device.frame.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="button" type="uint32" summary="button code"/>
<arg name="state" type="uint32" enum="button_state"/>
@ -1148,7 +1148,7 @@
See the ei_pointer.motion_relative request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="x" type="float"/>
<arg name="y" type="float"/>
@ -1159,7 +1159,7 @@
See the ei_pointer.motion_absolute request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="x" type="float"/>
<arg name="y" type="float"/>
@ -1170,7 +1170,7 @@
See the ei_pointer.scroll request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="x" type="float"/>
<arg name="y" type="float"/>
@ -1181,7 +1181,7 @@
See the ei_pointer.scroll_discrete request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="x" type="int32"/>
<arg name="y" type="int32"/>
@ -1192,7 +1192,7 @@
See the ei_pointer.scroll_stop request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="x" type="uint32"/>
<arg name="y" type="uint32"/>
@ -1204,7 +1204,7 @@
See the ei_pointer.button request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="button" type="uint32"/>
<arg name="state" type="uint32" enum="button_state"/>
@ -1223,7 +1223,7 @@
the device) if the interface is releasd.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_keyboard client requests version 1 -->
@ -1252,7 +1252,7 @@
within the same ei_device.frame.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than sender.
of an ei_handshake.context_type other than sender.
</description>
<arg name="key" type="uint32" summary="the key code"/>
<arg name="state" type="uint32" enum="key_state" summary="logical state of the key"/>
@ -1284,7 +1284,7 @@
<description summary="keymap notification">
Notification that this device has a keymap. Future key events must be
interpreted by the client according to this keymap. For clients
of ei_connection_setup.context_type sender it is the client's
of ei_handshake.context_type sender it is the client's
responsibility to send the correct ei_keyboard.key keycodes to
generate the expected keysym in the EIS implementation.
@ -1309,7 +1309,7 @@
See the ei_keyboard.key request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="key" type="uint32"/>
<arg name="state" type="uint32" enum="key_state"/>
@ -1350,7 +1350,7 @@
the device) if the interface is releasd.
Note that for a client to receive objects of this type, it must announce
support for this interface in ei_connection_setup.interface.
support for this interface in ei_handshake.interface.
</description>
<!-- ei_touchscreen client requests version 1 -->
@ -1421,7 +1421,7 @@
See the ei_touchscreen.down request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="touchid" type="uint32"/>
<arg name="x" type="float"/>
@ -1433,7 +1433,7 @@
See the ei_touchscreen.motion request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="touchid" type="uint32"/>
<arg name="x" type="float"/>
@ -1445,7 +1445,7 @@
See the ei_touchscreen.up request for details.
It is a protocol violation to send this request for a client
of an ei_connection_setup.context_type other than receiver.
of an ei_handshake.context_type other than receiver.
</description>
<arg name="touchid" type="uint32"/>
</event>

View file

@ -1,189 +0,0 @@
/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2023 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN connection_setup WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include <errno.h>
#include <stdbool.h>
#include "util-bits.h"
#include "util-macros.h"
#include "util-mem.h"
#include "util-io.h"
#include "util-strings.h"
#include "util-version.h"
#include "libei-private.h"
#include "ei-proto.h"
static void
ei_connection_setup_destroy(struct ei_connection_setup *connection_setup)
{
struct ei *ei = ei_connection_setup_get_context(connection_setup);
ei_unregister_object(ei, &connection_setup->proto_object);
}
OBJECT_IMPLEMENT_REF(ei_connection_setup);
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_connection_setup);
OBJECT_IMPLEMENT_GETTER(ei_connection_setup, user_data, void*);
OBJECT_IMPLEMENT_SETTER(ei_connection_setup, user_data, void*);
OBJECT_IMPLEMENT_GETTER_AS_REF(ei_connection_setup, proto_object, const struct brei_object *);
static
OBJECT_IMPLEMENT_CREATE(ei_connection_setup);
static
OBJECT_IMPLEMENT_PARENT(ei_connection_setup, ei);
struct ei*
ei_connection_setup_get_context(struct ei_connection_setup *connection_setup)
{
assert(connection_setup);
return ei_connection_setup_parent(connection_setup);
}
uint32_t
ei_connection_setup_get_version(struct ei_connection_setup *connection_setup)
{
return connection_setup->proto_object.version;
}
static int
ei_connection_setup_initialize(struct ei_connection_setup *setup, uint32_t version)
{
struct ei *ei = ei_connection_setup_get_context(setup);
if (version >= EI_CONNECTION_SETUP_REQUEST_CONTEXT_TYPE_SINCE_VERSION)
ei_connection_setup_request_context_type(setup,
ei->is_sender ?
EI_CONNECTION_SETUP_CONTEXT_TYPE_SENDER :
EI_CONNECTION_SETUP_CONTEXT_TYPE_RECEIVER);
if (version >= EI_CONNECTION_SETUP_REQUEST_NAME_SINCE_VERSION)
ei_connection_setup_request_name(setup, ei->name);
if (version >= EI_CONNECTION_SETUP_REQUEST_INTERFACE_VERSION_SINCE_VERSION) {
struct ei_interface_versions *v = &ei->interface_versions;
ei_connection_setup_request_interface_version(setup, "ei_connection_setup", v->ei_connection_setup);
ei_connection_setup_request_interface_version(setup, "ei_connection", v->ei_connection);
ei_connection_setup_request_interface_version(setup, "ei_callback", v->ei_callback);
ei_connection_setup_request_interface_version(setup, "ei_pingpong", v->ei_pingpong);
ei_connection_setup_request_interface_version(setup, "ei_seat", v->ei_seat);
ei_connection_setup_request_interface_version(setup, "ei_device", v->ei_device);
ei_connection_setup_request_interface_version(setup, "ei_pointer", v->ei_pointer);
ei_connection_setup_request_interface_version(setup, "ei_keyboard", v->ei_keyboard);
ei_connection_setup_request_interface_version(setup, "ei_touchscreen", v->ei_touchscreen);
}
ei_connection_setup_request_finish(setup);
return 0;
}
static struct brei_result *
handle_msg_interface_version(struct ei_connection_setup *setup, const char *name, uint32_t version)
{
struct ei *ei = ei_connection_setup_get_context(setup);
struct ei_interface_versions *v = &ei->interface_versions;
if (streq(name, "ei_connection_setup")) {
uint32_t min_version = min(version, ei->interface_versions.ei_connection_setup);
v->ei_connection_setup = min_version;
/* Now upgrade our protocol object to the server version (if applicable) */
setup->proto_object.version = min_version;
/* Now send all the bits we need to send */
ei_connection_setup_initialize(setup, min_version);
}
#define VERSION_UPDATE(iface_) if (streq(name, #iface_)) v->iface_ = min(version, v->iface_);
else VERSION_UPDATE(ei_connection)
else VERSION_UPDATE(ei_callback)
else VERSION_UPDATE(ei_pingpong)
else VERSION_UPDATE(ei_seat)
else VERSION_UPDATE(ei_device)
else VERSION_UPDATE(ei_pointer)
else VERSION_UPDATE(ei_keyboard)
else VERSION_UPDATE(ei_touchscreen)
#undef VERSION_UPDATE
return NULL;
}
static void
connected(struct ei_connection *connection, void *user_data)
{
struct ei *ei = ei_connection_get_context(connection);
/* If we get here, the server didn't immediately disconnect us */
if (ei->state == EI_STATE_DISCONNECTED)
return;
ei_connected(ei);
}
static struct brei_result *
handle_msg_connection(struct ei_connection_setup *setup, uint32_t serial, uint32_t id, uint32_t version)
{
struct ei *ei = ei_connection_setup_get_context(setup);
assert(setup == ei->connection_setup);
/* we're done with our connection setup, drop it */
ei_connection_setup_unref(steal(&ei->connection_setup));
ei->connection = ei_connection_new(ei, id, version);
ei->state = EI_STATE_CONNECTING;
ei_update_serial(ei, serial);
/* Send a sync on the connection - EIS should immediately send a
* disconnect event where applicable, so if we get through to our
* sync callback, we didn't immediately get disconnected */
ei_connection_sync(ei->connection, connected, NULL);
return NULL;
}
static const struct ei_connection_setup_interface interface = {
.interface_version = handle_msg_interface_version,
.connection = handle_msg_connection,
};
const struct ei_connection_setup_interface *
ei_connection_setup_get_interface(struct ei_connection_setup *connection_setup) {
return &interface;
}
struct ei_connection_setup *
ei_connection_setup_new(struct ei *ei, uint32_t version)
{
struct ei_connection_setup *connection_setup = ei_connection_setup_create(&ei->object);
connection_setup->proto_object.id = ei_get_new_id(ei);
assert(connection_setup->proto_object.id == 0); /* Special object */
connection_setup->proto_object.implementation = connection_setup;
connection_setup->proto_object.interface = &ei_connection_setup_proto_interface;
connection_setup->proto_object.version = version;
ei_register_object(ei, &connection_setup->proto_object);
return connection_setup; /* ref owned by caller */
}

189
src/libei-handshake.c Normal file
View file

@ -0,0 +1,189 @@
/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2023 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include <errno.h>
#include <stdbool.h>
#include "util-bits.h"
#include "util-macros.h"
#include "util-mem.h"
#include "util-io.h"
#include "util-strings.h"
#include "util-version.h"
#include "libei-private.h"
#include "ei-proto.h"
static void
ei_handshake_destroy(struct ei_handshake *handshake)
{
struct ei *ei = ei_handshake_get_context(handshake);
ei_unregister_object(ei, &handshake->proto_object);
}
OBJECT_IMPLEMENT_REF(ei_handshake);
OBJECT_IMPLEMENT_UNREF_CLEANUP(ei_handshake);
OBJECT_IMPLEMENT_GETTER(ei_handshake, user_data, void*);
OBJECT_IMPLEMENT_SETTER(ei_handshake, user_data, void*);
OBJECT_IMPLEMENT_GETTER_AS_REF(ei_handshake, proto_object, const struct brei_object *);
static
OBJECT_IMPLEMENT_CREATE(ei_handshake);
static
OBJECT_IMPLEMENT_PARENT(ei_handshake, ei);
struct ei*
ei_handshake_get_context(struct ei_handshake *handshake)
{
assert(handshake);
return ei_handshake_parent(handshake);
}
uint32_t
ei_handshake_get_version(struct ei_handshake *handshake)
{
return handshake->proto_object.version;
}
static int
ei_handshake_initialize(struct ei_handshake *setup, uint32_t version)
{
struct ei *ei = ei_handshake_get_context(setup);
if (version >= EI_HANDSHAKE_REQUEST_CONTEXT_TYPE_SINCE_VERSION)
ei_handshake_request_context_type(setup,
ei->is_sender ?
EI_HANDSHAKE_CONTEXT_TYPE_SENDER :
EI_HANDSHAKE_CONTEXT_TYPE_RECEIVER);
if (version >= EI_HANDSHAKE_REQUEST_NAME_SINCE_VERSION)
ei_handshake_request_name(setup, ei->name);
if (version >= EI_HANDSHAKE_REQUEST_INTERFACE_VERSION_SINCE_VERSION) {
struct ei_interface_versions *v = &ei->interface_versions;
ei_handshake_request_interface_version(setup, "ei_handshake", v->ei_handshake);
ei_handshake_request_interface_version(setup, "ei_connection", v->ei_connection);
ei_handshake_request_interface_version(setup, "ei_callback", v->ei_callback);
ei_handshake_request_interface_version(setup, "ei_pingpong", v->ei_pingpong);
ei_handshake_request_interface_version(setup, "ei_seat", v->ei_seat);
ei_handshake_request_interface_version(setup, "ei_device", v->ei_device);
ei_handshake_request_interface_version(setup, "ei_pointer", v->ei_pointer);
ei_handshake_request_interface_version(setup, "ei_keyboard", v->ei_keyboard);
ei_handshake_request_interface_version(setup, "ei_touchscreen", v->ei_touchscreen);
}
ei_handshake_request_finish(setup);
return 0;
}
static struct brei_result *
handle_msg_interface_version(struct ei_handshake *setup, const char *name, uint32_t version)
{
struct ei *ei = ei_handshake_get_context(setup);
struct ei_interface_versions *v = &ei->interface_versions;
if (streq(name, "ei_handshake")) {
uint32_t min_version = min(version, ei->interface_versions.ei_handshake);
v->ei_handshake = min_version;
/* Now upgrade our protocol object to the server version (if applicable) */
setup->proto_object.version = min_version;
/* Now send all the bits we need to send */
ei_handshake_initialize(setup, min_version);
}
#define VERSION_UPDATE(iface_) if (streq(name, #iface_)) v->iface_ = min(version, v->iface_);
else VERSION_UPDATE(ei_connection)
else VERSION_UPDATE(ei_callback)
else VERSION_UPDATE(ei_pingpong)
else VERSION_UPDATE(ei_seat)
else VERSION_UPDATE(ei_device)
else VERSION_UPDATE(ei_pointer)
else VERSION_UPDATE(ei_keyboard)
else VERSION_UPDATE(ei_touchscreen)
#undef VERSION_UPDATE
return NULL;
}
static void
connected(struct ei_connection *connection, void *user_data)
{
struct ei *ei = ei_connection_get_context(connection);
/* If we get here, the server didn't immediately disconnect us */
if (ei->state == EI_STATE_DISCONNECTED)
return;
ei_connected(ei);
}
static struct brei_result *
handle_msg_connection(struct ei_handshake *setup, uint32_t serial, uint32_t id, uint32_t version)
{
struct ei *ei = ei_handshake_get_context(setup);
assert(setup == ei->handshake);
/* we're done with our handshake, drop it */
ei_handshake_unref(steal(&ei->handshake));
ei->connection = ei_connection_new(ei, id, version);
ei->state = EI_STATE_CONNECTING;
ei_update_serial(ei, serial);
/* Send a sync on the connection - EIS should immediately send a
* disconnect event where applicable, so if we get through to our
* sync callback, we didn't immediately get disconnected */
ei_connection_sync(ei->connection, connected, NULL);
return NULL;
}
static const struct ei_handshake_interface interface = {
.interface_version = handle_msg_interface_version,
.connection = handle_msg_connection,
};
const struct ei_handshake_interface *
ei_handshake_get_interface(struct ei_handshake *handshake) {
return &interface;
}
struct ei_handshake *
ei_handshake_new(struct ei *ei, uint32_t version)
{
struct ei_handshake *handshake = ei_handshake_create(&ei->object);
handshake->proto_object.id = ei_get_new_id(ei);
assert(handshake->proto_object.id == 0); /* Special object */
handshake->proto_object.implementation = handshake;
handshake->proto_object.interface = &ei_handshake_proto_interface;
handshake->proto_object.version = version;
ei_register_object(ei, &handshake->proto_object);
return handshake; /* ref owned by caller */
}

View file

@ -19,7 +19,7 @@
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN connection_setup WITH THE SOFTWARE OR THE USE OR OTHER
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -30,26 +30,26 @@
#include "brei-shared.h"
struct ei;
struct ei_connection_setup;
struct ei_handshake;
typedef void (*ei_connection_setup_func)(struct ei_connection_setup *connection_setup, void *connection_setup_data, uint32_t proto_data);
typedef void (*ei_handshake_func)(struct ei_handshake *handshake, void *handshake_data, uint32_t proto_data);
/* This is a protocol-only object, not exposed in the API */
struct ei_connection_setup {
struct ei_handshake {
struct object object;
struct brei_object proto_object;
void *user_data; /* Note: user-data is attached to the object */
};
OBJECT_DECLARE_GETTER(ei_connection_setup, context, struct ei*);
OBJECT_DECLARE_GETTER(ei_connection_setup, proto_object, const struct brei_object *);
OBJECT_DECLARE_GETTER(ei_connection_setup, id, uint32_t);
OBJECT_DECLARE_GETTER(ei_connection_setup, version, uint32_t);
OBJECT_DECLARE_GETTER(ei_connection_setup, interface, const struct ei_connection_setup_interface *);
OBJECT_DECLARE_GETTER(ei_connection_setup, user_data, void*);
OBJECT_DECLARE_SETTER(ei_connection_setup, user_data, void*);
OBJECT_DECLARE_REF(ei_connection_setup);
OBJECT_DECLARE_UNREF(ei_connection_setup);
OBJECT_DECLARE_GETTER(ei_handshake, context, struct ei*);
OBJECT_DECLARE_GETTER(ei_handshake, proto_object, const struct brei_object *);
OBJECT_DECLARE_GETTER(ei_handshake, id, uint32_t);
OBJECT_DECLARE_GETTER(ei_handshake, version, uint32_t);
OBJECT_DECLARE_GETTER(ei_handshake, interface, const struct ei_handshake_interface *);
OBJECT_DECLARE_GETTER(ei_handshake, user_data, void*);
OBJECT_DECLARE_SETTER(ei_handshake, user_data, void*);
OBJECT_DECLARE_REF(ei_handshake);
OBJECT_DECLARE_UNREF(ei_handshake);
struct ei_connection_setup *
ei_connection_setup_new(struct ei *ei, uint32_t version);
struct ei_handshake *
ei_handshake_new(struct ei *ei, uint32_t version);

View file

@ -37,7 +37,7 @@
#include "libei-callback.h"
#include "libei-connection.h"
#include "libei-connection-setup.h"
#include "libei-handshake.h"
#include "libei-seat.h"
#include "libei-device.h"
#include "libei-keyboard.h"
@ -62,7 +62,7 @@ enum ei_state {
struct ei_interface_versions {
uint32_t ei_connection;
uint32_t ei_connection_setup;
uint32_t ei_handshake;
uint32_t ei_callback;
uint32_t ei_pingpong;
uint32_t ei_seat;
@ -76,7 +76,7 @@ struct ei {
struct object object;
struct ei_connection *connection;
struct ei_connection_setup *connection_setup;
struct ei_handshake *handshake;
struct ei_interface_versions interface_versions;
struct list proto_objects; /* brei_object list */
uint32_t next_object_id;

View file

@ -62,7 +62,7 @@ ei_destroy(struct ei *ei)
if (ei->backend_interface.destroy)
ei->backend_interface.destroy(ei, ei->backend);
ei->backend = NULL;
ei_connection_setup_unref(ei->connection_setup);
ei_handshake_unref(ei->handshake);
ei_connection_unref(ei->connection);
brei_context_unref(ei->brei);
sink_unref(ei->sink);
@ -105,7 +105,7 @@ ei_create_context(bool is_sender, void *user_data)
ei->interface_versions = (struct ei_interface_versions){
.ei_connection = VERSION_V(1),
.ei_connection_setup = VERSION_V(1),
.ei_handshake = VERSION_V(1),
.ei_callback = VERSION_V(1),
.ei_pingpong = VERSION_V(1),
.ei_seat = VERSION_V(1),
@ -115,7 +115,7 @@ ei_create_context(bool is_sender, void *user_data)
.ei_touchscreen = VERSION_V(1),
};
/* This must be v1 until the server tells us otherwise */
ei->connection_setup = ei_connection_setup_new(ei, VERSION_V(1));
ei->handshake = ei_handshake_new(ei, VERSION_V(1));
ei->next_object_id = 1;
ei->brei = brei_context_new(ei);
brei_context_set_log_context(ei->brei, ei);
@ -803,7 +803,7 @@ ei_set_socket(struct ei *ei, int fd)
ei->source = source_ref(source);
ei->state = EI_STATE_BACKEND;
/* The server SHOULD have already sent the connection setup
/* The server SHOULD have already sent the handshake
* version, let's process that. If not ready, it'll happen
* in the next dispatch.
*

View file

@ -51,7 +51,7 @@ DEFINE_UNREF_CLEANUP_FUNC(brei_result);
static void
eis_client_destroy(struct eis_client *client)
{
eis_connection_setup_unref(client->setup);
eis_handshake_unref(client->setup);
eis_connection_unref(client->connection);
free(client->name);
brei_context_unref(client->brei);
@ -415,7 +415,7 @@ eis_client_new(struct eis *eis, int fd)
client->interface_versions = (struct eis_client_interface_versions){
.ei_connection = VERSION_V(1),
.ei_connection_setup = VERSION_V(1),
.ei_handshake = VERSION_V(1),
.ei_callback = VERSION_V(1),
.ei_pingpong = VERSION_V(1),
.ei_seat = VERSION_V(1),
@ -444,7 +444,7 @@ eis_client_new(struct eis *eis, int fd)
source_unref(s);
client->setup = eis_connection_setup_new(client, &client->interface_versions);
client->setup = eis_handshake_new(client, &client->interface_versions);
return client;
}

View file

@ -40,7 +40,7 @@ enum eis_client_state {
struct eis_client_interface_versions {
uint32_t ei_connection;
uint32_t ei_connection_setup;
uint32_t ei_handshake;
uint32_t ei_callback;
uint32_t ei_pingpong;
uint32_t ei_seat;
@ -61,7 +61,7 @@ struct eis_client {
uint32_t serial;
uint32_t last_client_serial;
struct eis_connection_setup *setup;
struct eis_handshake *setup;
struct eis_client_interface_versions interface_versions;

View file

@ -18,7 +18,7 @@
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN connection_setup WITH THE SOFTWARE OR THE USE OR OTHER
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -38,39 +38,39 @@
#include "eis-proto.h"
static void
eis_connection_setup_destroy(struct eis_connection_setup *setup)
eis_handshake_destroy(struct eis_handshake *setup)
{
struct eis_client * client = eis_connection_setup_get_client(setup);
struct eis_client * client = eis_handshake_get_client(setup);
eis_client_unregister_object(client, &setup->proto_object);
free(setup->name);
}
OBJECT_IMPLEMENT_REF(eis_connection_setup);
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_connection_setup);
OBJECT_IMPLEMENT_GETTER(eis_connection_setup, version, uint32_t);
OBJECT_IMPLEMENT_GETTER_AS_REF(eis_connection_setup, proto_object, const struct brei_object *);
OBJECT_IMPLEMENT_REF(eis_handshake);
OBJECT_IMPLEMENT_UNREF_CLEANUP(eis_handshake);
OBJECT_IMPLEMENT_GETTER(eis_handshake, version, uint32_t);
OBJECT_IMPLEMENT_GETTER_AS_REF(eis_handshake, proto_object, const struct brei_object *);
static
OBJECT_IMPLEMENT_CREATE(eis_connection_setup);
OBJECT_IMPLEMENT_CREATE(eis_handshake);
static
OBJECT_IMPLEMENT_PARENT(eis_connection_setup, eis_client);
OBJECT_IMPLEMENT_PARENT(eis_handshake, eis_client);
struct eis_client*
eis_connection_setup_get_client(struct eis_connection_setup *setup)
eis_handshake_get_client(struct eis_handshake *setup)
{
return eis_connection_setup_parent(setup);
return eis_handshake_parent(setup);
}
struct eis*
eis_connection_setup_get_context(struct eis_connection_setup *setup)
eis_handshake_get_context(struct eis_handshake *setup)
{
struct eis_client *client = eis_connection_setup_parent(setup);
struct eis_client *client = eis_handshake_parent(setup);
return eis_client_get_context(client);
}
uint32_t
eis_connection_setup_get_id(struct eis_connection_setup *setup)
eis_handshake_get_id(struct eis_handshake *setup)
{
return setup->proto_object.id;
}
@ -83,9 +83,9 @@ pong(struct eis_connection *connection, void *user_data)
}
static struct brei_result *
client_msg_finish(struct eis_connection_setup *setup)
client_msg_finish(struct eis_handshake *setup)
{
struct eis_client *client = eis_connection_setup_get_client(setup);
struct eis_client *client = eis_handshake_get_client(setup);
/* Required interfaces - immediate disconnection if missing */
if (setup->client_versions.ei_connection == 0 ||
@ -96,16 +96,16 @@ client_msg_finish(struct eis_connection_setup *setup)
/* ei_callback needs a client-created object, so tell the client
* about our version */
eis_connection_setup_event_interface_version(setup, "ei_callback",
setup->client_versions.ei_callback);
eis_handshake_event_interface_version(setup, "ei_callback",
setup->client_versions.ei_callback);
eis_client_setup_done(client, setup->name, setup->is_sender, &setup->client_versions);
client->connection = eis_connection_new(client);
eis_connection_setup_event_connection(setup,
eis_client_get_next_serial(client),
eis_connection_get_id(client->connection),
eis_connection_get_version(client->connection));
eis_handshake_event_connection(setup,
eis_client_get_next_serial(client),
eis_connection_get_id(client->connection),
eis_connection_get_version(client->connection));
/* These aren't required but libei is pointless without them, so let's enforce them
* by establishing the connection and immediately sending the disconnect */
@ -118,13 +118,13 @@ client_msg_finish(struct eis_connection_setup *setup)
eis_connection_ping(client->connection, pong, NULL);
}
client->setup = eis_connection_setup_unref(setup);
client->setup = eis_handshake_unref(setup);
return NULL;
}
static struct brei_result *
client_msg_name(struct eis_connection_setup *setup, const char *name)
client_msg_name(struct eis_handshake *setup, const char *name)
{
if (setup->name)
return brei_result_new(EIS_CONNECTION_DISCONNECT_REASON_PROTOCOL, "Duplicate client name");
@ -135,13 +135,13 @@ client_msg_name(struct eis_connection_setup *setup, const char *name)
}
static struct brei_result *
client_msg_context_type(struct eis_connection_setup *setup, uint32_t type)
client_msg_context_type(struct eis_handshake *setup, uint32_t type)
{
switch(type) {
case EIS_CONNECTION_SETUP_CONTEXT_TYPE_SENDER:
case EIS_HANDSHAKE_CONTEXT_TYPE_SENDER:
setup->is_sender = true;
return NULL;
case EIS_CONNECTION_SETUP_CONTEXT_TYPE_RECEIVER:
case EIS_HANDSHAKE_CONTEXT_TYPE_RECEIVER:
setup->is_sender = false;
return NULL;
}
@ -150,9 +150,9 @@ client_msg_context_type(struct eis_connection_setup *setup, uint32_t type)
}
static struct brei_result *
client_msg_interface_version(struct eis_connection_setup *setup, const char *name, uint32_t version)
client_msg_interface_version(struct eis_handshake *setup, const char *name, uint32_t version)
{
struct eis_client *client = eis_connection_setup_get_client(setup);
struct eis_client *client = eis_handshake_get_client(setup);
struct eis *eis = eis_client_get_context(client);
struct v {
const char *name;
@ -167,7 +167,7 @@ client_msg_interface_version(struct eis_connection_setup *setup, const char *nam
VERSION_ENTRY(ei_callback),
VERSION_ENTRY(ei_pingpong),
VERSION_ENTRY(ei_connection),
VERSION_ENTRY(ei_connection_setup),
VERSION_ENTRY(ei_handshake),
VERSION_ENTRY(ei_seat),
VERSION_ENTRY(ei_device),
VERSION_ENTRY(ei_pointer),
@ -198,36 +198,36 @@ client_msg_interface_version(struct eis_connection_setup *setup, const char *nam
return 0;
}
static const struct eis_connection_setup_interface interface = {
static const struct eis_handshake_interface interface = {
.finish = client_msg_finish,
.context_type = client_msg_context_type,
.name = client_msg_name,
.interface_version = client_msg_interface_version,
};
const struct eis_connection_setup_interface *
eis_connection_setup_get_interface(struct eis_connection_setup *setup) {
const struct eis_handshake_interface *
eis_handshake_get_interface(struct eis_handshake *setup) {
return &interface;
}
struct eis_connection_setup *
eis_connection_setup_new(struct eis_client *client,
struct eis_handshake *
eis_handshake_new(struct eis_client *client,
const struct eis_client_interface_versions *versions)
{
struct eis_connection_setup *setup = eis_connection_setup_create(&client->object);
struct eis_handshake *setup = eis_handshake_create(&client->object);
setup->proto_object.id = 0;
setup->proto_object.implementation = setup;
setup->proto_object.interface = &eis_connection_setup_proto_interface;
setup->proto_object.interface = &eis_handshake_proto_interface;
/* This object is always v1 until the client tells us otherwise */
setup->proto_object.version = VERSION_V(1);
list_init(&setup->proto_object.link);
setup->version = VERSION_V(1); /* our ei-connection-setup version */
setup->version = VERSION_V(1); /* our ei-handshake version */
setup->server_versions = *versions;
eis_client_register_object(client, &setup->proto_object);
eis_connection_setup_event_interface_version(setup, "ei_connection_setup", versions->ei_connection_setup);
eis_handshake_event_interface_version(setup, "ei_handshake", versions->ei_handshake);
return setup; /* ref owned by caller */
}

View file

@ -19,7 +19,7 @@
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN connection_setup WITH THE SOFTWARE OR THE USE OR OTHER
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -33,7 +33,7 @@ struct eis;
struct eis_client;
/* This is a protocol-only object, not exposed in the API */
struct eis_connection_setup {
struct eis_handshake {
struct object object;
struct brei_object proto_object;
@ -45,15 +45,15 @@ struct eis_connection_setup {
struct eis_client_interface_versions server_versions;
};
OBJECT_DECLARE_GETTER(eis_connection_setup, context, struct eis *);
OBJECT_DECLARE_GETTER(eis_connection_setup, client, struct eis_client *);
OBJECT_DECLARE_GETTER(eis_connection_setup, id, uint32_t);
OBJECT_DECLARE_GETTER(eis_connection_setup, version, uint32_t);
OBJECT_DECLARE_GETTER(eis_connection_setup, proto_object, const struct brei_object *);
OBJECT_DECLARE_GETTER(eis_connection_setup, interface, const struct eis_connection_setup_interface *);
OBJECT_DECLARE_REF(eis_connection_setup);
OBJECT_DECLARE_UNREF(eis_connection_setup);
OBJECT_DECLARE_GETTER(eis_handshake, context, struct eis *);
OBJECT_DECLARE_GETTER(eis_handshake, client, struct eis_client *);
OBJECT_DECLARE_GETTER(eis_handshake, id, uint32_t);
OBJECT_DECLARE_GETTER(eis_handshake, version, uint32_t);
OBJECT_DECLARE_GETTER(eis_handshake, proto_object, const struct brei_object *);
OBJECT_DECLARE_GETTER(eis_handshake, interface, const struct eis_handshake_interface *);
OBJECT_DECLARE_REF(eis_handshake);
OBJECT_DECLARE_UNREF(eis_handshake);
struct eis_connection_setup *
eis_connection_setup_new(struct eis_client *client,
struct eis_handshake *
eis_handshake_new(struct eis_client *client,
const struct eis_client_interface_versions *versions);

View file

@ -38,7 +38,7 @@
#include "libeis-callback.h"
#include "libeis-client.h"
#include "libeis-connection.h"
#include "libeis-connection-setup.h"
#include "libeis-handshake.h"
#include "libeis-device.h"
#include "libeis-event.h"
#include "libeis-pingpong.h"

View file

@ -135,7 +135,7 @@ class Context:
@classmethod
def create(cls) -> "Context":
o = cls()
o.register(EiConnectionSetup.create(object_id=0, version=1))
o.register(EiHandshake.create(object_id=0, version=1))
return o

View file

@ -42,7 +42,7 @@ try:
MessageHeader,
EiCallback,
EiConnection,
EiConnectionSetup,
EiHandshake,
EiDevice,
EiSeat,
)
@ -151,14 +151,14 @@ class Ei:
)
@property
def connection_setup(self) -> EiConnectionSetup:
def handshake(self) -> EiHandshake:
setup = self.context.objects[0]
assert isinstance(setup, EiConnectionSetup)
assert isinstance(setup, EiHandshake)
return setup
def init_default_sender_connection(self) -> None:
setup = self.connection_setup
self.send(setup.ContextType(EiConnectionSetup.EiContextType.SENDER))
setup = self.handshake
self.send(setup.ContextType(EiHandshake.EiContextType.SENDER))
self.send(setup.Name("test client"))
self.send(
setup.InterfaceVersion("ei_connection", VERSION_V(1))
@ -347,33 +347,33 @@ class TestEiProtocol:
def test_server_sends_version_event_immediately(self, eis):
"""
The server is expected to send ei_connection_setup.interface_version immediately
The server is expected to send ei_handshake.interface_version immediately
on connect
"""
ei = eis.ei
ei.dispatch()
setup = ei.context.objects[0]
assert isinstance(setup, EiConnectionSetup)
assert isinstance(setup, EiHandshake)
ei.wait_for(lambda: bool(setup.calllog))
call = setup.calllog[0]
assert call.name == "InterfaceVersion"
assert call.args["name"] == "ei_connection_setup"
assert call.args["name"] == "ei_handshake"
assert call.args["version"] == VERSION_V(1)
eis.terminate()
def test_server_sends_interface_version_events(self, eis):
"""
The server is expected to send ei_connection_setup.interface_version immediately
The server is expected to send ei_handshake.interface_version immediately
on connect
"""
ei = eis.ei
ei.dispatch()
setup = ei.connection_setup
setup = ei.handshake
ei.init_default_sender_connection()
ei.dispatch()
@ -399,14 +399,14 @@ class TestEiProtocol:
# Pick some random type (and make sure it's not a valid type in the current API)
invalid_type = 4
try:
EiConnectionSetup.EiContextType(invalid_type)
EiHandshake.EiContextType(invalid_type)
assert (
False
), f"{invalid_type} should not be a valid ContextType, this test needs an update"
except ValueError:
pass
ei.send(ei.connection_setup.ContextType(invalid_type))
ei.send(ei.handshake.ContextType(invalid_type))
try:
# The server either disconnects the socket because we sent garbage
@ -415,9 +415,9 @@ class TestEiProtocol:
for interface in ["ei_connection", "ei_callback", "ei_pingpong"]:
ei.send(
ei.connection_setup.InterfaceVersion(interface, VERSION_V(1))
ei.handshake.InterfaceVersion(interface, VERSION_V(1))
) # these are required
ei.send(ei.connection_setup.Finish())
ei.send(ei.handshake.Finish())
ei.dispatch()
ei.wait_for_connection(timeout=1)
@ -500,10 +500,10 @@ class TestEiProtocol:
"""
ei = eis.ei
ei.dispatch()
setup = ei.connection_setup
setup = ei.handshake
# Establish our connection
ei.send(setup.ContextType(EiConnectionSetup.EiContextType.SENDER))
ei.send(setup.ContextType(EiHandshake.EiContextType.SENDER))
ei.send(setup.Name("test client"))
for interface in ["ei_connection", "ei_callback", "ei_pingpong"]:
ei.send(
@ -560,10 +560,10 @@ class TestEiProtocol:
"""
ei = eis.ei
ei.dispatch()
setup = ei.connection_setup
setup = ei.handshake
# Establish our connection
ei.send(setup.ContextType(EiConnectionSetup.EiContextType.SENDER))
ei.send(setup.ContextType(EiHandshake.EiContextType.SENDER))
ei.send(setup.Name("test client"))
for interface in ["ei_connection", "ei_callback", "ei_pingpong"]:
ei.send(
@ -714,7 +714,7 @@ class TestEiProtocol:
def test_disconnect_before_setup_finish(self, eis):
ei = eis.ei
ei.dispatch()
ei.send(ei.connection_setup.ContextType(EiConnectionSetup.EiContextType.SENDER))
ei.send(ei.handshake.ContextType(EiHandshake.EiContextType.SENDER))
ei.sock.close()
time.sleep(0.5)
# Not much we can test here other than hoping the EIS implementation doesn't segfault
@ -734,8 +734,8 @@ class TestEiProtocol:
ei = eis.ei
ei.dispatch()
setup = ei.connection_setup
ei.send(setup.ContextType(EiConnectionSetup.EiContextType.SENDER))
setup = ei.handshake
ei.send(setup.ContextType(EiHandshake.EiContextType.SENDER))
ei.send(setup.Name("test client"))
for interface in [