]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blob - mt_server.h
queue input events
[coffee/mt-apps.git] / mt_server.h
1 #ifndef MT_SERVER_H
2 #define MT_SERVER_H
3
4 #include <ev.h>
5 #include <libwebsockets.h>
6
7 // set these two according to your data
8 // rx buf size must be >= permessage-deflate rx size
9 #define MT_PROTOCOL_RX_BUFFER_SIZE 128
10 #define INPUT_LINE_LENGTH          512
11
12 #define HTTP_PORT       80                    // listen here
13 #define HTTP_MOUNTPOINT "/"                   // mountpoint URL
14 #define HTTP_ORIGIN     "/usr/share/mtserver" // where the html files are
15 #define HTTP_DEFAULT    "index.html"          // default filename
16
17 #define JSON_EMPTY "{\"type\":\"empty\"}" // default message
18
19 typedef struct list {
20     char *line;
21     struct list *next;
22 } list;
23
24 typedef struct ev_io_ws {
25     ev_io w;                     // input watcher
26     struct lws_context *context;
27     list *lines;
28     char *text;                  // input buffer pointer
29     char *pos;                   // input buffer current position pointer
30 } ev_io_ws;
31
32 typedef struct mt_server_t {
33     struct lws_context *context;
34     ev_io_ws fd_watcher;         // input watcher
35 } mt_server_t;
36
37 // init self, add it to loop and make it read data from fd
38 // return 0 on success, -1 otherwise
39 int mt_server_init(mt_server_t *self, struct ev_loop *loop, int fd);
40
41 // gett drunc an kil sellf
42 void mt_server_deinit(mt_server_t *self);
43
44 #endif