-
-struct id_allocator {
- unsigned next = 1;
-
- // Surfaces that where requested but not yet created
- std::unordered_map<unsigned, std::string> id2name;
- // std::unordered_set<unsigned> pending_surfaces;
- std::unordered_map<std::string, unsigned> name2id;
-
- id_allocator(id_allocator const &) = delete;
- id_allocator(id_allocator &&) = delete;
- id_allocator &operator=(id_allocator const &);
- id_allocator &operator=(id_allocator &&) = delete;
-
- // Insert and return a new ID
- unsigned generate_id(std::string const &name) {
- unsigned sid = this->next++;
- this->id2name[sid] = name;
- // this->pending_surfaces.insert({sid});
- this->name2id[name] = sid;
- HMI_DEBUG("wm", "allocated new id %u with name %s", sid, name.c_str());
- return sid;
- }
-
- // Insert a new ID which defined outside
- void register_name_id(std::string const &name, unsigned sid) {
- this->id2name[sid] = name;
- this->name2id[name] = sid;
- HMI_DEBUG("wm", "register id %u with name %s", sid, name.c_str());
- return;
- }
-
- // Lookup by ID or by name
- optional<unsigned> lookup(std::string const &name) const {
- auto i = this->name2id.find(name);
- return i == this->name2id.end() ? nullopt : optional<unsigned>(i->second);
- }
-
- optional<std::string> lookup(unsigned id) const {
- auto i = this->id2name.find(id);
- return i == this->id2name.end() ? nullopt
- : optional<std::string>(i->second);
- }
-
- // Remove a surface id and name
- void remove_id(std::string const &name) {
- auto i = this->name2id.find(name);
- if (i != this->name2id.end()) {
- this->id2name.erase(i->second);
- this->name2id.erase(i);
- }
- }
-
- void remove_id(unsigned id) {
- auto i = this->id2name.find(id);
- if (i != this->id2name.end()) {
- this->name2id.erase(i->second);
- this->id2name.erase(i);
- }
- }
+class AppList;
+
+struct id_allocator
+{
+ unsigned next = 1;
+
+ // Surfaces that where requested but not yet created
+ std::unordered_map<unsigned, std::string> id2name;
+ // std::unordered_set<unsigned> pending_surfaces;
+ std::unordered_map<std::string, unsigned> name2id;
+
+ id_allocator(id_allocator const &) = delete;
+ id_allocator(id_allocator &&) = delete;
+ id_allocator &operator=(id_allocator const &);
+ id_allocator &operator=(id_allocator &&) = delete;
+
+ // Insert and return a new ID
+ unsigned generate_id(std::string const &name)
+ {
+ unsigned sid = this->next++;
+ this->id2name[sid] = name;
+ // this->pending_surfaces.insert({sid});
+ this->name2id[name] = sid;
+ HMI_DEBUG("wm", "allocated new id %u with name %s", sid, name.c_str());
+ return sid;
+ }
+
+ // Insert a new ID which defined outside
+ void register_name_id(std::string const &name, unsigned sid)
+ {
+ this->id2name[sid] = name;
+ this->name2id[name] = sid;
+ HMI_DEBUG("wm", "register id %u with name %s", sid, name.c_str());
+ return;
+ }
+
+ // Lookup by ID or by name
+ optional<unsigned> lookup(std::string const &name) const
+ {
+ auto i = this->name2id.find(name);
+ return i == this->name2id.end() ? nullopt : optional<unsigned>(i->second);
+ }
+
+ optional<std::string> lookup(unsigned id) const
+ {
+ auto i = this->id2name.find(id);
+ return i == this->id2name.end() ? nullopt
+ : optional<std::string>(i->second);
+ }
+
+ // Remove a surface id and name
+ void remove_id(std::string const &name)
+ {
+ auto i = this->name2id.find(name);
+ if (i != this->name2id.end())
+ {
+ this->id2name.erase(i->second);
+ this->name2id.erase(i);
+ }
+ }
+
+ void remove_id(unsigned id)
+ {
+ auto i = this->id2name.find(id);
+ if (i != this->id2name.end())
+ {
+ this->name2id.erase(i->second);
+ this->id2name.erase(i);
+ }
+ }