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
81
82
83
84
85
86
87
88
89
90
91
|
#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;
static void
cb_notification(redisAsyncContext *c, void *r, void *privdata)
{
redisReply *reply = r;
if (!reply)
return;
/* XXX notify modules */
log_debug("viz: redis cb_notification: %s\n", reply->str);
}
static void
cb_connect(const redisAsyncContext *c, int status)
{
if (status != REDIS_OK) {
log_warn("redis error: %s", c->errstr);
return;
}
log_info("viz: redis connected\n");
}
static void
cb_disconnect(const redisAsyncContext *c, int status)
{
if (status != REDIS_OK) {
log_warn("redis error: %s", c->errstr);
return;
}
log_info("viz: redis disconnected");
}
static 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;
setprocname("viz");
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);
if (_viz->rc->err)
return -1;
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);
if (!_viz->srv_tcp.ev)
return -1;
log_debug("XXX viz ok");
event_base_dispatch(_viz->evb);
return 0;
}
void
viz_shutdown(void) {
}
|