Application code clean-up
[staging/windowmanager.git] / AFBClient.cpp
index 6a57310..a009610 100644 (file)
@@ -8,14 +8,6 @@
 
 #define UNUSED(x) (void)(x)
 
-extern "C" {
-extern struct afb_wsj1 *afb_ws_client_connect_wsj1(struct sd_event *eloop, const char *uri, struct afb_wsj1_itf *itf, void *closure);
-extern int afb_wsj1_call_s(struct afb_wsj1 *wsj1, const char *api, const char *verb, const char *object, void (*on_reply)(void *closure, struct afb_wsj1_msg *msg), void *closure);
-extern int afb_wsj1_msg_is_reply_ok(struct afb_wsj1_msg *msg);
-extern int afb_wsj1_send_event_s(struct afb_wsj1 *wsj1, const char *event, const char *object);
-static inline int afb_wsj1_reply_error_s(struct afb_wsj1_msg *msg, const char *object, const char *token);
-}
-
 const char * AFBClient::wmURI = "ws://localhost:1700/api?token=wm";
 const char * AFBClient::wmAPI = "winman";
 
@@ -33,7 +25,7 @@ AFBClient::~AFBClient()
 
 bool AFBClient::init()
 {
-    printf("init() -->\n");
+    printf("AFBClient::init() -->\n");
     /* get the default event loop */
     int rc = sd_event_default(&loop);
     if (rc < 0) {
@@ -48,13 +40,17 @@ bool AFBClient::init()
         return false;
     }
 
-    printf("init() <--\n");
+    printf("AFBClient::init() <--\n");
     return true;
 }
 
+int AFBClient::dispatch(uint64_t timeout) {
+    return sd_event_run(loop, timeout);
+}
+
 int AFBClient::requestSurface(const char *label)
 {
-   printf("requestSurface(%s) -->\n", label);
+   printf("AFBClient::requestSurface(%s) -->\n", label);
    constexpr char const *verb = "request_surface";
    int ret = -1;
 
@@ -67,7 +63,7 @@ int AFBClient::requestSurface(const char *label)
       bool is_not_set;
    };
 
-   constexpr struct optional nullopt = {0, true};
+   constexpr struct optional const nullopt = {0, true};
    auto id = nullopt;
 
    /* send the request */
@@ -105,14 +101,14 @@ int AFBClient::requestSurface(const char *label)
       }
    }
 
-   printf("requestSurface(%s) = %d <--\n", label, ret);
+   printf("AFBClient::requestSurface(%s) = %d <--\n", label, ret);
 
    return ret;
 }
 
 void AFBClient::activateSurface(const char *label)
 {
-    printf("activateSurface(%s) -->\n", label);
+    printf("AFBClient::activateSurface(%s) -->\n", label);
     fflush(stdout);
 
     const char begin[] = "{\"drawing_name\":\"";
@@ -129,22 +125,34 @@ void AFBClient::activateSurface(const char *label)
     // Sync this one too
     dispatch(-1);
 
-    printf("activateSurface(%s) <--\n", label);
+    printf("AFBClient::activateSurface(%s) <--\n", label);
     fflush(stdout);
 }
 
-int AFBClient::dispatch(uint64_t timeout) {
-    return sd_event_run(loop, timeout);
-}
-
 void AFBClient::deactivateSurface(const char *label)
 {
-    UNUSED(label);
+    printf("AFBClient::deactivateSurface(%s) -->\n", label);
+    fflush(stdout);
+    json_object *j = json_object_new_object();
+    json_object_object_add(j, "drawing_name", json_object_new_string(label));
+    call(AFBClient::wmAPI, "deactivate_surface", json_object_to_json_string(j));
+    json_object_put(j);
+    dispatch(-1);
+    printf("AFBClient::deactivateSurface(%s) <--\n", label);
+    fflush(stdout);
 }
 
 void AFBClient::endDraw(const char *label)
 {
-    UNUSED(label);
+    printf("AFBClient::endDraw(%s) -->\n", label);
+    fflush(stdout);
+    json_object *j = json_object_new_object();
+    json_object_object_add(j, "drawing_name", json_object_new_string(label));
+    call(AFBClient::wmAPI, "enddraw", json_object_to_json_string(j));
+    json_object_put(j);
+    dispatch(-1);
+    printf("AFBClient::endDraw(%s) <--\n", label);
+    fflush(stdout);
 }
 
 /* called when wsj1 receives a method invocation */