]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blob - mt_server.h
Add simulator mode (for debugging without terminal)
[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          MT_PROTOCOL_RX_BUFFER_SIZE
11
12 #if defined(SIM)
13 #define HTTP_PORT       8080                    // listen here
14 #define HTTP_ORIGIN     "html" // where the html files are
15 #else
16 #define HTTP_PORT       80                    // listen here
17 #define HTTP_ORIGIN     "/usr/share/mtserver" // where the html files are
18 #endif
19 #define HTTP_MOUNTPOINT "/"                   // mountpoint URL
20 #define HTTP_DEFAULT    "index.html"          // default filename
21
22 #define JSON_EMPTY "{\"type\":\"empty\"}" // default message
23
24 typedef struct node {
25     char *line;
26     struct node *next;
27 } node;
28
29 typedef struct list {
30     struct node *first;
31     struct node *last;
32 } list;
33
34 typedef struct ev_io_ws {
35     ev_io w;                     // input watcher
36     struct lws_context *context;
37     list *lines;
38     char *text;                  // input buffer pointer
39     char *pos;                   // input buffer current position pointer
40 } ev_io_ws;
41
42 typedef struct mt_server_t {
43     struct lws_context *context;
44     ev_io_ws fd_watcher;         // input watcher
45 } mt_server_t;
46
47 // init self, add it to loop and make it read data from fd
48 // return 0 on success, -1 otherwise
49 int mt_server_init(mt_server_t *self, struct ev_loop *loop, int fd);
50
51 // gett drunc an kil sellf
52 void mt_server_deinit(mt_server_t *self);
53
54 #endif