]> git.tdb.fi Git - netvis.git/commitdiff
Reorder NetVis members
authorMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 20:12:05 +0000 (20:12 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 20:12:05 +0000 (20:12 +0000)
Do initialization in constructor and teardown in destructor

source/netvis.cpp
source/netvis.h

index e9c6d50a3719da9628e935911a2c3f75b94b63df..e4d30579dac6e3352a38d9ccc69114c62d929649 100644 (file)
@@ -5,7 +5,6 @@ Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
 Distributed unter the GPL
 */
 
-#include <iostream>
 #include <limits>
 #include <cstdlib>
 #include <cmath>
@@ -34,6 +33,10 @@ using namespace std;
 using namespace Msp;
 
 NetVis::NetVis(int argc, char **argv):
+       pcap(0),
+       resolver(0),
+       wnd(0),
+       font(0),
        max_hosts(1000),
        max_visible_hosts(30),
        draw_labels(true),
@@ -43,10 +46,7 @@ NetVis::NetVis(int argc, char **argv):
        if(argc<2)
                throw UsageError("No interface given");
        iface = argv[1];
-}
 
-int NetVis::main()
-{
        char err[1024];
        pcap = pcap_open_live(iface.c_str(), 128, true, 0, err);
        if(!pcap)
@@ -59,9 +59,9 @@ int NetVis::main()
        localnet = ntohl(localnet);
        localnet_mask = ntohl(localnet_mask);
 
-       dpy = new Graphics::Display;
-       wnd = new Graphics::Window(*dpy, 1024, 768);
-       glc = new Graphics::GLContext(*wnd);
+       resolver = new Resolver;
+
+       wnd = new Graphics::SimpleGLWindow(1024, 768);
        wnd->set_title("NetVis");
        wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &NetVis::exit), 0));
        wnd->signal_key_press.connect(sigc::mem_fun(this, &NetVis::key_press));
@@ -74,24 +74,14 @@ int NetVis::main()
        DataFile::load(*font, "dejavu-10.font");
 
        catch_signal(SIGINT);
+}
 
-       resolver = new Resolver;
-
-       //set_loop_mode(TICK_BUSY);
-
-       Application::main();
-
+NetVis::~NetVis()
+{
        delete resolver;
 
        delete font;
-       delete glc;
        delete wnd;
-       delete dpy;
-
-       cout<<hosts.size()+disabled_hosts.size()<<" different hosts seen\n";
-       cout<<"capture: "<<profiler.scope("capture").total_time<<'\n';
-       cout<<"tick:    "<<profiler.scope("tick").total_time<<'\n';
-       cout<<"render:  "<<profiler.scope("render").total_time<<'\n';
 
        pcap_close(pcap);
        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
@@ -100,8 +90,6 @@ int NetVis::main()
                delete i->second;
        for(list<Packet *>::iterator i=packets.begin(); i!=packets.end(); ++i)
                delete *i;
-
-       return exit_code;
 }
 
 void NetVis::tick()
@@ -119,7 +107,7 @@ void NetVis::tick()
                frames = 0;
        }
 
-       dpy->tick();
+       wnd->get_display().tick();
 
        {
                Debug::ProfilingScope s(profiler, "capture");
@@ -269,7 +257,7 @@ void NetVis::tick()
                GL::pop_matrix();
                GL::Texture::unbind();
 
-               glc->swap_buffers();
+               wnd->swap_buffers();
        }
 
        ++frames;
index 35d9952ac826e3aed295da08405da580c1ce20d1..47f5de5bd31e7b05ea80248fe1ae32f32ffa5669 100644 (file)
@@ -15,7 +15,7 @@ Distributed unter the GPL
 #include <msp/debug/profiler.h>
 #include <msp/gbase/display.h>
 #include <msp/gbase/glcontext.h>
-#include <msp/gbase/window.h>
+#include <msp/gbase/simplewindow.h>
 #include <msp/gl/color.h>
 #include <msp/gl/font.h>
 #include <msp/time/timestamp.h>
@@ -29,30 +29,33 @@ class NetVis: public Msp::Application
 private:
        std::string iface;
        pcap_t *pcap;
-       std::list<Packet *> packets;
+       Resolver *resolver;
+       unsigned localnet;
+       unsigned localnet_mask;
+
+       Msp::Graphics::SimpleGLWindow *wnd;
+       Msp::GL::Font *font;
+
        unsigned max_hosts;
        unsigned max_visible_hosts;
        std::map<unsigned, Host *> hosts;
        std::map<unsigned, Host *> disabled_hosts;
-       Msp::Graphics::Display *dpy;
-       Msp::Graphics::Window *wnd;
-       Msp::Graphics::GLContext *glc;
-       Msp::Time::TimeStamp tick_t;
+       std::list<Packet *> packets;
        std::map<unsigned, Msp::GL::Color> port_colors;
-       Msp::GL::Font *font;
-       Msp::Debug::Profiler profiler;
        bool draw_labels;
        bool blend;
-       Resolver *resolver;
-       unsigned localnet;
-       unsigned localnet_mask;
+
+       Msp::Time::TimeStamp tick_t;
        Msp::Time::TimeStamp fps_t;
        unsigned frames;
        float fps;
 
+       Msp::Debug::Profiler profiler;
+
 public:
        NetVis(int, char **);
-       int main();
+       ~NetVis();
+
        const Msp::GL::Font &get_font() const { return *font; }
        const std::map<unsigned, Host *> &get_hosts() const { return hosts; }
 private: