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;
+}
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
*
* Get the repeat delay and repeat period values for this device. This
LIBEVDEV_1_3 {
global:
libevdev_set_device_log_function;
+ libevdev_property_from_name;
+ libevdev_property_from_name_n;
local:
*;
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 */")
}
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)
{
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;
}