X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fport.cpp;h=a96e151fcd63c9d82f933d91bfc9b879d469c96e;hb=d21b97e4f7f62ccdaf347012d6355a76f974f87e;hp=d4be82ce182b0c7d195557741d114cafbc8896f9;hpb=42bd2e83d66a98584540dd8cc5b47ee2349fe844;p=netvis.git diff --git a/source/port.cpp b/source/port.cpp index d4be82c..a96e151 100644 --- a/source/port.cpp +++ b/source/port.cpp @@ -22,6 +22,7 @@ using namespace Msp; Port::Port(NetVis &v, unsigned n): netvis(v), number(n), + registered(false), mesh((GL::COLOR4_UBYTE, GL::VERTEX2)) { char buf[128]; @@ -31,12 +32,19 @@ Port::Port(NetVis &v, unsigned n): addr.sin_addr.s_addr = 0; int err = getnameinfo(reinterpret_cast(&addr), sizeof(sockaddr_in), 0, 0, buf, sizeof(buf), 0); if(err==0) + { name = buf; + registered = !isdigit(name[0]); + } else - name = Msp::lexical_cast(number); + name = Msp::lexical_cast(number); + const map &ports = netvis.get_ports(); + unsigned tries = 100; + if(ports.size()>100 && !registered) + tries = 10000/ports.size()+1; float best_score = 0; - for(unsigned i=0; (i<100 && best_score<1); ++i) + for(unsigned i=0; (i &ports = netvis.get_ports(); for(map::const_iterator j=ports.begin(); j!=ports.end(); ++j) { + if(registered && !j->second->is_registered()) + break; const GL::Color &other = j->second->get_color(); float dr = c.r-other.r; float dg = c.g-other.g; @@ -83,13 +92,33 @@ Port::Port(NetVis &v, unsigned n): bld.end(); } +void Port::add_activity(unsigned bytes) +{ + activity.add_bytes(bytes); +} + +void Port::tick(const Time::TimeDelta &dt) +{ + activity.tick(dt); +} + void Port::render() const { - GL::PushMatrix push_; + GL::MatrixStack::Push push_(GL::MatrixStack::modelview()); mesh.draw(); - GL::translate(16, 1, 0); - GL::scale_uniform(10); - GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2)); - netvis.get_font().draw_string(name, imm); + { + GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2)); + imm.begin(GL::QUADS); + imm.color(color.r, color.g, color.b, color.a); + unsigned x = static_cast(activity.get_average()/4096); + imm.vertex(14, 0); + imm.vertex(14+x, 0); + imm.vertex(14+x, 10); + imm.vertex(14, 10); + imm.end(); + } + GL::MatrixStack::modelview() *= GL::Matrix::translation(16, 1, 0); + GL::MatrixStack::modelview() *= GL::Matrix::scaling(10); + netvis.get_font().draw_string(name); GL::Texture::unbind(); }