diff options
author | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-01 12:55:56 +0200 |
---|---|---|
committer | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-14 14:04:51 +0200 |
commit | 31768957cd3e7ce3152db910b487ff73b73fffc4 (patch) | |
tree | b22c9038d058b69d28919e6a7d1884624dbd8b2a | |
parent | b8ec6408f237065d6f87a23bcfe6c20ac56528bf (diff) |
AFBClient: trace dispatch_internal(), header hygiene
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r-- | AFBClient.cpp | 32 | ||||
-rw-r--r-- | AFBClient.h | 14 |
2 files changed, 27 insertions, 19 deletions
diff --git a/AFBClient.cpp b/AFBClient.cpp index 407aeac..9bcb880 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -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 diff --git a/AFBClient.h b/AFBClient.h index a31479c..c6da6f7 100644 --- a/AFBClient.h +++ b/AFBClient.h @@ -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 |