init: switch out keychord id with std::vector match of chords
Drop all references to keychord_id and id and instead use keycodes_
as the id. The keycodes are a std::vector<int> with an unique
sorted-order emplacement method added in the parser. Solves the
academic issue with duplicate keychords and trigger all services
that match rather than first match only.
Test: init_tests
Bug: 64114943
Change-Id: I5582779d81458fda393004c551c0d3c03d9471e0
diff --git a/init/keychords.h b/init/keychords.h
index 74a9195..00ed205 100644
--- a/init/keychords.h
+++ b/init/keychords.h
@@ -36,8 +36,8 @@
Keychords& operator=(Keychords&&) = delete;
~Keychords() noexcept;
- int GetId(const std::vector<int>& keycodes);
- void Start(Epoll* epoll, std::function<void(int)> handler);
+ void Register(const std::vector<int>& keycodes);
+ void Start(Epoll* epoll, std::function<void(const std::vector<int>&)> handler);
private:
// Bit management
@@ -65,10 +65,8 @@
};
struct Entry {
- Entry(const std::vector<int>& keycodes, int id);
+ Entry();
- const std::vector<int> keycodes;
- const int id;
bool notified;
};
@@ -84,12 +82,11 @@
void GeteventCloseDevice(const std::string& device);
Epoll* epoll_;
- std::function<void(int)> handler_;
+ std::function<void(const std::vector<int>&)> handler_;
std::map<std::string, int> registration_;
- int count_;
- std::vector<Entry> entries_;
+ std::map<const std::vector<int>, Entry> entries_;
Mask current_;