AFBClient: trace dispatch_internal(), header hygiene
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Fri, 1 Sep 2017 10:55:56 +0000 (12:55 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Thu, 14 Sep 2017 12:04:51 +0000 (14:04 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
AFBClient.cpp
AFBClient.h

index 407aeac..9bcb880 100644 (file)
@@ -6,8 +6,18 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+
 #include <unistd.h>
 
+#include <systemd/sd-event.h>
+
+#include <json-c/json.h>
+
+extern "C" {
+#include <afb/afb-ws-client.h>
+#include <afb/afb-wsj1.h>
+}
+
 #define UNUSED(x) (void)(x)
 
 namespace {
@@ -28,14 +38,14 @@ constexpr const char *const wmAPI = "winman";
     ScopeTrace __attribute__((unused)) CONCAT(named_trace_scope_, __LINE__)(#N)
 
 struct ScopeTrace {
-    static int indent;
+    thread_local static int indent;
     char const *f{};
     ScopeTrace(char const *func) : f(func) {
         fprintf(stderr, "%*s%s -->\n", 2 * indent++, "", this->f);
     }
     ~ScopeTrace() { fprintf(stderr, "%*s%s <--\n", 2 * --indent, "", this->f); }
 };
-int ScopeTrace::indent = 0;
+thread_local int ScopeTrace::indent = 0;
 #endif
 
 /* called when wsj1 receives a method invocation */
@@ -73,6 +83,15 @@ void onHangup(void *closure, afb_wsj1 *wsj1) {
     exit(0);
 }
 
+static struct afb_wsj1_itf itf = {
+    onHangup, onCall, onEvent,
+};
+
+void dispatch_internal(AFBClient *c, uint64_t timeout) {
+   TRACE();
+   c->dispatch(timeout);
+}
+
 }  // namespace
 
 AFBClient &AFBClient::instance() {
@@ -81,12 +100,7 @@ AFBClient &AFBClient::instance() {
     return obj;
 }
 
-AFBClient::AFBClient() : wsj1{}, itf{}, loop{} {
-    TRACE();
-    itf.on_hangup = onHangup;
-    itf.on_call = onCall;
-    itf.on_event = onEvent;
-}
+AFBClient::AFBClient() : wsj1{}, loop{} { TRACE(); }
 
 AFBClient::~AFBClient() {
     TRACE();
@@ -267,7 +281,7 @@ int AFBClient::call(const char *verb, json_object *object,
         // if events get triggered by the call (and would be dispatched before
         // the actual call-reply).
         while (!returned) {
-            dispatch(-1);
+            dispatch_internal(this, -1);
         }
 
         // return the actual API call result
index a31479c..c6da6f7 100644 (file)
@@ -1,16 +1,13 @@
 #ifndef AFBCLIENT_H
 #define AFBCLIENT_H
 
-#include <systemd/sd-event.h>
-
 #include <functional>
 
 extern "C"
 {
-#include <json-c/json.h>
-
-#include "afb-wsj1.h"
-#include "afb-ws-client.h"
+   struct json_object;
+   struct afb_wsj1;
+   struct sd_event;
 }
 
 class AFBClient
@@ -46,13 +43,10 @@ public:
           std::function<void(char const *label)> f);
 
 private:
-    /// object will be json_object_put
     int call(const char *verb, json_object *object,
           std::function<void(bool ok, json_object*)> onReply);
 
     struct afb_wsj1 *wsj1;
-    struct afb_wsj1_itf itf;
-
-    sd_event *loop;
+    struct sd_event *loop;
 };
 #endif // AFBCLIENT_H