2 * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef TMCAGLWM_APP_HPP
18 #define TMCAGLWM_APP_HPP
20 #include <json-c/json.h>
22 #include <unordered_map>
23 #include <unordered_set>
25 #include "afb_binding_api.hpp"
27 #include "controller_hooks.hpp"
31 #include "wayland.hpp"
44 unsigned next = 0x0100'0000;
46 // Surfaces that where requested but not yet created
47 std::unordered_map<unsigned, std::string> surfaces;
48 // std::unordered_set<unsigned> pending_surfaces;
49 std::unordered_map<std::string, unsigned> names;
51 id_allocator(id_allocator const &) = delete;
52 id_allocator(id_allocator &&) = delete;
53 id_allocator &operator=(id_allocator const &);
54 id_allocator &operator=(id_allocator &&) = delete;
56 // Insert and return a new ID
57 unsigned generate_id(std::string const &name) {
58 unsigned sid = this->next++;
59 this->surfaces[sid] = name;
60 // this->pending_surfaces.insert({sid});
61 this->names[name] = sid;
62 logdebug("allocated new id %u with name %s", sid, name.c_str());
66 // Lookup by ID or by name
67 optional<unsigned> lookup(std::string const &name) const {
68 auto i = this->names.find(name);
69 return i == this->names.end() ? nullopt : optional<unsigned>(i->second);
72 optional<std::string> lookup(unsigned id) const {
73 auto i = this->surfaces.find(id);
74 return i == this->surfaces.end() ? nullopt
75 : optional<std::string>(i->second);
78 // Remove a surface id and name
79 // I don't think I will need this, do I?
80 void remove_id(std::string const &name) {
81 auto i = this->names.find(name);
82 if (i != this->names.end()) {
83 this->surfaces.erase(i->second);
88 void remove_id(unsigned id) {
89 auto i = this->surfaces.find(id);
90 if (i != this->surfaces.end()) {
91 this->names.erase(i->second);
92 this->surfaces.erase(i);
98 struct binding_api api;
99 struct controller_hooks chooks;
101 // This is the one thing, we do not own.
102 struct wl::display *display;
104 std::unique_ptr<struct genivi::controller> controller;
105 std::vector<std::unique_ptr<struct wl::output>> outputs;
107 struct config config;
109 layouts_type layouts;
112 typedef std::pair<char const *, std::function<void()>> name_task_pair;
113 std::vector<name_task_pair> pending;
115 typedef std::map<std::string, int> drawing_name_map;
116 drawing_name_map name_mapping;
118 struct id_allocator id_alloc;
120 explicit App(wl::display *d);
123 App(App const &) = delete;
124 App &operator=(App const &) = delete;
125 App(App &&) = delete;
126 App &operator=(App &&) = delete;
131 int dispatch_events();
133 void surface_set_layout(uint32_t surface_id);
134 char const *activate_surface(uint32_t surface_id);
136 // Allocate a surface ID for this role
137 result<int> request_surface(char const *drawing_name);
139 // Activate (i.e. make visible, if allowed!) a surface
140 char const *activate_surface(char const *drawing_name);
142 // add tasks, executed after dispatch_events()
143 void add_task(char const *name, std::function<void()> &&f);
144 void execute_pending();
146 // Events from the compositor we are interested in
147 void surface_created(uint32_t surface_id);
148 void surface_removed(uint32_t surface_id);
153 #endif // TMCAGLWM_APP_HPP