d776057a4fa31380f2a087f9f3af71665ea75f84
[staging/windowmanager.git] / AFBClient.h
1 #ifndef AFBCLIENT_H
2 #define AFBCLIENT_H
3
4 #include <systemd/sd-event.h>
5
6 #include <functional>
7
8 extern "C"
9 {
10 #include <json-c/json.h>
11
12 #include "afb-wsj1.h"
13 #include "afb-ws-client.h"
14 }
15
16 class AFBClient
17 {
18     AFBClient();
19     ~AFBClient();
20
21     AFBClient(const AFBClient &) = delete;
22     AFBClient &operator=(const AFBClient &) = delete;
23
24 public:
25     enum EventType {
26        Event_Active = 1,
27        Event_Inactive,
28        Event_Visible,
29        Event_Invisible,
30        Event_SyncDraw,
31        Event_FlushDraw,
32     };
33
34     static AFBClient &instance();
35
36     int init(int port, char const *token);
37     int dispatch(uint64_t timeout);
38
39     // WM API
40     int requestSurface(const char *label);
41     int activateSurface(const char *label);
42     int deactivateSurface(const char *label);
43     int endDraw(const char *label);
44
45     void set_event_handler(enum EventType et, std::function<void(char const *label)> f);
46
47 private:
48     void call(const char *api, const char *verb, const char *object);
49
50     struct afb_wsj1 *wsj1;
51     struct afb_wsj1_itf itf;
52
53     sd_event *loop;
54 };
55 #endif // AFBCLIENT_H