Add operator<< for printing some dispatcher structs
When working on dispatcher code, it's very convenient to be able to
quickly print some of the dispatcher structs, like TouchState,
TouchedWindow, etc. Add operator<< to some of these structs in this CL.
This removes the need to memorize the specific function that needs to be
called, like "dump", "getDescription", etc.
Bug: 211379801
Test: none
Change-Id: I663b217a3449daa34476ac6f28f188cdf0618278
diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp
index cb369a8..fa8f548 100644
--- a/services/inputflinger/dispatcher/Entry.cpp
+++ b/services/inputflinger/dispatcher/Entry.cpp
@@ -269,6 +269,11 @@
return msg;
}
+std::ostream& operator<<(std::ostream& out, const MotionEntry& motionEntry) {
+ out << motionEntry.getDescription();
+ return out;
+}
+
// --- SensorEntry ---
SensorEntry::SensorEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h
index 8dc2a2a..dd4aab8 100644
--- a/services/inputflinger/dispatcher/Entry.h
+++ b/services/inputflinger/dispatcher/Entry.h
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <utils/Timers.h>
#include <functional>
+#include <ostream>
#include <string>
namespace android::inputdispatcher {
@@ -189,6 +190,8 @@
~MotionEntry() override;
};
+std::ostream& operator<<(std::ostream& out, const MotionEntry& motionEntry);
+
struct SensorEntry : EventEntry {
int32_t deviceId;
uint32_t source;
diff --git a/services/inputflinger/dispatcher/TouchState.cpp b/services/inputflinger/dispatcher/TouchState.cpp
index 4221e42..9dcf615 100644
--- a/services/inputflinger/dispatcher/TouchState.cpp
+++ b/services/inputflinger/dispatcher/TouchState.cpp
@@ -288,4 +288,9 @@
return out;
}
+std::ostream& operator<<(std::ostream& out, const TouchState& state) {
+ out << state.dump();
+ return out;
+}
+
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/TouchState.h b/services/inputflinger/dispatcher/TouchState.h
index 39e63e5..f016936 100644
--- a/services/inputflinger/dispatcher/TouchState.h
+++ b/services/inputflinger/dispatcher/TouchState.h
@@ -17,6 +17,7 @@
#pragma once
#include <bitset>
+#include <ostream>
#include <set>
#include "TouchedWindow.h"
@@ -79,5 +80,7 @@
std::string dump() const;
};
+std::ostream& operator<<(std::ostream& out, const TouchState& state);
+
} // namespace inputdispatcher
} // namespace android
diff --git a/services/inputflinger/dispatcher/TouchedWindow.cpp b/services/inputflinger/dispatcher/TouchedWindow.cpp
index 9807a6d..ff4b425 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.cpp
+++ b/services/inputflinger/dispatcher/TouchedWindow.cpp
@@ -256,5 +256,10 @@
return out;
}
+std::ostream& operator<<(std::ostream& out, const TouchedWindow& window) {
+ out << window.dump();
+ return out;
+}
+
} // namespace inputdispatcher
} // namespace android
diff --git a/services/inputflinger/dispatcher/TouchedWindow.h b/services/inputflinger/dispatcher/TouchedWindow.h
index 0a38f9f..3f760c0 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.h
+++ b/services/inputflinger/dispatcher/TouchedWindow.h
@@ -20,6 +20,7 @@
#include <input/Input.h>
#include <utils/BitSet.h>
#include <bitset>
+#include <ostream>
#include <set>
#include "InputTarget.h"
@@ -92,5 +93,7 @@
static std::string deviceStateToString(const TouchedWindow::DeviceState& state);
};
+std::ostream& operator<<(std::ostream& out, const TouchedWindow& window);
+
} // namespace inputdispatcher
} // namespace android