Code layout cleanup
- Fwd declare where possible
- List .h first in the .cpp to verify proper includes
- Remove hacky -internal.h file and move testBitInRange to a new component
Change-Id: I442248c4b32738c6c2af250f45d4c8822c862e08
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
index b12867c..1f5e12f 100644
--- a/modules/input/evdev/Android.mk
+++ b/modules/input/evdev/Android.mk
@@ -18,6 +18,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
+ BitUtils.cpp \
InputHub.cpp \
InputDevice.cpp \
InputDeviceManager.cpp \
diff --git a/modules/input/evdev/BitUtils.cpp b/modules/input/evdev/BitUtils.cpp
new file mode 100644
index 0000000..3434c31
--- /dev/null
+++ b/modules/input/evdev/BitUtils.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "BitUtils"
+//#define LOG_NDEBUG 0
+
+#include "BitUtils.h"
+
+#include <utils/Log.h>
+
+// Enables debug output for hasKeyInRange
+#define DEBUG_KEY_RANGE 0
+
+namespace android {
+
+#if DEBUG_KEY_RANGE
+static const char* bitstrings[16] = {
+ "0000", "0001", "0010", "0011",
+ "0100", "0101", "0110", "0111",
+ "1000", "1001", "1010", "1011",
+ "1100", "1101", "1110", "1111",
+};
+#endif
+
+bool testBitInRange(const uint8_t arr[], size_t start, size_t end) {
+#if DEBUG_KEY_RANGE
+ ALOGD("testBitInRange(%d, %d)", start, end);
+#endif
+ // Invalid range! This is nonsense; just say no.
+ if (end <= start) return false;
+
+ // Find byte array indices. The end is not included in the range, nor is
+ // endIndex. Round up for endIndex.
+ size_t startIndex = start / 8;
+ size_t endIndex = (end + 7) / 8;
+#if DEBUG_KEY_RANGE
+ ALOGD("startIndex=%d, endIndex=%d", startIndex, endIndex);
+#endif
+ for (size_t i = startIndex; i < endIndex; ++i) {
+ uint8_t bits = arr[i];
+ uint8_t mask = 0xff;
+#if DEBUG_KEY_RANGE
+ ALOGD("block %04d: %s%s", i, bitstrings[bits >> 4], bitstrings[bits & 0x0f]);
+#endif
+ if (bits) {
+ // Mask off bits before our start bit
+ if (i == startIndex) {
+ mask &= 0xff << (start % 8);
+ }
+ // Mask off bits after our end bit
+ if (i == endIndex - 1 && (end % 8)) {
+ mask &= 0xff >> (8 - (end % 8));
+ }
+#if DEBUG_KEY_RANGE
+ ALOGD("mask: %s%s", bitstrings[mask >> 4], bitstrings[mask & 0x0f]);
+#endif
+ // Test the index against the mask
+ if (bits & mask) return true;
+ }
+ }
+ return false;
+}
+} // namespace android
diff --git a/modules/input/evdev/InputHub-internal.h b/modules/input/evdev/BitUtils.h
similarity index 83%
rename from modules/input/evdev/InputHub-internal.h
rename to modules/input/evdev/BitUtils.h
index b4f1297..1aa1f6a 100644
--- a/modules/input/evdev/InputHub-internal.h
+++ b/modules/input/evdev/BitUtils.h
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#ifndef ANDROID_INPUT_HUB_INTERNAL_H_
-#define ANDROID_INPUT_HUB_INTERNAL_H_
+#ifndef ANDROID_BIT_UTILS_H_
+#define ANDROID_BIT_UTILS_H_
+
+#include <cstdint>
namespace android {
-namespace internal {
/** Test whether any bits in the interval [start, end) are set in the array. */
bool testBitInRange(const uint8_t arr[], size_t start, size_t end);
-} // namespace internal
} // namespace android
-#endif // ANDROID_INPUT_HUB_INTERNAL_H_
+#endif // ANDROID_BIT_UTILS_H_
diff --git a/modules/input/evdev/InputDevice.cpp b/modules/input/evdev/InputDevice.cpp
index 8365386..ea90068 100644
--- a/modules/input/evdev/InputDevice.cpp
+++ b/modules/input/evdev/InputDevice.cpp
@@ -20,6 +20,8 @@
// Enables debug output for processing input events
#define DEBUG_INPUT_EVENTS 0
+#include "InputDevice.h"
+
#include <linux/input.h>
#define __STDC_FORMAT_MACROS
@@ -30,9 +32,8 @@
#include <utils/Log.h>
#include <utils/Timers.h>
+#include "InputHost.h"
#include "InputHub.h"
-#include "InputDevice.h"
-#include "InputMapper.h"
#include "SwitchInputMapper.h"
#define MSC_ANDROID_TIME_SEC 0x6
diff --git a/modules/input/evdev/InputDevice.h b/modules/input/evdev/InputDevice.h
index a379d6c..6892778 100644
--- a/modules/input/evdev/InputDevice.h
+++ b/modules/input/evdev/InputDevice.h
@@ -22,12 +22,20 @@
#include <utils/Timers.h>
-#include "InputHost.h"
-#include "InputHub.h"
#include "InputMapper.h"
+struct input_device_handle;
+struct input_device_identifier;
+
namespace android {
+class InputDeviceDefinition;
+class InputDeviceNode;
+class InputHostInterface;
+struct InputEvent;
+using InputDeviceHandle = struct input_device_handle;
+using InputDeviceIdentifier = struct input_device_identifier;
+
/**
* InputDeviceInterface represents an input device in the HAL. It processes
* input events before passing them to the input host.
diff --git a/modules/input/evdev/InputDeviceManager.cpp b/modules/input/evdev/InputDeviceManager.cpp
index 46c9dfb..d50c1ae 100644
--- a/modules/input/evdev/InputDeviceManager.cpp
+++ b/modules/input/evdev/InputDeviceManager.cpp
@@ -17,10 +17,11 @@
#define LOG_TAG "InputDeviceManager"
//#define LOG_NDEBUG 0
+#include "InputDeviceManager.h"
+
#include <utils/Log.h>
#include "InputDevice.h"
-#include "InputDeviceManager.h"
namespace android {
diff --git a/modules/input/evdev/InputDeviceManager.h b/modules/input/evdev/InputDeviceManager.h
index 7ffec5b..8fbf3ca 100644
--- a/modules/input/evdev/InputDeviceManager.h
+++ b/modules/input/evdev/InputDeviceManager.h
@@ -22,12 +22,13 @@
#include <utils/Timers.h>
-#include "InputDevice.h"
-#include "InputHost.h"
#include "InputHub.h"
namespace android {
+class InputDeviceInterface;
+class InputHostInterface;
+
/**
* InputDeviceManager keeps the mapping of InputDeviceNodes to
* InputDeviceInterfaces and handles the callbacks from the InputHub, delegating
diff --git a/modules/input/evdev/InputHub.cpp b/modules/input/evdev/InputHub.cpp
index 8c48345..389955d 100644
--- a/modules/input/evdev/InputHub.cpp
+++ b/modules/input/evdev/InputHub.cpp
@@ -17,8 +17,7 @@
#define LOG_TAG "InputHub"
//#define LOG_NDEBUG 0
-// Enables debug output for hasKeyInRange
-#define DEBUG_KEY_RANGE 0
+#include "InputHub.h"
#include <dirent.h>
#include <errno.h>
@@ -36,15 +35,14 @@
#include <vector>
-#include "InputHub.h"
-#include "InputHub-internal.h"
-
#include <android/input.h>
#include <hardware_legacy/power.h>
#include <linux/input.h>
#include <utils/Log.h>
+#include "BitUtils.h"
+
namespace android {
static const char WAKE_LOCK_ID[] = "KeyEvents";
@@ -60,57 +58,6 @@
return (bits + 7) / 8;
}
-namespace internal {
-
-#if DEBUG_KEY_RANGE
-static const char* bitstrings[16] = {
- "0000", "0001", "0010", "0011",
- "0100", "0101", "0110", "0111",
- "1000", "1001", "1010", "1011",
- "1100", "1101", "1110", "1111",
-};
-#endif
-
-bool testBitInRange(const uint8_t arr[], size_t start, size_t end) {
-#if DEBUG_KEY_RANGE
- ALOGD("testBitInRange(%d, %d)", start, end);
-#endif
- // Invalid range! This is nonsense; just say no.
- if (end <= start) return false;
-
- // Find byte array indices. The end is not included in the range, nor is
- // endIndex. Round up for endIndex.
- size_t startIndex = start / 8;
- size_t endIndex = (end + 7) / 8;
-#if DEBUG_KEY_RANGE
- ALOGD("startIndex=%d, endIndex=%d", startIndex, endIndex);
-#endif
- for (size_t i = startIndex; i < endIndex; ++i) {
- uint8_t bits = arr[i];
- uint8_t mask = 0xff;
-#if DEBUG_KEY_RANGE
- ALOGD("block %04d: %s%s", i, bitstrings[bits >> 4], bitstrings[bits & 0x0f]);
-#endif
- if (bits) {
- // Mask off bits before our start bit
- if (i == startIndex) {
- mask &= 0xff << (start % 8);
- }
- // Mask off bits after our end bit
- if (i == endIndex - 1 && (end % 8)) {
- mask &= 0xff >> (8 - (end % 8));
- }
-#if DEBUG_KEY_RANGE
- ALOGD("mask: %s%s", bitstrings[mask >> 4], bitstrings[mask & 0x0f]);
-#endif
- // Test the index against the mask
- if (bits & mask) return true;
- }
- }
- return false;
-}
-} // namespace internal
-
static void getLinuxRelease(int* major, int* minor) {
struct utsname info;
if (uname(&info) || sscanf(info.release, "%d.%d", major, minor) <= 0) {
@@ -331,7 +278,7 @@
}
bool EvdevDeviceNode::hasKeyInRange(int32_t startKey, int32_t endKey) const {
- return internal::testBitInRange(mKeyBitmask, startKey, endKey);
+ return testBitInRange(mKeyBitmask, startKey, endKey);
}
bool EvdevDeviceNode::hasRelativeAxis(int axis) const {
diff --git a/modules/input/evdev/InputMapper.cpp b/modules/input/evdev/InputMapper.cpp
index 2353a9a..3893125 100644
--- a/modules/input/evdev/InputMapper.cpp
+++ b/modules/input/evdev/InputMapper.cpp
@@ -16,6 +16,8 @@
#include "InputMapper.h"
+#include "InputHost.h"
+
namespace android {
InputReport* InputMapper::getInputReport() {
diff --git a/modules/input/evdev/InputMapper.h b/modules/input/evdev/InputMapper.h
index b33cb63..5e88d06 100644
--- a/modules/input/evdev/InputMapper.h
+++ b/modules/input/evdev/InputMapper.h
@@ -17,11 +17,16 @@
#ifndef ANDROID_INPUT_MAPPER_H_
#define ANDROID_INPUT_MAPPER_H_
-#include "InputHost.h"
-#include "InputHub.h"
+struct input_device_handle;
namespace android {
+class InputDeviceNode;
+class InputReport;
+class InputReportDefinition;
+struct InputEvent;
+using InputDeviceHandle = struct input_device_handle;
+
/**
* An InputMapper processes raw evdev input events and combines them into
* Android input HAL reports. A given InputMapper will focus on a particular
@@ -31,7 +36,8 @@
*/
class InputMapper {
public:
- virtual ~InputMapper() = default;
+ InputMapper() = default;
+ virtual ~InputMapper() {}
/**
* If the mapper supports input events from the InputDevice,