summaryrefslogtreecommitdiffstats
path: root/sensors/multihal_sensors.h
diff options
context:
space:
mode:
Diffstat (limited to 'sensors/multihal_sensors.h')
-rw-r--r--sensors/multihal_sensors.h42
1 files changed, 38 insertions, 4 deletions
diff --git a/sensors/multihal_sensors.h b/sensors/multihal_sensors.h
index 80ed6a3b..382af7f7 100644
--- a/sensors/multihal_sensors.h
+++ b/sensors/multihal_sensors.h
@@ -17,8 +17,12 @@
#pragma once
#include <android-base/unique_fd.h>
#include <V2_1/SubHal.h>
+#include <atomic>
+#include <condition_variable>
#include <cstdint>
+#include <queue>
#include <thread>
+#include <vector>
namespace goldfish {
namespace ahs = ::android::hardware::sensors;
@@ -26,6 +30,7 @@ namespace ahs21 = ahs::V2_1;
namespace ahs10 = ahs::V1_0;
using ahs21::implementation::IHalProxyCallback;
+using ahs21::SensorInfo;
using ahs21::Event;
using ahs10::OperationMode;
using ahs10::RateLevel;
@@ -81,14 +86,18 @@ private:
float lastHingeAngle2Value = kSensorNoValue;
};
+ bool isSensorHandleValid(int sensorHandle) const;
+ bool isSensorActive(int sensorHandle) const {
+ return m_activeSensorsMask & (1u << sensorHandle); // m_mtx required
+ }
static bool activateQemuSensorImpl(int pipe, int sensorHandle, bool enabled);
- bool disableAllSensors();
+ bool setAllQemuSensors(bool enabled);
void parseQemuSensorEvent(const int pipe, QemuSensorsProtocolState* state);
void postSensorEvent(const Event& event);
- void postSensorEventLocked(const Event& event);
+ void doPostSensorEventLocked(const SensorInfo& sensor, const Event& event);
void qemuSensorListenerThread();
- static void qemuSensorListenerThreadStart(MultihalSensors* that);
+ void batchThread();
static constexpr char kCMD_QUIT = 'q';
bool qemuSensorThreadSendCommand(char cmd) const;
@@ -105,7 +114,32 @@ private:
uint32_t m_activeSensorsMask = 0;
OperationMode m_opMode = OperationMode::NORMAL;
sp<IHalProxyCallback> m_halProxyCallback;
- mutable std::mutex m_apiMtx;
+
+ // batching
+ struct BatchEventRef {
+ int64_t timestamp = -1;
+ int sensorHandle = -1;
+ int generation = 0;
+
+ bool operator<(const BatchEventRef &rhs) const {
+ // not a typo, we want m_batchQueue.top() to be the smallest timestamp
+ return timestamp > rhs.timestamp;
+ }
+ };
+
+ struct BatchInfo {
+ Event event;
+ int64_t samplingPeriodNs = 0;
+ int generation = 0;
+ };
+
+ std::priority_queue<BatchEventRef> m_batchQueue;
+ std::vector<BatchInfo> m_batchInfo;
+ std::condition_variable m_batchUpdated;
+ std::thread m_batchThread;
+ std::atomic<bool> m_batchRunning = true;
+
+ mutable std::mutex m_mtx;
};
} // namespace goldfish