X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=AFBClient.cpp;h=e47e23f3c3a1ab1f1b83e1e68f0a99ef0a9aa243;hb=4289b00ecc6a813454374c0a445c2331cb79c41b;hp=5ffad29c6608c18a7f473751b328379851ad1407;hpb=daac597f2ffe16f19b0669e69c91a323b0122d4b;p=staging%2Fwindowmanager.git diff --git a/AFBClient.cpp b/AFBClient.cpp index 5ffad29..e47e23f 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -110,9 +110,8 @@ void onHangup(void *closure, afb_wsj1 *wsj1) { TRACE(); UNUSED(closure); UNUSED(wsj1); - printf("ON-HANGUP\n"); - fflush(stdout); - exit(0); + fputs("Hangup, the WindowManager vanished\n", stderr); + exit(1); } constexpr struct afb_wsj1_itf itf = { @@ -206,7 +205,6 @@ AFBClient::Impl::~Impl() { TRACE(); afb_wsj1_unref(wsj1); sd_event_unref(loop); - loop = nullptr; } int AFBClient::Impl::init(int port, char const *token) { @@ -214,28 +212,34 @@ int AFBClient::Impl::init(int port, char const *token) { char *uribuf = nullptr; int rc = -1; + if (this->loop != nullptr && this->wsj1 != nullptr) { + fputs("AFBClient instance is already initialized!\n", stderr); + rc = -EALREADY; + goto fail; + } + if ((token == nullptr) || strlen(token) > token_maxlen) { - fprintf(stderr, "Token is invalid\n"); + fputs("Token is invalid\n", stderr); rc = -EINVAL; goto fail; } for (char const *p = token; *p != 0; p++) { if (isalnum(*p) == 0) { - fprintf(stderr, "Token is invalid\n"); + fputs("Token is invalid\n", stderr); rc = -EINVAL; goto fail; } } if (port < 1 && port > 0xffff) { - fprintf(stderr, "Port is invalid\n"); + fputs("Port is invalid\n", stderr); rc = -EINVAL; goto fail; } /* get the default event loop */ - rc = sd_event_default(&loop); + rc = sd_event_default(&this->loop); if (rc < 0) { fprintf(stderr, "Connection to default event loop failed: %s\n", strerror(-rc)); @@ -245,10 +249,11 @@ int AFBClient::Impl::init(int port, char const *token) { asprintf(&uribuf, "ws://localhost:%d/api?token=%s", port, token); /* connect the websocket wsj1 to the uri given by the first argument */ - wsj1 = afb_ws_client_connect_wsj1( - loop, uribuf, const_cast(&itf), this); - if (wsj1 == nullptr) { - sd_event_unref(loop); + this->wsj1 = afb_ws_client_connect_wsj1( + this->loop, uribuf, const_cast(&itf), this); + if (this->wsj1 == nullptr) { + sd_event_unref(this->loop); + this->loop = nullptr; fprintf(stderr, "Connection to %s failed: %m\n", uribuf); rc = -errno; goto fail; @@ -262,14 +267,15 @@ fail: int AFBClient::Impl::dispatch() { std::lock_guard guard(dispatch_mutex); - return sd_event_run(loop, 1); + return sd_event_run(this->loop, 1); +} } int AFBClient::Impl::requestSurface(const char *label) { TRACE(); if (this->labels.find(label) != this->labels.end()) { - fprintf(stderr, "Surface label already known!\n"); + fputs("Surface label already known!\n", stderr); return -EINVAL; }