aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-01-07 17:30:40 +0100
committernsensfel <SpamShield0@noot-noot.org>2020-01-07 17:30:40 +0100
commit43ea7c79785e4ea3518b2d122b6e47891ab478d9 (patch)
tree9cf0a3bf9a45b9d34c88d0fdf646dd1e09ce9e82
parent272e335b057dce34304d17074a81d3e3d0cde175 (diff)
downloadrelabsd-43ea7c79785e4ea3518b2d122b6e47891ab478d9.zip
relabsd-43ea7c79785e4ea3518b2d122b6e47891ab478d9.tar.bz2
Adds compatibility test.
-rw-r--r--include/relabsd/compatibility_test.h10
-rw-r--r--include/relabsd/device/physical_device.h5
-rw-r--r--include/relabsd/device/virtual_device.h11
-rw-r--r--include/relabsd/device/virtual_device_types.h1
-rw-r--r--src/compatibility_test.c93
-rw-r--r--src/config/parameters/parameters.c71
-rw-r--r--src/device/physical/physical_device.c8
-rw-r--r--src/device/virtual/virtual_device.c56
-rw-r--r--src/main.c3
-rw-r--r--src/server/conversion_main_loop.c19
-rw-r--r--src/server/server.c5
11 files changed, 239 insertions, 43 deletions
diff --git a/include/relabsd/compatibility_test.h b/include/relabsd/compatibility_test.h
new file mode 100644
index 0000000..b81d767
--- /dev/null
+++ b/include/relabsd/compatibility_test.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include <relabsd/config/parameters_types.h>
+
+int relabsd_compatibility_test_main
+(
+ const int argc,
+ const char * const argv [const static argc],
+ struct relabsd_parameters parameters [const restrict static 1]
+);
diff --git a/include/relabsd/device/physical_device.h b/include/relabsd/device/physical_device.h
index 33ff18a..babf911 100644
--- a/include/relabsd/device/physical_device.h
+++ b/include/relabsd/device/physical_device.h
@@ -45,3 +45,8 @@ int relabsd_physical_device_get_file_descriptor
(
const struct relabsd_physical_device device [const restrict static 1]
);
+
+struct libevdev * relabsd_physical_device_get_libevdev
+(
+ struct relabsd_physical_device device [const restrict static 1]
+);
diff --git a/include/relabsd/device/virtual_device.h b/include/relabsd/device/virtual_device.h
index fffb2a3..f4ffeca 100644
--- a/include/relabsd/device/virtual_device.h
+++ b/include/relabsd/device/virtual_device.h
@@ -54,3 +54,14 @@ void relabsd_virtual_device_set_axes_to_zero
struct relabsd_parameters parameters [const restrict static 1],
const struct relabsd_virtual_device device [const restrict static 1]
);
+
+void relabsd_virtual_device_set_has_already_timed_out
+(
+ const int val,
+ struct relabsd_virtual_device device [const restrict static 1]
+);
+
+int relabsd_virtual_device_has_already_timed_out
+(
+ const struct relabsd_virtual_device device [const restrict static 1]
+);
diff --git a/include/relabsd/device/virtual_device_types.h b/include/relabsd/device/virtual_device_types.h
index 7c0c05a..304f537 100644
--- a/include/relabsd/device/virtual_device_types.h
+++ b/include/relabsd/device/virtual_device_types.h
@@ -18,6 +18,7 @@
struct relabsd_virtual_device
{
+ int already_timed_out;
struct libevdev * libevdev;
struct libevdev_uinput * uinput_device;
};
diff --git a/src/compatibility_test.c b/src/compatibility_test.c
new file mode 100644
index 0000000..1741e07
--- /dev/null
+++ b/src/compatibility_test.c
@@ -0,0 +1,93 @@
+/**** POSIX *******************************************************************/
+#include <stdio.h>
+
+/**** LIBEVDEV ****************************************************************/
+#include <libevdev/libevdev.h>
+
+/**** RELABSD *****************************************************************/
+#include <relabsd/debug.h>
+
+#include <relabsd/config/parameters.h>
+
+#include <relabsd/device/axis.h>
+#include <relabsd/device/physical_device.h>
+
+/******************************************************************************/
+/**** LOCAL FUNCTIONS *********************************************************/
+/******************************************************************************/
+static int test_for_axis_and_print_info
+(
+ const struct libevdev * const restrict libevdev
+)
+{
+ int i, device_has_rel;
+ unsigned int rel_code;
+
+ device_has_rel = 0;
+
+ for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i)
+ {
+ rel_code = relabsd_axis_name_to_evdev_rel((enum relabsd_axis_name) i);
+
+ if (libevdev_has_event_code(libevdev, EV_REL, rel_code))
+ {
+ printf
+ (
+ "Relative axis: %s\n",
+ relabsd_axis_name_to_string((enum relabsd_axis_name) i)
+ );
+
+ device_has_rel = 1;
+ }
+ }
+
+ return device_has_rel;
+}
+
+/******************************************************************************/
+/**** EXPORTED FUNCTIONS ******************************************************/
+/******************************************************************************/
+int relabsd_compatibility_test_main
+(
+ const int argc,
+ const char * const argv [const static argc],
+ struct relabsd_parameters parameters [const restrict static 1]
+)
+{
+ struct relabsd_physical_device device;
+ int is_compatible;
+ struct libevdev * libevdev;
+
+ if (relabsd_parameters_parse_options(argc, argv, parameters) < 0)
+ {
+ return -1;
+ }
+
+ if
+ (
+ relabsd_physical_device_open
+ (
+ relabsd_parameters_get_physical_device_file_name(parameters),
+ &device
+ )
+ < 0
+ )
+ {
+ return -1;
+ }
+
+ libevdev = relabsd_physical_device_get_libevdev(&device);
+ is_compatible = test_for_axis_and_print_info (libevdev);
+
+ if (!is_compatible)
+ {
+ return 0;
+ }
+
+ if (relabsd_parameters_are_compatible_with(libevdev, parameters))
+ {
+ return 2;
+ }
+
+ return 1;
+}
diff --git a/src/config/parameters/parameters.c b/src/config/parameters/parameters.c
index eb06c42..0e98016 100644
--- a/src/config/parameters/parameters.c
+++ b/src/config/parameters/parameters.c
@@ -148,6 +148,32 @@ int relabsd_parameters_parse_execution_mode
parameters->physical_device_file_name = argv[2];
parameters->read_argc = 2;
}
+ else if (argc == 3)
+ {
+ parameters->mode = RELABSD_PARAMETERS_SERVER_MODE;
+ parameters->communication_node_name = (char *) NULL;
+ parameters->physical_device_file_name = argv[1];
+ parameters->read_argc = 2;
+
+ if (relabsd_parameters_parse_config_file(argv[2], parameters) < 0)
+ {
+ return -1;
+ }
+ }
+ else if (argc == 4)
+ {
+ parameters->mode = RELABSD_PARAMETERS_SERVER_MODE;
+ parameters->communication_node_name = (char *) NULL;
+ parameters->physical_device_file_name = argv[1];
+
+ if (relabsd_parameters_parse_config_file(argv[2], parameters) < 0)
+ {
+ return -1;
+ }
+
+ parameters->device_name = argv[3];
+ parameters->read_argc = 3;
+ }
else
{
relabsd_parameters_print_usage(argv[0]);
@@ -377,25 +403,27 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])
{
printf
(
- "USAGE: %s <MODE> [<OPTION>+]\n\n"
+ "USAGES:\n"
+ "\t%s <physical_device_file> <config_file>\n"
+ "\t%s <physical_device_file> <config_file> <relabsd_device_name>\n"
+ "\t\tLegacy usage.\n\n"
- "<MODE>:\n"
- "\t[-? | --compatible] <physical_device_file>:\n"
- "\t\tDevice compatibility test.\n\n"
+ "\t%s [-? | --compatible] <physical_device_file> [<CONF_OPTION>+]\n"
+ "\t\tDevice & configuration compatibility test.\n\n"
- "\t[-c | --client] <server_file>:\n"
+ "\t%s [-c | --client] <server_file> [(<CLIENT_OPTION>|<CONF_OPTION>)+]"
+ "\n"
"\t\tSends the commands to a given server instance.\n\n"
- "\t[-s | --server] <server_file> <physical_device_file>:\n"
- "\t\tCreates a named server instance.\n\n"
+ "\t%s [-s | --server] <server_file> <physical_device_file>"
+ " [(<SERVER_OPTION>|<CONF_OPTION>)+]:\n"
+ "\t\tCreates a named server instance.\n\n"
- "\t[-1 | --self] <physical_device_file>:\n"
- "\t\tCreates a unnamed server instance.\n\n"
-
- "<OPTION>:\n"
- "\t[-d | --daemon]:\n"
- "\t\tRuns server instance in the background.\n\n"
+ "\t%s [-1 | --self] <physical_device_file>"
+ " [(<SERVER_OPTION>|<CONF_OPTION>)+]:\n"
+ "\t\tCreates an unnamed server instance.\n\n"
+ "<CONF_OPTION>:\n"
"\t[-n | --name] <relabsd_device_name>:\n"
"\t\tNames the virtual device.\n\n"
@@ -406,16 +434,25 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])
"<options>:\n"
"\t\t(Re)defines an axis.\n\n"
- "\t[-m | --mod-axis] <name> <MOD_PARAM> [+|-|=]<value>:\n"
+ "\t[-m | --mod-axis] <name> [min|max|fuzz|flat|resolution]"
+ " [+|-|=]<value>:\n"
"\t\tModifies an axis.\n\n"
"\t[-f | --config] <config_file>"
"\t\tUse the options defined in <config_file>.\n\n"
- "\t[-q | --quit]:\n"
- "\t\tTerminates the targeted server instance.\n\n"
+ "<SERVER_OPTION>:\n"
+ "\t[-d | --daemon]:\n"
+ "\t\tRuns server instance in the background.\n\n"
- "<MOD_PARAM>: [min|max|fuzz|flat|resolution]\n",
+ "<CLIENT_OPTION>:\n"
+ "\t[-q | --quit]:\n"
+ "\t\tTerminates the targeted server instance.\n",
+ exec,
+ exec,
+ exec,
+ exec,
+ exec,
exec
);
}
diff --git a/src/device/physical/physical_device.c b/src/device/physical/physical_device.c
index 1bf3326..52d58dc 100644
--- a/src/device/physical/physical_device.c
+++ b/src/device/physical/physical_device.c
@@ -222,3 +222,11 @@ int relabsd_physical_device_get_file_descriptor
{
return device->file;
}
+
+struct libevdev * relabsd_physical_device_get_libevdev
+(
+ struct relabsd_physical_device device [const restrict static 1]
+)
+{
+ return device->libevdev;
+}
diff --git a/src/device/virtual/virtual_device.c b/src/device/virtual/virtual_device.c
index 246a90b..6866d65 100644
--- a/src/device/virtual/virtual_device.c
+++ b/src/device/virtual/virtual_device.c
@@ -161,6 +161,8 @@ int relabsd_virtual_device_create_from
RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Creating virtual device...");
+ device->already_timed_out = 0;
+
errno = 0;
physical_device_file =
open
@@ -316,7 +318,7 @@ int relabsd_virtual_device_write_evdev_event
void relabsd_virtual_device_set_axes_to_zero
(
- struct relabsd_parameters parameters [const restrict static 1],
+ struct relabsd_parameters parameters [const static 1],
const struct relabsd_virtual_device device [const restrict static 1]
)
{
@@ -324,13 +326,12 @@ void relabsd_virtual_device_set_axes_to_zero
for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i)
{
- if
- (
- relabsd_axis_is_enabled
- (
- relabsd_parameters_get_axis((enum relabsd_axis_name) i, parameters)
- )
- )
+ struct relabsd_axis * axis;
+
+ axis =
+ relabsd_parameters_get_axis((enum relabsd_axis_name) i, parameters);
+
+ if (relabsd_axis_is_enabled(axis))
{
relabsd_virtual_device_write_evdev_event
(
@@ -339,24 +340,33 @@ void relabsd_virtual_device_set_axes_to_zero
relabsd_axis_name_to_evdev_abs((enum relabsd_axis_name) i),
0
);
+
+ axis->previous_value = 0;
}
}
- /*
- * Also send a SYN event when the axes have been modified.
- */
- i =
- libevdev_uinput_write_event(device->uinput_device, EV_SYN, SYN_REPORT, 0);
+ (void) relabsd_virtual_device_write_evdev_event
+ (
+ device,
+ EV_SYN,
+ SYN_REPORT,
+ 0
+ );
+}
- if (i != 0)
- {
- RELABSD_ERROR
- (
- "Unable to generate event"
- " {type = EV_SYN; code = SYN_REPORT; value = 0}:"
- " %s.",
- strerror(-i)
- );
- }
+void relabsd_virtual_device_set_has_already_timed_out
+(
+ const int val,
+ struct relabsd_virtual_device device [const restrict static 1]
+)
+{
+ device->already_timed_out = val;
}
+int relabsd_virtual_device_has_already_timed_out
+(
+ const struct relabsd_virtual_device device [const restrict static 1]
+)
+{
+ return device->already_timed_out;
+}
diff --git a/src/main.c b/src/main.c
index 79ed9d7..a741f5d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,6 @@
/**** RELABSD *****************************************************************/
#include <relabsd/client.h>
+#include <relabsd/compatibility_test.h>
#include <relabsd/config.h>
#include <relabsd/debug.h>
#include <relabsd/server.h>
@@ -41,7 +42,7 @@ int main (int const argc, const char * const * const argv)
case RELABSD_PARAMETERS_COMPATIBILITY_TEST_MODE:
/* TODO: implement this. */
- RELABSD_S_FATAL("Compatibility test mode not implemented.");
+ retval = relabsd_compatibility_test_main(argc, argv, &params);
break;
}
diff --git a/src/server/conversion_main_loop.c b/src/server/conversion_main_loop.c
index e36bbd0..937fc68 100644
--- a/src/server/conversion_main_loop.c
+++ b/src/server/conversion_main_loop.c
@@ -74,6 +74,12 @@ static void convert_input
abs_code,
value
);
+
+ relabsd_virtual_device_set_has_already_timed_out
+ (
+ 0,
+ &(server->virtual_device)
+ );
return;
case 0:
@@ -105,6 +111,12 @@ static void reset_axes
struct relabsd_server server [const restrict static 1]
)
{
+ relabsd_virtual_device_set_has_already_timed_out
+ (
+ 1,
+ &(server->virtual_device)
+ );
+
relabsd_virtual_device_set_axes_to_zero
(
&(server->parameters),
@@ -146,7 +158,12 @@ static int wait_for_next_event
errno = 0;
- if (relabsd_parameters_use_timeout(&(server->parameters)))
+ if
+ (
+ relabsd_parameters_use_timeout(&(server->parameters))
+ &&
+ !relabsd_virtual_device_has_already_timed_out(&(server->virtual_device))
+ )
{
struct timeval curr_timeout;
diff --git a/src/server/server.c b/src/server/server.c
index 223e57a..84beca6 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -132,7 +132,10 @@ int relabsd_server_main
return -2;
}
- (void) initialize(&server);
+ if (initialize(&server) < 0)
+ {
+ return -1;
+ }
(void) relabsd_server_conversion_loop(&server);