aboutsummaryrefslogtreecommitdiffstats
path: root/glouglou_efl/glouglou_efl.c
diff options
context:
space:
mode:
Diffstat (limited to 'glouglou_efl/glouglou_efl.c')
-rw-r--r--glouglou_efl/glouglou_efl.c243
1 files changed, 211 insertions, 32 deletions
diff --git a/glouglou_efl/glouglou_efl.c b/glouglou_efl/glouglou_efl.c
index 625ba5d..646cfac 100644
--- a/glouglou_efl/glouglou_efl.c
+++ b/glouglou_efl/glouglou_efl.c
@@ -1,15 +1,168 @@
+#include <err.h>
+
#include <Elementary.h>
#include <libglouglou.h>
-Evas_Object *win, *connbox;
+struct conn {
+ int id;
+ struct node *nsrc;
+ struct node *ndst;
+ int proto;
+ int size;
+ char name[DNSNAME_MAX];
+ Evas_Object *line;
+};
+
+struct node {
+ char name[DNSNAME_MAX];
+ u_int ip;
+ char fqdn[DNSNAME_MAX];
+ Evas_Object *btn;
+};
+
+Evas_Object *_mainwin, *_connbox;
+Eina_List *_conns = NULL;
+Eina_List *_nodes = NULL;
+
+static struct conn *conn_add(u_int, struct node *, struct node *, u_int, u_int);
+static void conn_del(struct conn *);
+static struct conn *conn_find(u_int);
+static struct conn *conn_find_or_create(u_int, struct node *, struct node *, u_int, u_int);
+static struct node *node_add(u_int);
+static void node_del(struct node *);
+static struct node *node_find(u_int);
+static struct node *node_find_or_create(u_int);
+static void node_update_name(struct node *, char *, int);
+
+static struct conn *
+conn_add(u_int id, struct node *nsrc, struct node *ndst, u_int proto, u_int size)
+{
+ struct conn *c;
+
+ c = calloc(sizeof(struct conn), 1);
+ if (!c)
+ err(1, "calloc failed in conn_add\n");
+ c->id = id;
+ c->nsrc = nsrc;
+ c->ndst = ndst;
+ c->proto = proto;
+ c->size = size;
+ snprintf(c->name, sizeof(c->name), "%d: %x -> %x - %d",
+ id, nsrc->ip, ndst->ip, proto);
+
+ _conns = eina_list_append(_conns, c);
+
+ // XXX c->line evas
+
+ return c;
+}
+
+static void
+conn_del(struct conn *c)
+{
+ if (c->line)
+ evas_object_del(c->line);
+ _conns = eina_list_prepend(_conns, c);
+ free(c);
+}
+
+static struct conn *
+conn_find(u_int id)
+{
+ struct conn *c;
+ Eina_List *l;
+
+ EINA_LIST_FOREACH(_conns, l, c)
+ if (c->id == id)
+ return c;
+ return NULL;
+}
+
+static struct conn *
+conn_find_or_create(u_int id, struct node *nsrc, struct node *ndst, u_int proto, u_int size)
+{
+ struct conn *c;
+
+ c = conn_find(id);
+ if (!c)
+ c = conn_add(id, nsrc, ndst, proto, size);
+ return c;
+}
+
+static struct node *
+node_add(u_int ip)
+{
+ struct node *n;
+
+ n = calloc(sizeof(struct node), 1);
+ if (!n)
+ err(1, "calloc failed in node_add\n");
+ n->ip = ip;
+
+ _nodes = eina_list_append(_nodes, n);
+
+ n->btn = elm_button_add(_mainwin);
+ node_update_name(n, NULL, 0);
+ elm_box_pack_end(_connbox, n->btn);
+ evas_object_show(n->btn);
+
+ return n;
+}
+
+static void
+node_del(struct node *n)
+{
+ if (n->btn)
+ evas_object_del(n->btn);
+ _nodes = eina_list_prepend(_nodes, n);
+ free(n);
+}
+
+static struct node *
+node_find(u_int ip)
+{
+ struct node *n;
+ Eina_List *l;
+
+ EINA_LIST_FOREACH(_nodes, l, n)
+ if (n->ip == ip)
+ return n;
+ return NULL;
+}
+
+static struct node *
+node_find_or_create(u_int ip)
+{
+ struct node *n;
+
+ n = node_find(ip);
+ if (!n)
+ n = node_add(ip);
+ return n;
+}
+
+static void
+node_update_name(struct node *n, char *name, int len)
+{
+ if (!name) {
+ snprintf(n->name, sizeof(n->name), "%x", n->ip);
+ } else {
+ if (len > sizeof(n->name))
+ len = sizeof(n->name);
+ strncpy(n->name, name, len);
+ }
+ elm_object_text_set(n->btn, n->name);
+}
static Eina_Bool
_cb_conn_data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
{
- Evas_Object *btn;
+ u_int id, ip, src, dst, proto, size, len;
+ struct node *n, *nsrc, *ndst;
+ struct conn *c;
struct packet *p;
- char name[32];
+ char *fqdn;
int i;
printf("data received:\n");
@@ -22,35 +175,61 @@ _cb_conn_data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
p = ev->data;
switch(p->type) {
case PACKET_NEWCONN:
+ id = p->newconn_id;
+ src = ntohl(p->newconn_src);
+ dst = ntohl(p->newconn_dst);
+ proto = p->newconn_proto;
+ size = ntohs(p->newconn_size);
+
printf(" type PACKET_NEWCONN\n");
- printf(" newconn_id %d\n", p->newconn_id);
- printf(" newconn_src %4x\n", ntohl(p->newconn_src));
- printf(" newconn_dst %4x\n", ntohl(p->newconn_dst));
- printf(" newconn_proto %d\n", p->newconn_proto);
- printf(" newconn_size %d\n", ntohs(p->newconn_size));
-
- btn = elm_button_add(win);
- snprintf(name, sizeof(name), "%d: %x -> %x - %d",
- p->newconn_id, ntohl(p->newconn_src), ntohl(p->newconn_dst), p->newconn_proto);
- elm_object_text_set(btn, name);
- elm_box_pack_end(connbox, btn);
- evas_object_show(btn);
+ printf(" newconn_id %d\n", id);
+ printf(" newconn_src %4x\n", src);
+ printf(" newconn_dst %4x\n", dst);
+ printf(" newconn_proto %d\n", proto);
+ printf(" newconn_size %d\n", size);
+
+ nsrc = node_find_or_create(src);
+ ndst = node_find_or_create(dst);
+ conn_find_or_create(id, nsrc, ndst, proto, size);
break;
case PACKET_DELCONN:
+ id = p->delconn_id;
+
printf(" type PACKET_DELCONN\n");
- printf(" delconn_id %d\n", p->delconn_id);
+ printf(" delconn_id %d\n", id);
+
+ n = node_find(id);
+ if (n)
+ node_del(n);
+
break;
case PACKET_DATA:
+ id = p->data_connid;
+ size = ntohs(p->data_size);
+
printf(" type PACKET_DATA\n");
- printf(" data_connid %d\n", p->data_connid);
- printf(" data_size %d\n", ntohs(p->data_size));
+ printf(" data_connid %d\n", id);
+ printf(" data_size %d\n", size);
+
+ c = conn_find(id);
+ // XXX evas_point on conn line
+
break;
case PACKET_NAME:
+ ip = ntohl(p->name_addr);
+ len = p->name_len;
+ fqdn = (char *)p->name_fqdn;
+
printf(" type PACKET_NAME\n");
- printf(" name_addr %4x\n", ntohl(p->name_addr));
- printf(" name_len %d\n", p->name_len);
- printf(" name_name_fqdn %s\n", p->name_fqdn);
+ printf(" name_addr %4x\n", ip);
+ printf(" name_len %d\n", len);
+ printf(" name_name_fqdn %s\n", fqdn);
+
+ n = node_find(ip);
+ if (n)
+ node_update_name(n, fqdn, len);
+
break;
}
@@ -69,34 +248,34 @@ elm_main(int argc, char **argv)
Evas_Object *box, *lab, *btn, *bg;
Ecore_Con_Server *conn;
- win = elm_win_util_standard_add("hello", "Hello");
- evas_object_smart_callback_add(win, "delete,request", _cb_on_done, NULL);
+ _mainwin = elm_win_util_standard_add("hello", "Hello");
+ evas_object_smart_callback_add(_mainwin, "delete,request", _cb_on_done, NULL);
- bg = elm_bg_add(win);
+ bg = elm_bg_add(_mainwin);
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(win, bg);
+ elm_win_resize_object_add(_mainwin, bg);
evas_object_show(bg);
- box = elm_box_add(win);
+ box = elm_box_add(_mainwin);
elm_box_horizontal_set(box, EINA_TRUE);
- elm_win_resize_object_add(win, box);
+ elm_win_resize_object_add(_mainwin, box);
evas_object_show(box);
- lab = elm_label_add(win);
+ lab = elm_label_add(_mainwin);
elm_object_text_set(lab, "Welcome to glouglou_efl");
elm_box_pack_end(box, lab);
evas_object_show(lab);
- btn = elm_button_add(win);
+ btn = elm_button_add(_mainwin);
elm_object_text_set(btn, "Quit");
elm_box_pack_end(box, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _cb_on_done, NULL);
- connbox = elm_box_add(win);
- evas_object_show(connbox);
+ _connbox = elm_box_add(_mainwin);
+ evas_object_show(_connbox);
- evas_object_show(win);
+ evas_object_show(_mainwin);
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
(Ecore_Event_Handler_Cb)_cb_conn_data, NULL);