summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Kilbourn <tkilbourn@google.com>2015-04-06 13:49:40 -0700
committerTim Kilbourn <tkilbourn@google.com>2015-04-16 13:21:39 -0700
commit6fa82480aeb702ca60bc20d5c8df3c4a62904e3b (patch)
treefd192f04871fa0a8848cf4b09e181001e5948d48
parent7771e6c52188dae295524088e577b0db64869b17 (diff)
downloadhardware_libhardware-6fa82480aeb702ca60bc20d5c8df3c4a62904e3b.zip
hardware_libhardware-6fa82480aeb702ca60bc20d5c8df3c4a62904e3b.tar.gz
hardware_libhardware-6fa82480aeb702ca60bc20d5c8df3c4a62904e3b.tar.bz2
Add input HAL methods for getting device properties.
A property map holds the collection of the properties for a given device identifier. HAL modules allocate and release these property maps to control the lifetime of the data. The host will typically open and read the corresponding idc file on allocation, and release these resources when it is freed. Change-Id: Ia13ec7b7abf1a79eeed87dc744c174a37f1fb8a9
-rw-r--r--include/hardware/input.h42
-rw-r--r--modules/input/evdev/InputHost.cpp26
-rw-r--r--modules/input/evdev/InputHost.h59
3 files changed, 127 insertions, 0 deletions
diff --git a/include/hardware/input.h b/include/hardware/input.h
index 5aa3e51..969b8ce 100644
--- a/include/hardware/input.h
+++ b/include/hardware/input.h
@@ -48,6 +48,10 @@ typedef struct input_report input_report_t;
typedef struct input_collection input_collection_t;
+typedef struct input_property_map input_property_map_t;
+
+typedef struct input_property input_property_t;
+
typedef enum {
// keycodes
INPUT_USAGE_KEYCODE_UNKNOWN,
@@ -472,6 +476,44 @@ typedef struct input_host_callbacks {
input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index);
void (*report_event)(input_host_t* host, input_device_handle_t* d, input_report_t* report);
+
+ /**
+ * Retrieve the set of properties for the device. The returned
+ * input_property_map_t* may be used to query specific properties via the
+ * input_get_device_property callback.
+ */
+ input_property_map_t* (*input_get_device_property_map)(input_host_t* host,
+ input_device_identifier_t* id);
+ /**
+ * Retrieve a property for the device with the given key. Returns NULL if
+ * the key does not exist, or an input_property_t* that must be freed using
+ * input_free_device_property(). Using an input_property_t after the
+ * corresponding input_property_map_t is freed is undefined.
+ */
+ input_property_t* (*input_get_device_property)(input_host_t* host,
+ input_property_map_t* map, const char* key);
+
+ /**
+ * Get the key for the input property. Returns NULL if the property is NULL.
+ * The returned const char* is owned by the input_property_t.
+ */
+ const char* (*input_get_property_key)(input_host_t* host, input_property_t* property);
+
+ /**
+ * Get the value for the input property. Returns NULL if the property is
+ * NULL. The returned const char* is owned by the input_property_t.
+ */
+ const char* (*input_get_property_value)(input_host_t* host, input_property_t* property);
+
+ /**
+ * Frees the input_property_t*.
+ */
+ void (*input_free_device_property)(input_host_t* host, input_property_t* property);
+
+ /**
+ * Frees the input_property_map_t*.
+ */
+ void (*input_free_device_property_map)(input_host_t* host, input_property_map_t* map);
} input_host_callbacks_t;
typedef struct input_module input_module_t;
diff --git a/modules/input/evdev/InputHost.cpp b/modules/input/evdev/InputHost.cpp
index 0903f47..6a65fcd 100644
--- a/modules/input/evdev/InputHost.cpp
+++ b/modules/input/evdev/InputHost.cpp
@@ -47,6 +47,27 @@ void InputDeviceDefinition::addReport(InputReportDefinition r) {
mCallbacks.input_device_definition_add_report(mHost, mDeviceDefinition, r);
}
+InputProperty::~InputProperty() {
+ mCallbacks.input_free_device_property(mHost, mProperty);
+}
+
+const char* InputProperty::getKey() {
+ return mCallbacks.input_get_property_key(mHost, mProperty);
+}
+
+const char* InputProperty::getValue() {
+ return mCallbacks.input_get_property_value(mHost, mProperty);
+}
+
+InputPropertyMap::~InputPropertyMap() {
+ mCallbacks.input_free_device_property_map(mHost, mMap);
+}
+
+InputProperty InputPropertyMap::getDeviceProperty(const char* key) {
+ return InputProperty(mHost, mCallbacks,
+ mCallbacks.input_get_device_property(mHost, mMap, key));
+}
+
InputDeviceIdentifier InputHost::createDeviceIdentifier(const char* name, int32_t productId,
int32_t vendorId, InputBus bus, const char* uniqueId) {
return mCallbacks.create_device_identifier(mHost, name, productId, vendorId, bus, uniqueId);
@@ -75,4 +96,9 @@ void InputHost::unregisterDevice(InputDeviceHandle handle) {
return mCallbacks.unregister_device(mHost, handle);
}
+InputPropertyMap InputHost::getDevicePropertyMap(InputDeviceIdentifier id) {
+ return InputPropertyMap(mHost, mCallbacks,
+ mCallbacks.input_get_device_property_map(mHost, id));
+}
+
} // namespace android
diff --git a/modules/input/evdev/InputHost.h b/modules/input/evdev/InputHost.h
index 129443e..98ce26f 100644
--- a/modules/input/evdev/InputHost.h
+++ b/modules/input/evdev/InputHost.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_INPUT_HOST_H_
#define ANDROID_INPUT_HOST_H_
+#include <memory>
+
#include <hardware/input.h>
namespace android {
@@ -109,6 +111,61 @@ private:
input_device_definition_t* mDeviceDefinition;
};
+class InputProperty : private InputHostBase {
+public:
+ virtual ~InputProperty();
+
+ operator input_property_t*() { return mProperty; }
+
+ const char* getKey();
+ const char* getValue();
+
+ // Default move constructor transfers ownership of the input_property_t
+ // pointer.
+ InputProperty(InputProperty&& rhs) = default;
+
+ // Prevent copy/assign because of the ownership of the underlying
+ // input_property_t pointer.
+ InputProperty(const InputProperty& rhs) = delete;
+ InputProperty& operator=(const InputProperty& rhs) = delete;
+
+private:
+ friend class InputPropertyMap;
+
+ InputProperty(
+ input_host_t* host, input_host_callbacks_t cb, input_property_t* p) :
+ InputHostBase(host, cb), mProperty(p) {}
+
+ input_property_t* mProperty;
+};
+
+class InputPropertyMap : private InputHostBase {
+public:
+ virtual ~InputPropertyMap();
+
+ operator input_property_map_t*() { return mMap; }
+
+ InputProperty getDeviceProperty(const char* key);
+
+ // Default move constructor transfers ownership of the input_property_map_t
+ // pointer.
+ InputPropertyMap(InputPropertyMap&& rhs) = default;
+
+ // Prevent copy/assign because of the ownership of the underlying
+ // input_property_map_t pointer.
+ InputPropertyMap(const InputPropertyMap& rhs) = delete;
+ InputPropertyMap& operator=(const InputPropertyMap& rhs) = delete;
+
+private:
+ friend class InputHost;
+
+ InputPropertyMap(
+ input_host_t* host, input_host_callbacks_t cb, input_property_map_t* m) :
+ InputHostBase(host, cb), mMap(m) {}
+
+ input_property_map_t* mMap;
+};
+
class InputHost : private InputHostBase {
public:
InputHost(input_host_t* host, input_host_callbacks_t cb) : InputHostBase(host, cb) {}
@@ -126,6 +183,8 @@ public:
InputDeviceHandle registerDevice(InputDeviceIdentifier id, InputDeviceDefinition d);
void unregisterDevice(InputDeviceHandle handle);
+
+ InputPropertyMap getDevicePropertyMap(InputDeviceIdentifier id);
};
} // namespace android