mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2026-02-10 04:20:35 +01:00
Add libevdev_property_from_name()
12717d79 "Add libevdev_event_type/code_from_name() resolvers" added the
lookup functions for types and codes, this commit adds the missing ones for
input properties.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
87c1cd05ec
commit
8742e1e346
5 changed files with 93 additions and 1 deletions
|
|
@ -141,3 +141,23 @@ libevdev_event_code_from_name_n(unsigned int type, const char *name, size_t len)
|
|||
|
||||
return entry ? (int)entry->value : -1;
|
||||
}
|
||||
|
||||
LIBEVDEV_EXPORT int
|
||||
libevdev_property_from_name(const char *name)
|
||||
{
|
||||
return libevdev_property_from_name_n(name, strlen(name));
|
||||
}
|
||||
|
||||
LIBEVDEV_EXPORT int
|
||||
libevdev_property_from_name_n(const char *name, size_t len)
|
||||
{
|
||||
struct name_lookup lookup;
|
||||
const struct name_entry *entry;
|
||||
|
||||
lookup.name = name;
|
||||
lookup.len = len;
|
||||
|
||||
entry = lookup_name(prop_names, ARRAY_LENGTH(prop_names), &lookup);
|
||||
|
||||
return entry ? (int)entry->value : -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2084,6 +2084,36 @@ int libevdev_event_code_from_name(unsigned int type, const char *name);
|
|||
int libevdev_event_code_from_name_n(unsigned int type, const char *name,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* @ingroup misc
|
||||
*
|
||||
* Look up an input property by its name. Properties start with the fixed
|
||||
* prefix "INPUT_PROP_" followed by their name (eg., "INPUT_PROP_POINTER").
|
||||
* The prefix must be included in the name. It returns the constant assigned
|
||||
* to the property or -1 if not found.
|
||||
*
|
||||
* @param name A non-NULL string describing an input property
|
||||
*
|
||||
* @return The given code constant for the name or -1 if not found.
|
||||
*/
|
||||
int libevdev_property_from_name(const char *name);
|
||||
|
||||
/**
|
||||
* @ingroup misc
|
||||
*
|
||||
* Look up an input property by its name. Properties start with the fixed
|
||||
* prefix "INPUT_PROP_" followed by their name (eg., "INPUT_PROP_POINTER").
|
||||
* The prefix must be included in the name. It returns the constant assigned
|
||||
* to the property or -1 if not found.
|
||||
*
|
||||
* @param name A non-NULL string describing an input property
|
||||
* @param len The length of the string in @p name excluding any terminating 0
|
||||
* character.
|
||||
*
|
||||
* @return The given code constant for the name or -1 if not found.
|
||||
*/
|
||||
int libevdev_property_from_name_n(const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* @ingroup bits
|
||||
*
|
||||
|
|
|
|||
|
|
@ -106,6 +106,8 @@ local:
|
|||
LIBEVDEV_1_3 {
|
||||
global:
|
||||
libevdev_set_device_log_function;
|
||||
libevdev_property_from_name;
|
||||
libevdev_property_from_name_n;
|
||||
|
||||
local:
|
||||
*;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,10 @@ def print_lookup_table(bits):
|
|||
print_lookup(bits, prefix[:-1].lower())
|
||||
print("};")
|
||||
print("")
|
||||
|
||||
print("static const struct name_entry prop_names[] = {")
|
||||
print_lookup(bits, "input_prop")
|
||||
print("};")
|
||||
print("")
|
||||
|
||||
def print_mapping_table(bits):
|
||||
print("/* THIS FILE IS GENERATED, DO NOT EDIT */")
|
||||
|
|
|
|||
|
|
@ -99,6 +99,38 @@ START_TEST(test_key_invalid)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_properties)
|
||||
{
|
||||
struct prop {
|
||||
int val;
|
||||
const char *name;
|
||||
} lut[] = {
|
||||
{ INPUT_PROP_DIRECT, "INPUT_PROP_DIRECT" },
|
||||
{ INPUT_PROP_POINTER, "INPUT_PROP_POINTER" },
|
||||
{ INPUT_PROP_MAX, "INPUT_PROP_MAX" },
|
||||
{ -1, NULL}
|
||||
};
|
||||
struct prop *p = lut;
|
||||
while (p->val != -1) {
|
||||
ck_assert_int_eq(libevdev_property_from_name(p->name), p->val);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_properties_invalid)
|
||||
{
|
||||
ck_assert_int_eq(libevdev_property_from_name("EV_ABS"), -1);
|
||||
ck_assert_int_eq(libevdev_property_from_name("INPUT_PROP"), -1);
|
||||
ck_assert_int_eq(libevdev_property_from_name("INPUT_PROP_"), -1);
|
||||
ck_assert_int_eq(libevdev_property_from_name("INPUT_PROP_FOO"), -1);
|
||||
|
||||
ck_assert_int_eq(libevdev_property_from_name_n("INPUT_PROP_POINTER", 11), -1);
|
||||
ck_assert_int_eq(libevdev_property_from_name_n("INPUT_PROP_POINTER",
|
||||
strlen("INPUT_PROP_POINTER") - 1), -1);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite *
|
||||
event_code_suite(void)
|
||||
{
|
||||
|
|
@ -114,5 +146,10 @@ event_code_suite(void)
|
|||
tcase_add_test(tc, test_key_invalid);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("property tests");
|
||||
tcase_add_test(tc, test_properties);
|
||||
tcase_add_test(tc, test_properties_invalid);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue