+} // namespace
+
+optional<int> layer_map::get_layer_id(int surface_id) {
+ auto e = get_surface_id_to_layer(this, surface_id);
+ if (!e) {
+ auto i = this->surfaces.find(surface_id);
+ if (i != this->surfaces.end()) {
+ return optional<int>(int(i->second));
+ }
+ return nullopt;
+ }
+ return optional<int>(e->layer_id);
+}
+
+optional<int> layer_map::get_layer_id(std::string const &role) {
+ for (auto const &r : this->roles) {
+ auto re = std::regex(r.first);
+ if (std::regex_match(role, re)) {
+ logdebug("role %s matches layer %d", role.c_str(), r.second);
+ return optional<int>(r.second);
+ }
+ }
+ logdebug("role %s does NOT match any layer", role.c_str());
+ return nullopt;
+}
+
+optional<genivi::rect> layer_map::get_layer_rect(int surface_id) {
+ auto e = get_surface_id_to_layer(this, surface_id);
+ return e ? optional<genivi::rect>(e->rect) : nullopt;
+}
+
+json layer::to_json() const {
+ auto is_full = this->rect == genivi::full_rect;
+
+ json r{};
+ if (is_full) {
+ r = {{"type", "full"}};
+ } else {
+ r = {{"type", "rect"},
+ {"rect",
+ {{"x", this->rect.x},
+ {"y", this->rect.y},
+ {"width", this->rect.w},
+ {"height", this->rect.h}}}};
+ }
+
+ return {
+ {"id_min", this->id_min}, {"id_max", this->id_max},
+ {"name", this->name}, {"role", this->role},
+ {"layer_id", this->layer_id}, {"area", r},
+ };
+}
+
+json layer_map::to_json() const {
+ json j{};
+ for (auto const &i : this->mapping) {
+ j.push_back(i.to_json());
+ }
+ return j;
+}