summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-04 13:27:43 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-14 14:04:51 +0200
commit6766079f68f6a7e2ccdd68b36e9eb206229dd4f7 (patch)
treed43593e9404ffe3bb9d375e239034b158c25f62e
parente91bb69cb8d5f239f1ad1d1d920b2d0141e21b5c (diff)
AFBClient: Pimpl'ed to hide impl details
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--AFBClient.cpp95
-rw-r--r--AFBClient.h8
2 files changed, 83 insertions, 20 deletions
diff --git a/AFBClient.cpp b/AFBClient.cpp
index 0452d16..3a8549d 100644
--- a/AFBClient.cpp
+++ b/AFBClient.cpp
@@ -89,6 +89,7 @@ static struct afb_wsj1_itf itf = {
onHangup, onCall, onEvent,
};
+// XXX: I am not sure this is the right thing to do though...
std::recursive_mutex dispatch_mutex;
void dispatch_internal(struct sd_event *loop) {
@@ -159,22 +160,45 @@ int api_call(struct sd_event *loop, struct afb_wsj1 *wsj1, const char *verb,
} // namespace
-AFBClient &AFBClient::instance() {
- TRACE();
- static AFBClient obj;
- return obj;
-}
+// _ ___ _
+// ___| | __ _ ___ ___ |_ _|_ __ ___ _ __ | |
+// / __| |/ _` / __/ __| | || '_ ` _ \| '_ \| |
+// | (__| | (_| \__ \__ \ | || | | | | | |_) | |
+// \___|_|\__,_|___/___/ |___|_| |_| |_| .__/|_|
+// |_|
+class AFBClient::Impl {
+ friend class AFBClient;
+
+ // This is the AFBClient interface impl
+ int init(int port, char const *token);
+ int dispatch();
+
+ // WM API
+ int requestSurface(const char *label);
+ int activateSurface(const char *label);
+ int deactivateSurface(const char *label);
+ int endDraw(const char *label);
+
+ void set_event_handler(enum EventType et,
+ std::function<void(char const *label)> f);
+
+ Impl();
+ ~Impl();
+
+ struct afb_wsj1 *wsj1;
+ struct sd_event *loop;
+};
-AFBClient::AFBClient() : wsj1{}, loop{} { TRACE(); }
+AFBClient::Impl::Impl() : wsj1{}, loop{} { TRACE(); }
-AFBClient::~AFBClient() {
+AFBClient::Impl::~Impl() {
TRACE();
afb_wsj1_unref(wsj1);
sd_event_unref(loop);
loop = nullptr;
}
-int AFBClient::init(int port, char const *token) {
+int AFBClient::Impl::init(int port, char const *token) {
TRACE();
char *uribuf = nullptr;
int rc = -1;
@@ -224,12 +248,12 @@ fail:
return rc;
}
-int AFBClient::dispatch() {
+int AFBClient::Impl::dispatch() {
std::lock_guard<std::recursive_mutex> guard(dispatch_mutex);
return sd_event_run(loop, 1);
}
-int AFBClient::requestSurface(const char *label) {
+int AFBClient::Impl::requestSurface(const char *label) {
TRACE();
json_object *jp = json_object_new_object();
json_object_object_add(jp, "drawing_name", json_object_new_string(label));
@@ -261,7 +285,7 @@ int AFBClient::requestSurface(const char *label) {
return rc2 < 0 ? rc2 : rc;
}
-int AFBClient::activateSurface(const char *label) {
+int AFBClient::Impl::activateSurface(const char *label) {
TRACE();
json_object *j = json_object_new_object();
json_object_object_add(j, "drawing_name", json_object_new_string(label));
@@ -276,7 +300,7 @@ int AFBClient::activateSurface(const char *label) {
});
}
-int AFBClient::deactivateSurface(const char *label) {
+int AFBClient::Impl::deactivateSurface(const char *label) {
TRACE();
json_object *j = json_object_new_object();
json_object_object_add(j, "drawing_name", json_object_new_string(label));
@@ -291,7 +315,7 @@ int AFBClient::deactivateSurface(const char *label) {
});
}
-int AFBClient::endDraw(const char *label) {
+int AFBClient::Impl::endDraw(const char *label) {
TRACE();
json_object *j = json_object_new_object();
json_object_object_add(j, "drawing_name", json_object_new_string(label));
@@ -305,10 +329,51 @@ int AFBClient::endDraw(const char *label) {
});
}
-void AFBClient::set_event_handler(enum EventType et,
- std::function<void(char const *)> func) {
+void AFBClient::Impl::set_event_handler(
+ enum EventType et, std::function<void(char const *)> func) {
UNUSED(et);
UNUSED(func);
TRACE();
// XXX todo
}
+
+// _ _ _____ ____ ____ _ _ _
+// ___| | __ _ ___ ___ / \ | ___| __ ) / ___| (_) ___ _ __ | |_
+// / __| |/ _` / __/ __| / _ \ | |_ | _ \| | | | |/ _ \ '_ \| __|
+// | (__| | (_| \__ \__ \ / ___ \| _| | |_) | |___| | | __/ | | | |_
+// \___|_|\__,_|___/___/ /_/ \_\_| |____/ \____|_|_|\___|_| |_|\__|
+//
+int AFBClient::init(int port, char const *token) {
+ return this->d->init(port, token);
+}
+
+int AFBClient::dispatch() { return this->d->dispatch(); }
+
+int AFBClient::requestSurface(const char *label) {
+ return this->d->requestSurface(label);
+}
+
+int AFBClient::activateSurface(const char *label) {
+ return this->d->activateSurface(label);
+}
+
+int AFBClient::deactivateSurface(const char *label) {
+ return this->d->deactivateSurface(label);
+}
+
+int AFBClient::endDraw(const char *label) { return this->d->endDraw(label); }
+
+void AFBClient::set_event_handler(enum EventType et,
+ std::function<void(char const *label)> f) {
+ return this->d->set_event_handler(et, std::move(f));
+}
+
+AFBClient &AFBClient::instance() {
+ TRACE();
+ static AFBClient obj;
+ return obj;
+}
+
+AFBClient::AFBClient() : d(new Impl) {}
+
+AFBClient::~AFBClient() { delete d; }
diff --git a/AFBClient.h b/AFBClient.h
index 05fa5a5..f42aeea 100644
--- a/AFBClient.h
+++ b/AFBClient.h
@@ -3,9 +3,6 @@
#include <functional>
-struct afb_wsj1;
-struct sd_event;
-
class AFBClient
{
AFBClient();
@@ -38,8 +35,9 @@ public:
void set_event_handler(enum EventType et,
std::function<void(char const *label)> f);
+ struct Impl;
+
private:
- struct afb_wsj1 *wsj1;
- struct sd_event *loop;
+ Impl *d;
};
#endif // AFBCLIENT_H