Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#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 {
#define UNUSED(x) (void)(x)
namespace {
ScopeTrace __attribute__((unused)) CONCAT(named_trace_scope_, __LINE__)(#N)
struct ScopeTrace {
ScopeTrace __attribute__((unused)) CONCAT(named_trace_scope_, __LINE__)(#N)
struct ScopeTrace {
+ 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); }
};
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 */
#endif
/* called when wsj1 receives a method invocation */
+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() {
} // namespace
AFBClient &AFBClient::instance() {
-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();
AFBClient::~AFBClient() {
TRACE();
// if events get triggered by the call (and would be dispatched before
// the actual call-reply).
while (!returned) {
// if events get triggered by the call (and would be dispatched before
// the actual call-reply).
while (!returned) {
+ dispatch_internal(this, -1);
}
// return the actual API call result
}
// return the actual API call result
#ifndef AFBCLIENT_H
#define AFBCLIENT_H
#ifndef AFBCLIENT_H
#define AFBCLIENT_H
-#include <systemd/sd-event.h>
-
#include <functional>
extern "C"
{
#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;
std::function<void(char const *label)> f);
private:
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;
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;