author | mickeyl <mickeyl> | 2003-04-09 21:37:05 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-09 21:37:05 (UTC) |
commit | b055856776807f0a459a86b1e1f62902d2d3a9c3 (patch) (unidiff) | |
tree | 46bee28833c363607d20f4db93eef0166a45852d | |
parent | c8401f7ebb9e9314ed48517da38b949c24800c50 (diff) | |
download | opie-b055856776807f0a459a86b1e1f62902d2d3a9c3.zip opie-b055856776807f0a459a86b1e1f62902d2d3a9c3.tar.gz opie-b055856776807f0a459a86b1e1f62902d2d3a9c3.tar.bz2 |
implements a statistic interface for OPacketCapturer
-rw-r--r-- | libopie2/opienet/opcap.cpp | 40 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 7 |
2 files changed, 43 insertions, 4 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 5c464cf..6a3dc26 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -41,2 +41,3 @@ | |||
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include <qobjectlist.h> | ||
42 | 43 | ||
@@ -89,2 +90,15 @@ int OPacket::caplen() const | |||
89 | 90 | ||
91 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | ||
92 | { | ||
93 | if (!l) return; | ||
94 | QObject* o = l->first(); | ||
95 | while ( o ) | ||
96 | { | ||
97 | stats[o->name()]++; | ||
98 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | ||
99 | o = l->next(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | |||
90 | QString OPacket::dump( int bpl ) const | 104 | QString OPacket::dump( int bpl ) const |
@@ -129,3 +143,2 @@ QString OPacket::dump( int bpl ) const | |||
129 | 143 | ||
130 | |||
131 | int OPacket::len() const | 144 | int OPacket::len() const |
@@ -135,2 +148,3 @@ int OPacket::len() const | |||
135 | 148 | ||
149 | |||
136 | /*====================================================================================== | 150 | /*====================================================================================== |
@@ -774,2 +788,9 @@ void OPacketCapturer::close() | |||
774 | } | 788 | } |
789 | |||
790 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | ||
791 | qDebug( "--------------------------------------------------" ); | ||
792 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | ||
793 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | ||
794 | qDebug( "--------------------------------------------------" ); | ||
795 | |||
775 | } | 796 | } |
@@ -795,3 +816,2 @@ int OPacketCapturer::fileno() const | |||
795 | 816 | ||
796 | |||
797 | OPacket* OPacketCapturer::next() | 817 | OPacket* OPacketCapturer::next() |
@@ -805,3 +825,3 @@ OPacket* OPacketCapturer::next() | |||
805 | { | 825 | { |
806 | return new OPacket( dataLink(), header, pdata, 0 ); | 826 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
807 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 827 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
@@ -810,2 +830,7 @@ OPacket* OPacketCapturer::next() | |||
810 | // by emit() [ see below ] | 830 | // by emit() [ see below ] |
831 | |||
832 | //TODO: make gathering statistics optional, because it takes time | ||
833 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | ||
834 | |||
835 | return p; | ||
811 | } | 836 | } |
@@ -841,2 +866,3 @@ bool OPacketCapturer::open( const QString& name ) | |||
841 | _open = true; | 866 | _open = true; |
867 | _stats.clear(); | ||
842 | 868 | ||
@@ -868,3 +894,3 @@ void OPacketCapturer::readyToReceive() | |||
868 | { | 894 | { |
869 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); | 895 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
870 | OPacket* p = next(); | 896 | OPacket* p = next(); |
@@ -875 +901,7 @@ void OPacketCapturer::readyToReceive() | |||
875 | 901 | ||
902 | |||
903 | const QMap<QString,int>& OPacketCapturer::statistics() const | ||
904 | { | ||
905 | return _stats; | ||
906 | } | ||
907 | |||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index ddef278..c9b0624 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -48,2 +48,3 @@ extern "C" // work around a bpf/pcap conflict in recent headers | |||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qevent.h> | ||
49 | #include <qhostaddress.h> | 50 | #include <qhostaddress.h> |
@@ -51,2 +52,3 @@ extern "C" // work around a bpf/pcap conflict in recent headers | |||
51 | #include <qstring.h> | 52 | #include <qstring.h> |
53 | #include <qmap.h> | ||
52 | 54 | ||
@@ -82,2 +84,4 @@ class OPacket : public QObject | |||
82 | 84 | ||
85 | void updateStats( QMap<QString,int>&, QObjectList* ); | ||
86 | |||
83 | private: | 87 | private: |
@@ -436,2 +440,4 @@ class OPacketCapturer : public QObject | |||
436 | 440 | ||
441 | const QMap<QString,int>& statistics() const; | ||
442 | |||
437 | signals: | 443 | signals: |
@@ -448,2 +454,3 @@ class OPacketCapturer : public QObject | |||
448 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; | 454 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; |
455 | QMap<QString, int> _stats; // statistics; | ||
449 | }; | 456 | }; |