From bfa2318a6b87eec9288e3a06621a5fbd00f5e4e9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 17:22:59 +0100 Subject: attach and detach node groups to "inactive tree" or to current active node --- gg_map/gg_map.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'gg_map/gg_map.c') diff --git a/gg_map/gg_map.c b/gg_map/gg_map.c index 2f971a3..2d710de 100644 --- a/gg_map/gg_map.c +++ b/gg_map/gg_map.c @@ -78,12 +78,41 @@ _node_to_vertice(struct ggnet_node *n) return v; } +static void +_node_attach_parentgroup(struct ggnet_node *n) +{ + struct ggnet_nodegroup *g; + Egraph_Vertice *vg, *vparentg; + + g = ggnet_node_group_get(n); + if (!g || !g->parent) + return; + vg = ggnet_nodegroup_usrdata_get(g); + vparentg = ggnet_nodegroup_usrdata_get(g->parent); + egraph_group_vertice_attach(_egraph, vg, vparentg); +} + +static void +_node_detach_parentgroup(struct ggnet_node *n) +{ + struct ggnet_nodegroup *g; + Egraph_Vertice *vg, *vparentg; + + g = ggnet_node_group_get(n); + if (!g || !g->parent) + return; + vg = ggnet_nodegroup_usrdata_get(g); + vparentg = ggnet_nodegroup_usrdata_get(g->parent); + egraph_group_vertice_detach(_egraph, vg, vparentg); +} + static void _conn_add(u_int id, u_int src, u_int dst, u_int proto, u_int8_t pktsize) { struct ggnet_conn *conn; - Egraph_Vertice *a, *b; Egraph_Edge *e; + struct ggnet_node *a, *b; + Egraph_Vertice *va, *vb; struct in_addr srcaddr, dstaddr; int size, response; @@ -97,13 +126,19 @@ _conn_add(u_int id, u_int src, u_int dst, u_int proto, u_int8_t pktsize) dstaddr.s_addr = dst; conn = ggnet_conn_add(_ggnet, &srcaddr, -1, &dstaddr, -1, proto, size, id); - a = _node_to_vertice(ggnet_conn_src_get(conn)); - b = _node_to_vertice(ggnet_conn_dst_get(conn)); - e = egraph_edge_find(_egraph, a, b); + a = ggnet_conn_src_get(conn); + b = ggnet_conn_dst_get(conn); + va = _node_to_vertice(a); + vb = _node_to_vertice(b); + e = egraph_edge_find(_egraph, va, vb); if (_debug) - printf("_conn_add: a %d b %d e %x id %d\n", a->id, b->id, e, id); + printf("_conn_add: a %d b %d e %x id %d\n", va->id, vb->id, e, id); if (!e) { - e = egraph_edge_add(_egraph, a, b, conn); + if (a->group && a->group->conn_count == 1) + _node_detach_parentgroup(a); + if (b->group && b->group->conn_count == 1) + _node_detach_parentgroup(b); + e = egraph_edge_add(_egraph, va, vb, conn); if (_debug) printf("_conn_add: egraph edge added %x\n", e); } @@ -132,7 +167,10 @@ _conn_del(int id) { if (_debug) printf("_conn_del: edge del %x\n", e); // XXX egraph_edge_del(_egraph, e); - //if (ggnet_node_is_connected( + if (a->group && a->group->conn_count == 0) + _node_attach_parentgroup(a); + if (b->group && b->group->conn_count == 0) + _node_attach_parentgroup(b); } else { if (_debug) printf("_conn_del: not last one, edge %x *not* deleted\n", e); -- cgit v1.2.3-59-g8ed1b