Add set_event_handler, added int returns for all API methods.
[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     explicit AFBClient();
19     AFBClient(const AFBClient& that) = delete;
20     virtual~AFBClient();
21
22 public:
23     enum EventType {
24        Event_Active = 1,
25        Event_Inactive,
26        Event_Visible,
27        Event_Invisible,
28        Event_SyncDraw,
29        Event_FlushDraw,
30     };
31
32     static AFBClient &instance()
33     {
34         static AFBClient obj;
35         return obj;
36     }
37
38     int init(int port, char const *token);
39     int dispatch(uint64_t timeout);
40
41     // WM API
42     int requestSurface(const char *label);
43     int activateSurface(const char *label);
44     int deactivateSurface(const char *label);
45     int endDraw(const char *label);
46
47     void set_event_handler(enum EventType et, std::function<void(char const *label)> f);
48
49     static void onCall(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
50     static void onEvent(void *closure, const char *event, struct afb_wsj1_msg *msg);
51     static void onHangup(void *closure, struct afb_wsj1 *wsj1);
52     static void onReply(void *closure, struct afb_wsj1_msg *msg);
53
54 private:
55     void call(const char *api, const char *verb, const char *object);
56     void event(const char *event, const char *object);
57
58     struct afb_wsj1 *wsj1;
59     struct afb_wsj1_itf itf;
60
61     sd_event *loop;
62     static const char *wmURI;
63     static const char *wmAPI;
64 };
65 #endif // AFBCLIENT_H