Skip to content

Commit

Permalink
refactor(device): ignore post-state packets
Browse files Browse the repository at this point in the history
Ignore and warn about packets received after a device has been
disconnected.
  • Loading branch information
andyholmes committed Dec 17, 2024
1 parent d5d7d67 commit 93f459a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libvalent/device/valent-device-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@
* Since: 1.0
*/

G_DEFINE_ABSTRACT_TYPE (ValentDevicePlugin, valent_device_plugin, VALENT_TYPE_EXTENSION)
typedef struct
{
ValentDeviceState state;
} ValentDevicePluginPrivate;

G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentDevicePlugin, valent_device_plugin, VALENT_TYPE_EXTENSION)

/* LCOV_EXCL_START */
static void
Expand Down Expand Up @@ -273,12 +278,18 @@ valent_device_plugin_handle_packet (ValentDevicePlugin *plugin,
const char *type,
JsonNode *packet)
{
ValentDevicePluginPrivate *priv = valent_device_plugin_get_instance_private (plugin);

VALENT_ENTRY;

g_return_if_fail (VALENT_IS_DEVICE_PLUGIN (plugin));
g_return_if_fail (type != NULL && *type != '\0');
g_return_if_fail (VALENT_IS_PACKET (packet));

// FIXME: due to a race-condition while swapping device channels, packets
// may be handled while a device is briefly in a disconnected state
g_return_if_fail ((priv->state & VALENT_DEVICE_STATE_CONNECTED) != 0);

VALENT_DEVICE_PLUGIN_GET_CLASS (plugin)->handle_packet (plugin, type, packet);

VALENT_EXIT;
Expand All @@ -304,10 +315,13 @@ void
valent_device_plugin_update_state (ValentDevicePlugin *plugin,
ValentDeviceState state)
{
ValentDevicePluginPrivate *priv = valent_device_plugin_get_instance_private (plugin);

VALENT_ENTRY;

g_return_if_fail (VALENT_IS_DEVICE_PLUGIN (plugin));

priv->state = state;
VALENT_DEVICE_PLUGIN_GET_CLASS (plugin)->update_state (plugin, state);

VALENT_EXIT;
Expand Down

0 comments on commit 93f459a

Please sign in to comment.