summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-06-29 14:29:13 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:24:00 +0200
commit1c2a6b6e01836423ca4168cc3f067a113efe654b (patch)
tree5744570f1f3eb9271c2f429c6ae373d9eca98e09
parent5968e97fec8fe24398f05c694d6882895671b9f6 (diff)
main: rename connection, streamline init_layout and error handling
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--src/main.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7734d97..52d6b32 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,7 +5,7 @@
#include <sys/poll.h>
-struct conn {
+struct connection {
std::vector<std::unique_ptr<wl::output>> outputs;
std::unique_ptr<genivi::controller> c;
};
@@ -17,7 +17,7 @@ namespace {
// | (__| | | | __/ (__| < | __/\ V / __/ | | | |_\__ \ | | |
// \___|_| |_|\___|\___|_|\_\___\___| \_/ \___|_| |_|\__|___/ | | |
// |_____| \_\/_/
-int check_events(struct wl::display &d, struct conn &c, int fd) {
+int check_events(struct wl::display &d, struct connection &c, int fd) {
struct pollfd pfd[2] = {{.fd = d.get_fd(), .events = POLLIN, .revents = 0},
{.fd = fd, .events = POLLIN, .revents = 0}};
@@ -76,7 +76,15 @@ int check_events(struct wl::display &d, struct conn &c, int fd) {
// | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
// |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
// |_____| |___/ \_\/_/
-void init_layout(struct conn &c) {
+char const *init_layout(struct connection &c) {
+ if (!c.c) {
+ return "ivi_controller global not available";
+ }
+
+ if (c.outputs.empty()) {
+ return "no output was set up!";
+ }
+
auto &o = c.outputs.front();
auto &s = c.c->screens.begin()->second;
auto &layers = c.c->layers;
@@ -108,6 +116,8 @@ void init_layout(struct conn &c) {
c.c->commit_changes();
// Note: this does not flush the display!
+
+ return nullptr;
}
} // namespace
@@ -129,7 +139,7 @@ int main(int /*argc*/, char ** /*argv*/) {
fatal("Could not connect to compositor");
}
- struct conn c {};
+ struct connection c {};
d.r.add_global_handler(
"ivi_controller", [&c](wl_registry *r, uint32_t name, uint32_t v) {
@@ -148,22 +158,14 @@ int main(int /*argc*/, char ** /*argv*/) {
// Third level objects
d.roundtrip();
- if (!c.c) {
- fatal("ivi_controller global not available");
- }
-
- if (c.outputs.empty()) {
- fatal("no output was set up!");
+ if (char const *e = init_layout(c)) {
+ fatal("Could not init layout: %s", e);
}
- init_layout(c);
-
while (check_events(d, c, STDIN_FILENO) != -1) {
c.c->execute_pending();
d.flush();
}
- d.roundtrip();
-
return 0;
}