+ return Err<struct layer_map>(e.what());
+ }
+}
+
+optional<int> layer_map::get_layer_id(int surface_id) {
+ auto i = this->surfaces.find(surface_id);
+ if (i != this->surfaces.end()) {
+ return optional<int>(i->second);
+ }
+ return nullopt;
+}
+
+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;
+}
+
+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 {
+ {"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.second.to_json());