main/app: started to move things to app
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 11 Jul 2017 13:18:42 +0000 (15:18 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Started implementing App, as the actual implementation, that is, to
pull out all the stuff that is actually the application and only have
glue code reside in main.

Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/CMakeLists.txt
src/app.cpp [new file with mode: 0644]
src/app.hpp [new file with mode: 0644]
src/main.cpp

index 62bdc9f..15ecc3c 100644 (file)
@@ -13,7 +13,7 @@ add_library(winman MODULE
    wayland.hpp
    util.cpp
    util.hpp
-   ${IVI_CON_PROTO} json_helper.cpp json_helper.hpp)
+   ${IVI_CON_PROTO} json_helper.cpp json_helper.hpp app.hpp app.cpp)
 
 target_include_directories(winman
     PRIVATE
diff --git a/src/app.cpp b/src/app.cpp
new file mode 100644 (file)
index 0000000..5da4f9d
--- /dev/null
@@ -0,0 +1,30 @@
+//
+// Created by mfritzsc on 7/11/17.
+//
+
+#include "app.hpp"
+
+namespace wm {
+
+    App::App()
+            : api{this}
+    {}
+
+    result<char const *, json> App::API::register_surface(uint32_t appid,
+                                                          uint32_t surfid) {
+        return Err<char const *, json>("not implemented");
+    }
+
+    result<char const *, json> App::API::debug_layers() const {
+        return Err<char const *, json>("not implemented");
+    }
+
+    result<char const *, json> App::API::debug_surfaces() const {
+        return Err<char const *, json>("not implemented");
+    }
+
+    result<char const *, json> App::API::debug_status() const {
+        return Err<char const *, json>("not implemented");
+    }
+
+} // namespace wm
\ No newline at end of file
diff --git a/src/app.hpp b/src/app.hpp
new file mode 100644 (file)
index 0000000..a3108b3
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// Created by mfritzsc on 7/11/17.
+//
+
+#ifndef TMCAGLWM_APP_HPP
+#define TMCAGLWM_APP_HPP
+
+#include <json.hpp>
+#include <experimental/optional>
+
+namespace wm {
+
+    using std::experimental::optional;
+    using std::experimental::nullopt;
+
+    template <typename E, typename T>
+    struct result {
+        optional<E> e;
+        optional<T> t;
+
+        bool is_ok() const { return this->t != nullopt; }
+        bool is_err() const { return this->e != nullopt; }
+        T unwrap() { return this->t.value(); }
+    };
+
+    template <typename E, typename T>
+    struct result<E, T> Err(E e) { return result<E, T>{e, nullopt}; }
+
+    template <typename E, typename T>
+    struct result<E, T> Ok(T t) { return result<E, T>{nullopt, t}; }
+
+    using json = nlohmann::json;
+
+    struct App {
+        struct API {
+            struct App *app;
+
+            result<char const *, json> debug_status() const;
+            result<char const *, json> debug_layers() const;
+            result<char const *, json> debug_surfaces() const;
+
+            result<char const *, json> register_surface(uint32_t appid, uint32_t surfid);
+        };
+
+        struct API api;
+
+        App();
+    };
+
+} // namespace wm
+
+#endif //TMCAGLWM_APP_HPP
index 4593f22..5c9df33 100644 (file)
@@ -1,6 +1,7 @@
 #include "json_helper.hpp"
 #include "util.hpp"
 #include "wayland.hpp"
+#include "app.hpp"
 
 #include <algorithm>
 #include <json.h>
@@ -211,6 +212,12 @@ void debug_status(struct afb_req req) {
    // Quick and dirty, dump current surfaces and layers
    AFB_REQ_DEBUG(req, "status");
 
+   // auto r = g_afb_instance->app.api.debug_status();
+   // if (r.is_err()) {
+   //    afb_req_fail(req, "failed", r.e.value());
+   //    return;
+   // }
+
    auto o = json_object_new_object();
    json_object_object_add(o, "surfaces",
                           to_json(g_afb_instance->controller->sprops));