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>
26 #include "afb_binding_api.hpp"
28 #include "controller_hooks.hpp"
32 #include "wayland.hpp"
45 constexpr static const unsigned id_shift = 22;
46 constexpr static const unsigned id_mask = (1 << id_shift) - 1;
50 // Surfaces that where requested but not yet created
51 std::unordered_map<unsigned, std::string> id2name;
52 // std::unordered_set<unsigned> pending_surfaces;
53 std::unordered_map<std::string, unsigned> name2id;
55 id_allocator(id_allocator const &) = delete;
56 id_allocator(id_allocator &&) = delete;
57 id_allocator &operator=(id_allocator const &);
58 id_allocator &operator=(id_allocator &&) = delete;
60 // Insert and return a new ID
61 unsigned generate_id(std::string const &name) {
62 unsigned sid = this->next++;
63 this->id2name[sid] = name;
64 // this->pending_surfaces.insert({sid});
65 this->name2id[name] = sid;
66 logdebug("allocated new id %u with name %s", sid, name.c_str());
70 // Lookup by ID or by name
71 optional<unsigned> lookup(std::string const &name) const {
72 auto i = this->name2id.find(name);
73 return i == this->name2id.end() ? nullopt : optional<unsigned>(i->second);
76 optional<std::string> lookup(unsigned id) const {
77 auto i = this->id2name.find(id);
78 return i == this->id2name.end() ? nullopt
79 : optional<std::string>(i->second);
82 // Remove a surface id and name
83 // I don't think I will need this, do I?
84 void remove_id(std::string const &name) {
85 auto i = this->name2id.find(name);
86 if (i != this->name2id.end()) {
87 this->id2name.erase(i->second);
88 this->name2id.erase(i);
92 void remove_id(unsigned id) {
93 auto i = this->id2name.find(id);
94 if (i != this->id2name.end()) {
95 this->name2id.erase(i->second);
96 this->id2name.erase(i);
102 struct binding_api api;
103 struct controller_hooks chooks;
105 // This is the one thing, we do not own.
106 struct wl::display *display;
108 std::unique_ptr<struct genivi::controller> controller;
109 std::vector<std::unique_ptr<struct wl::output>> outputs;
111 struct config config;
113 layouts_type layouts;
116 // ID allocation and proxy methods for lookup
117 struct id_allocator id_alloc;
118 optional<unsigned> lookup_id(char const *name) {
119 return this->id_alloc.lookup(std::string(name));
121 optional<std::string> lookup_name(unsigned id) {
122 return this->id_alloc.lookup(id);
125 std::deque<unsigned> last_active;
127 explicit App(wl::display *d);
130 App(App const &) = delete;
131 App &operator=(App const &) = delete;
132 App(App &&) = delete;
133 App &operator=(App &&) = delete;
138 int dispatch_events();
140 void surface_set_layout(uint32_t surface_id);
142 // Allocate a surface ID for this role
143 result<int> request_surface(char const *drawing_name);
145 // Activate (i.e. make visible, if allowed!) a surface
146 char const *activate_surface(char const *drawing_name);
147 char const *deactivate_surface(char const *drawing_name);
149 // Events from the compositor we are interested in
150 void surface_created(uint32_t surface_id);
151 void surface_removed(uint32_t surface_id);
153 // TMC WM Events to clients
154 void emit_activated(char const *label);
155 void emit_deactivated(char const *label);
156 void emit_syncdraw(char const *label);
157 void emit_flushdraw(char const *label);
158 void emit_visible(char const *label, bool is_visible);
163 #endif // TMCAGLWM_APP_HPP