1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  *
16  * Author: John Abraham <john.abraham.in@gmail.com>
17  */
18 
19 #ifndef STATSMODE_H
20 #define STATSMODE_H
21 
22 #include "common.h"
23 #include "mode.h"
24 
25 namespace netanim
26 {
27 
28 
29 class NodeButton: public QPushButton
30 {
31   Q_OBJECT
32 public:
33   NodeButton (uint32_t nodeId);
34 private:
35   uint32_t m_nodeId;
36   void setNodeActive (bool active);
37 public slots:
38   void buttonClickedSlot ();
39 
40 };
41 
42 class StatsMode: public Mode
43 {
44   Q_OBJECT
45 
46   typedef enum
47   {
48     IPMAC = 0,
49     Routing = 1,
50     FlowMon = 2,
51     CounterTables = 3
52   } StatType_t;
53 public:
54 
55   // Getters
56   static StatsMode * getInstance ();
57   QWidget * getCentralWidget ();
58   QString getTabName ();
59   bool isNodeActive (uint32_t nodeId);
60   QVector <uint32_t> stringToNodeVector (QString nodeString);
61   QString nodeVectorToString (QVector<uint32_t> nodeVector);
62   qreal getCurrentTime ();
63   qreal getCurrentFontSize ();
64 
65   // Setters
66   void setFocus (bool focus);
67   void systemReset ();
68   void setNodeActive (uint32_t nodeId, bool active);
69   void showPopup (QString message);
70   void setProgressBarRange (uint64_t rxCount);
71   void setParsingCount (uint64_t parsingCount);
72 
73 
74 
75 
76 
77 private:
78   // state
79   typedef enum
80   {
81     INIT,
82     READY
83   } StatsModeState_t;
84 
85   typedef std::vector<NodeButton *> NodeButtonVector_t;
86   typedef std::map<uint32_t, bool> ActiveNodesMap_t;
87   // Controls
88   QWidget * m_centralWidget;
89   QHBoxLayout * m_hLayout;
90   QVBoxLayout * m_vLayout;
91   QToolBar * m_nodeToolbar;
92   QToolBar * m_topToolbar;
93   QToolBar * m_bottomToolbar;
94   QScrollArea * m_nodeToolbarScrollArea;
95   QComboBox * m_statTypeComboBox;
96   QPushButton * m_selectAllNodesButton;
97   QPushButton * m_deselectAllNodesButton;
98   QDialog * m_parsingXMLDialog;
99   QToolButton * m_fileOpenButton;
100   QProgressBar * m_parseProgressBar;
101   QLabel * m_bottomStatusLabel;
102   QLCDNumber * m_qLcdNumber;
103   QSlider * m_simulationTimeSlider;
104   QLabel * m_simTimeLabel;
105   QLabel * m_fontSizeLabel;
106   QSpinBox * m_fontSizeSpinBox;
107   QPushButton * m_flowMonFileButton;
108   QComboBox * m_counterTablesCombobox;
109   QLineEdit * m_allowedNodesEdit;
110   QLabel * m_allowedNodesLabel;
111   QPushButton * m_showChartButton;
112 
113 
114 
115 
116 
117   NodeButtonVector_t m_nodeButtonVector;
118   ActiveNodesMap_t m_activeNodes;
119 
120   // State
121   uint64_t m_rtCount;
122   StatType_t m_statType;
123   int m_oldTimelineValue;
124   double m_currentTime;
125   qreal m_parsedMaxSimulationTime;
126   qreal m_currentFontSize;
127   bool m_showChart;
128   StatsModeState_t m_state;
129 
130 
131   StatsMode ();
132   void init ();
133   void initControls ();
134   void initToolbars ();
135   void initNodeToolbar ();
136   void initTopToolbar ();
137   void initBottomToolbar ();
138   void addNodesToToolbar (bool zeroIndexed = true);
139   bool parseRoutingXMLTraceFile (QString traceFileName);
140   bool parseFlowMonXMLTraceFile (QString traceFileName);
141   void showParsingXmlDialog (bool show);
142   void routingPreParse ();
143   void routingPostParse ();
144   void flowMonPreParse ();
145   void flowMonPostParse ();
146   uint32_t getCurrentNodeCount ();
147   void setMaxSimulationTime (double maxTime);
148   void setMinSimulationTime (double minTime);
149   void enableControlsForState ();
150   void enableFlowMonControls (bool enable);
151   void enableIpMacControls (bool enable);
152   void enableCounterTables (bool enable);
153   void enableRoutingStatsControls (bool enable);
154   void setAvailableCounters ();
155 
156 
157 
158 
159 public slots:
160   void testSlot ();
161 
162 private slots:
163   void clickRoutingTraceFileOpenSlot ();
164   void selectAllNodesSlot ();
165   void deselectAllNodesSlot ();
166   void statTypeChangedSlot (int index);
167   void updateTimelineSlot (int value);
168   void fontSizeSlot (int value);
169   void clickFlowMonTraceFileOpenSlot ();
170   void allowedNodesChangedSlot (QString allowedNodes);
171   void counterIndexChangedSlot (QString counterString);
172   void showChartSlot ();
173 
174 
175 
176 
177 };
178 
179 } // namespace netanim
180 
181 #endif // STATSMODE_H
182