InputDriver.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2015 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stdint.h>
  17. #include <sys/types.h>
  18. #define LOG_TAG "InputDriver"
  19. #define LOG_NDEBUG 0
  20. #include "InputDriver.h"
  21. #include "InputHost.h"
  22. #include <hardware/input.h>
  23. #include <utils/Log.h>
  24. #include <utils/String8.h>
  25. #define INDENT2 " "
  26. namespace android {
  27. static input_host_callbacks_t kCallbacks = {
  28. .create_device_identifier = create_device_identifier,
  29. .create_device_definition = create_device_definition,
  30. .create_input_report_definition = create_input_report_definition,
  31. .create_output_report_definition = create_output_report_definition,
  32. .input_device_definition_add_report = input_device_definition_add_report,
  33. .input_report_definition_add_collection = input_report_definition_add_collection,
  34. .input_report_definition_declare_usage_int = input_report_definition_declare_usage_int,
  35. .input_report_definition_declare_usages_bool = input_report_definition_declare_usages_bool,
  36. .register_device = register_device,
  37. .input_allocate_report = input_allocate_report,
  38. .input_report_set_usage_int = input_report_set_usage_int,
  39. .input_report_set_usage_bool = input_report_set_usage_bool,
  40. .report_event = report_event,
  41. .input_get_device_property_map = input_get_device_property_map,
  42. .input_get_device_property = input_get_device_property,
  43. .input_get_property_key = input_get_property_key,
  44. .input_get_property_value = input_get_property_value,
  45. .input_free_device_property = input_free_device_property,
  46. .input_free_device_property_map = input_free_device_property_map,
  47. };
  48. InputDriver::InputDriver(const char* name) : mName(String8(name)) {
  49. const hw_module_t* module;
  50. int err = input_open(&module, name);
  51. LOG_ALWAYS_FATAL_IF(err != 0, "Input module %s not found", name);
  52. mHal = reinterpret_cast<const input_module_t*>(module);
  53. }
  54. void InputDriver::init(InputHostInterface* host) {
  55. mHal->init(mHal, static_cast<input_host_t*>(host), kCallbacks);
  56. }
  57. void InputDriver::dump(String8& result) {
  58. result.appendFormat(INDENT2 "HAL Input Driver (%s)\n", mName.string());
  59. }
  60. // HAL wrapper functions
  61. input_device_identifier_t* create_device_identifier(input_host_t* host,
  62. const char* name, int32_t product_id, int32_t vendor_id,
  63. input_bus_t bus, const char* unique_id) {
  64. return nullptr;
  65. }
  66. input_device_definition_t* create_device_definition(input_host_t* host) {
  67. return nullptr;
  68. }
  69. input_report_definition_t* create_input_report_definition(input_host_t* host) {
  70. return nullptr;
  71. }
  72. input_report_definition_t* create_output_report_definition(input_host_t* host) {
  73. return nullptr;
  74. }
  75. void input_device_definition_add_report(input_host_t* host,
  76. input_device_definition_t* d, input_report_definition_t* r) { }
  77. void input_report_definition_add_collection(input_host_t* host,
  78. input_report_definition_t* report, input_collection_id_t id, int32_t arity) { }
  79. void input_report_definition_declare_usage_int(input_host_t* host,
  80. input_report_definition_t* report, input_collection_id_t id,
  81. input_usage_t usage, int32_t min, int32_t max, float resolution) { }
  82. void input_report_definition_declare_usages_bool(input_host_t* host,
  83. input_report_definition_t* report, input_collection_id_t id,
  84. input_usage_t* usage, size_t usage_count) { }
  85. input_device_handle_t* register_device(input_host_t* host,
  86. input_device_identifier_t* id, input_device_definition_t* d) {
  87. return nullptr;
  88. }
  89. input_report_t* input_allocate_report(input_host_t* host, input_report_definition_t* r) {
  90. return nullptr;
  91. }
  92. void input_report_set_usage_int(input_host_t* host, input_report_t* r,
  93. input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index) { }
  94. void input_report_set_usage_bool(input_host_t* host, input_report_t* r,
  95. input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index) { }
  96. void report_event(input_host_t* host, input_device_handle_t* d, input_report_t* report) { }
  97. input_property_map_t* input_get_device_property_map(input_host_t* host,
  98. input_device_identifier_t* id) {
  99. return nullptr;
  100. }
  101. input_property_t* input_get_device_property(input_host_t* host, input_property_map_t* map,
  102. const char* key) {
  103. return nullptr;
  104. }
  105. const char* input_get_property_key(input_host_t* host, input_property_t* property) {
  106. return nullptr;
  107. }
  108. const char* input_get_property_value(input_host_t* host, input_property_t* property) {
  109. return nullptr;
  110. }
  111. void input_free_device_property(input_host_t* host, input_property_t* property) { }
  112. void input_free_device_property_map(input_host_t* host, input_property_map_t* map) { }
  113. } // namespace android