Format source codes
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Sun, 24 Jun 2018 06:25:26 +0000 (15:25 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Sun, 24 Jun 2018 06:25:26 +0000 (15:25 +0900)
Change-Id: I73ee650e65028493895144944f729005f927d872
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/json_helper.cpp
src/layers.cpp
src/layers.hpp

index 193a187..2e49778 100644 (file)
 
 #include <json.h>
 
-json_object *to_json(compositor::surface_properties const &s) {
-   // auto j = json::object({
-   auto j = json_object_new_object();
-
-   //    {"id", s.id},
-   json_object_object_add(j, "id", json_object_new_int(s.id));
-
-   //    {"size", {{"width", s.size.w}, {"height", s.size.h}}},
-   auto jsize = json_object_new_object();
-   json_object_object_add(jsize, "width", json_object_new_int(s.size.w));
-   json_object_object_add(jsize, "height", json_object_new_int(s.size.h));
-   json_object_object_add(j, "size", jsize);
-
-   //    {"dst",
-   //     {{"width", s.dst_rect.w},
-   //      {"height", s.dst_rect.h},
-   //      {"x", s.dst_rect.x},
-   //      {"y", s.dst_rect.y}}},
-   auto jdst = json_object_new_object();
-   json_object_object_add(jdst, "width", json_object_new_int(s.dst_rect.w));
-   json_object_object_add(jdst, "height", json_object_new_int(s.dst_rect.h));
-   json_object_object_add(jdst, "x", json_object_new_int(s.dst_rect.x));
-   json_object_object_add(jdst, "y", json_object_new_int(s.dst_rect.y));
-   json_object_object_add(j, "dst", jdst);
-
-   //    {"src",
-   //     {{"width", s.src_rect.w},
-   //      {"height", s.src_rect.h},
-   //      {"x", s.src_rect.x},
-   //      {"y", s.src_rect.y}}},
-   auto jsrc = json_object_new_object();
-   json_object_object_add(jsrc, "width", json_object_new_int(s.src_rect.w));
-   json_object_object_add(jsrc, "height", json_object_new_int(s.src_rect.h));
-   json_object_object_add(jsrc, "x", json_object_new_int(s.src_rect.x));
-   json_object_object_add(jsrc, "y", json_object_new_int(s.src_rect.y));
-   json_object_object_add(j, "src", jsrc);
-
-   //    {"visibility", s.visibility},
-   json_object_object_add(
-      j, "visibility",
-      json_object_new_boolean(static_cast<json_bool>(s.visibility == 1)));
-
-   //    {"opacity", s.opacity},
-   json_object_object_add(j, "opacity", json_object_new_double(s.opacity));
-
-   //    {"orientation", s.orientation},
-   json_object_object_add(j, "orientation", json_object_new_int(s.orientation));
-
-   // });
-   return j;
+json_object *to_json(compositor::surface_properties const &s)
+{
+    // auto j = json::object({
+    auto j = json_object_new_object();
+
+    //    {"id", s.id},
+    json_object_object_add(j, "id", json_object_new_int(s.id));
+
+    //    {"size", {{"width", s.size.w}, {"height", s.size.h}}},
+    auto jsize = json_object_new_object();
+    json_object_object_add(jsize, "width", json_object_new_int(s.size.w));
+    json_object_object_add(jsize, "height", json_object_new_int(s.size.h));
+    json_object_object_add(j, "size", jsize);
+
+    //    {"dst",
+    //     {{"width", s.dst_rect.w},
+    //      {"height", s.dst_rect.h},
+    //      {"x", s.dst_rect.x},
+    //      {"y", s.dst_rect.y}}},
+    auto jdst = json_object_new_object();
+    json_object_object_add(jdst, "width", json_object_new_int(s.dst_rect.w));
+    json_object_object_add(jdst, "height", json_object_new_int(s.dst_rect.h));
+    json_object_object_add(jdst, "x", json_object_new_int(s.dst_rect.x));
+    json_object_object_add(jdst, "y", json_object_new_int(s.dst_rect.y));
+    json_object_object_add(j, "dst", jdst);
+
+    //    {"src",
+    //     {{"width", s.src_rect.w},
+    //      {"height", s.src_rect.h},
+    //      {"x", s.src_rect.x},
+    //      {"y", s.src_rect.y}}},
+    auto jsrc = json_object_new_object();
+    json_object_object_add(jsrc, "width", json_object_new_int(s.src_rect.w));
+    json_object_object_add(jsrc, "height", json_object_new_int(s.src_rect.h));
+    json_object_object_add(jsrc, "x", json_object_new_int(s.src_rect.x));
+    json_object_object_add(jsrc, "y", json_object_new_int(s.src_rect.y));
+    json_object_object_add(j, "src", jsrc);
+
+    //    {"visibility", s.visibility},
+    json_object_object_add(
+        j, "visibility",
+        json_object_new_boolean(static_cast<json_bool>(s.visibility == 1)));
+
+    //    {"opacity", s.opacity},
+    json_object_object_add(j, "opacity", json_object_new_double(s.opacity));
+
+    //    {"orientation", s.orientation},
+    json_object_object_add(j, "orientation", json_object_new_int(s.orientation));
+
+    // });
+    return j;
 }
 
-json_object *to_json(compositor::screen const *s) {
-   auto o = json_object_new_object();
-   json_object_object_add(o, "id", json_object_new_int(s->id));
-   return o;
+json_object *to_json(compositor::screen const *s)
+{
+    auto o = json_object_new_object();
+    json_object_object_add(o, "id", json_object_new_int(s->id));
+    return o;
 }
 
 template <typename T>
-json_object *to_json_(T const &s) {
-   auto a = json_object_new_array();
-
-   if (!s.empty()) {
-      for (auto const &i : s) {
-         json_object_array_add(a, to_json(i.second));
-      }
-   }
-
-   return a;
+json_object *to_json_(T const &s)
+{
+    auto a = json_object_new_array();
+
+    if (!s.empty())
+    {
+        for (auto const &i : s)
+        {
+            json_object_array_add(a, to_json(i.second));
+        }
+    }
+
+    return a;
 }
 
-json_object *to_json(compositor::controller::props_map const &s) {
-   return to_json_(s);
+json_object *to_json(compositor::controller::props_map const &s)
+{
+    return to_json_(s);
 }
 
-json_object *to_json(std::vector<uint32_t> const &v) {
-   auto a = json_object_new_array();
-   for (const auto i : v) {
-      json_object_array_add(a, json_object_new_int(i));
-   }
-   return a;
+json_object *to_json(std::vector<uint32_t> const &v)
+{
+    auto a = json_object_new_array();
+    for (const auto i : v)
+    {
+        json_object_array_add(a, json_object_new_int(i));
+    }
+    return a;
 }
index 6c6be55..b6244f8 100644 (file)
@@ -26,80 +26,80 @@ using json = nlohmann::json;
 
 layer::layer(nlohmann::json const &j)
 {
-      this->role = j["role"];
-      this->name = j["name"];
-      this->layer_id = j["layer_id"];
-      this->rect = compositor::full_rect;
-      if (j["area"]["type"] == "rect")
-      {
-            auto jr = j["area"]["rect"];
-            this->rect = compositor::rect{
-                jr["width"],
-                jr["height"],
-                jr["x"],
-                jr["y"],
-            };
-      }
-
-      // Init flag of normal layout only
-      this->is_normal_layout_only = true;
-
-      auto split_layouts = j.find("split_layouts");
-      if (split_layouts != j.end())
-      {
-
-            // Clear flag of normal layout only
-            this->is_normal_layout_only = false;
-
-            auto &sls = j["split_layouts"];
-            // this->layouts.reserve(sls.size());
-            std::transform(std::cbegin(sls), std::cend(sls),
-                           std::back_inserter(this->layouts), [this](json const &sl) {
-                                 struct split_layout l
-                                 {
-                                       sl["name"], sl["main_match"], sl["sub_match"]
-                                 };
-                                 HMI_DEBUG("wm",
-                                           "layer %d add split_layout \"%s\" (main: \"%s\") (sub: "
-                                           "\"%s\")",
-                                           this->layer_id,
-                                           l.name.c_str(), l.main_match.c_str(),
-                                           l.sub_match.c_str());
-                                 return l;
-                           });
-      }
-      HMI_DEBUG("wm", "layer_id:%d is_normal_layout_only:%d\n",
-                this->layer_id, this->is_normal_layout_only);
+    this->role = j["role"];
+    this->name = j["name"];
+    this->layer_id = j["layer_id"];
+    this->rect = compositor::full_rect;
+    if (j["area"]["type"] == "rect")
+    {
+        auto jr = j["area"]["rect"];
+        this->rect = compositor::rect{
+            jr["width"],
+            jr["height"],
+            jr["x"],
+            jr["y"],
+        };
+    }
+
+    // Init flag of normal layout only
+    this->is_normal_layout_only = true;
+
+    auto split_layouts = j.find("split_layouts");
+    if (split_layouts != j.end())
+    {
+
+        // Clear flag of normal layout only
+        this->is_normal_layout_only = false;
+
+        auto &sls = j["split_layouts"];
+        // this->layouts.reserve(sls.size());
+        std::transform(std::cbegin(sls), std::cend(sls),
+                       std::back_inserter(this->layouts), [this](json const &sl) {
+                           struct split_layout l
+                           {
+                               sl["name"], sl["main_match"], sl["sub_match"]
+                           };
+                           HMI_DEBUG("wm",
+                                     "layer %d add split_layout \"%s\" (main: \"%s\") (sub: "
+                                     "\"%s\")",
+                                     this->layer_id,
+                                     l.name.c_str(), l.main_match.c_str(),
+                                     l.sub_match.c_str());
+                           return l;
+                       });
+    }
+    HMI_DEBUG("wm", "layer_id:%d is_normal_layout_only:%d\n",
+              this->layer_id, this->is_normal_layout_only);
 }
 
 struct result<struct layer_map> to_layer_map(nlohmann::json const &j)
 {
-      try
-      {
-            layer_map stl{};
-            auto m = j["mappings"];
-
-            std::transform(std::cbegin(m), std::cend(m),
-                           std::inserter(stl.mapping, stl.mapping.end()),
-                           [](nlohmann::json const &j) {
-                                 return std::pair<int, struct layer>(
-                                     j.value("layer_id", -1), layer(j));
-                           });
-
-            // TODO: add sanity checks here?
-            // * check for double IDs
-            // * check for double names/roles
-
-            stl.layers.reserve(m.size());
-            std::transform(std::cbegin(stl.mapping), std::cend(stl.mapping),
-                           std::back_inserter(stl.layers),
-                           [&stl](std::pair<int, struct layer> const &k) {
-                                 stl.roles.emplace_back(
-                                     std::make_pair(k.second.role, k.second.layer_id));
-                                 return unsigned(k.second.layer_id);
-                           });
-
-            std::sort(stl.layers.begin(), stl.layers.end());
+    try
+    {
+        layer_map stl{};
+        auto m = j["mappings"];
+
+        std::transform(std::cbegin(m), std::cend(m),
+                       std::inserter(stl.mapping, stl.mapping.end()),
+                       [](nlohmann::json const &j) {
+                           return std::pair<int, struct layer>(
+                               j.value("layer_id", -1), layer(j));
+                       });
+
+        // TODO: add sanity checks here?
+        // * check for double IDs
+        // * check for double names/roles
+
+        stl.layers.reserve(m.size());
+        std::transform(std::cbegin(stl.mapping), std::cend(stl.mapping),
+                       std::back_inserter(stl.layers),
+                       [&stl](std::pair<int, struct layer> const &k) {
+                           stl.roles.emplace_back(
+                               std::make_pair(k.second.role, k.second.layer_id));
+                           return unsigned(k.second.layer_id);
+                       });
+
+        std::sort(stl.layers.begin(), stl.layers.end());
 
             for (auto i : stl.mapping)
             {
index 5a18fad..a8ab2cc 100644 (file)
@@ -124,8 +124,48 @@ struct layer_map
 struct result<struct layer_map> to_layer_map(nlohmann::json const &j);
 
 static const nlohmann::json default_layers_json = {
-    {"main_surface", {{"surface_role", "HomeScreen"}}},
-    {"mappings", {{{"role", "^HomeScreen$"}, {"name", "HomeScreen"}, {"layer_id", 1000}, {"area", {{"type", "full"}}}}, {{"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"}, {"name", "apps"}, {"layer_id", 1001}, {"area", {{"type", "rect"}, {"rect", {{"x", 0}, {"y", 218}, {"width", -1}, {"height", -433}}}}}}, {{"role", "^OnScreen.*"}, {"name", "popups"}, {"layer_id", 9999}, {"area", {{"type", "rect"}, {"rect", {{"x", 0}, {"y", 760}, {"width", -1}, {"height", 400}}}}}}}}};
+   {"main_surface", {
+      {"surface_role", "HomeScreen"}
+   }},
+   {"mappings", {
+      {
+         {"role", "^HomeScreen$"},
+         {"name", "HomeScreen"},
+         {"layer_id", 1000},
+         {"area", {
+            {"type", "full"}
+         }}
+      },
+      {
+         {"role", "MediaPlayer|Radio|Phone|Navigation|HVAC|Settings|Dashboard|POI|Mixer"},
+         {"name", "apps"},
+         {"layer_id", 1001},
+         {"area", {
+            {"type", "rect"},
+            {"rect", {
+               {"x", 0},
+               {"y", 218},
+               {"width", -1},
+               {"height", -433}
+            }}
+         }}
+      },
+      {
+         {"role", "^OnScreen.*"},
+         {"name", "popups"},
+         {"layer_id", 9999},
+         {"area", {
+            {"type", "rect"},
+            {"rect", {
+               {"x", 0},
+               {"y", 760},
+               {"width", -1},
+               {"height", 400}
+            }}
+         }}
+      }
+   }}
+};
 } // namespace wm
 
 #endif // TMCAGLWM_LAYERS_H