aboutsummaryrefslogtreecommitdiffstats
path: root/v3/glougloud/viz.c
blob: 182e086a00de10da7af1b473e9163d68aebd82db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <unistd.h>

#include <libglouglou.h>

#include "glougloud.h"

struct glougloud_viz {
	int pid;
	struct event_base *evb;
	struct modules *mods;
	redisAsyncContext *rc;
	struct {
		struct event *ev;
	} srv_tcp;
};

struct glougloud *_ggd;
struct glougloud_viz *_viz;

void cb_notification(redisAsyncContext *c, void *r, void *privdata)
{
	redisReply *reply = r;
	if (!reply)
		return;
	/* XXX notify modules */
	log_debug("redis cb_notification: %s\n", reply->str);
}

void cb_connect(const redisAsyncContext *c, int status)
{
	if (status != REDIS_OK) {
		log_warn("redis error: %s", c->errstr);
		return;
	}
	log_info("redis connected\n");
}

void cb_disconnect(const redisAsyncContext *c, int status)
{
	if (status != REDIS_OK) {
		log_warn("redis error: %s", c->errstr);
		return;
	}
	log_info("redis disconnected");
}

void
cb_srv_conn(evutil_socket_t listener, short event, void *arg)
{

}

int
viz_init(struct glougloud *ggd) {
	_ggd = ggd;
	_viz = xcalloc(1, sizeof(struct glougloud_viz));
	_viz->pid = fork();
	if (_viz->pid > 0)
		return 0;
	droppriv(GLOUGLOUD_USER_VIZ, 1, NULL);

	_viz->evb = event_base_new();
	_viz->mods = modules_load(GLOUGLOUD_MOD_PATH, NULL);

	_viz->rc = redis_connect(_viz->evb, cb_connect, cb_disconnect);
	redisAsyncCommand(_viz->rc, cb_notification, "event",
		"SUBSCRIBE __keyevent@ggd__:*");

	_viz->srv_tcp.ev = tcp_server_create(_viz->evb, &_ggd->viz.serv_ip,
		_ggd->viz.serv_port, cb_srv_conn, NULL);

	event_base_dispatch(ev_base);

	return 0;
}

void
viz_shutdown(void) {
}