1 | /*! |
---|
2 | * @file network_stats_widget.h |
---|
3 | * @brief Definition of an EnergyWidget, that displays a bar and a Text |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _NETWORK_STATS_WIDGET_H |
---|
7 | #define _NETWORK_STATS_WIDGET_H |
---|
8 | |
---|
9 | #include "glgui_fixedposition_box.h" |
---|
10 | #include "glgui_bar.h" |
---|
11 | #include "glgui_text.h" |
---|
12 | #include "glgui_pushbutton.h" |
---|
13 | |
---|
14 | #include "network/ip.h" |
---|
15 | |
---|
16 | class NetworkMonitor; |
---|
17 | class NetworkNode; |
---|
18 | class PeerInfo; |
---|
19 | |
---|
20 | class HostWidget : public OrxGui::GLGuiBox |
---|
21 | { |
---|
22 | public: |
---|
23 | HostWidget(const std::string& name, const IP& ip); |
---|
24 | HostWidget(const PeerInfo* peerInfo); |
---|
25 | |
---|
26 | void setName(const std::string& name) { this->_name.setText(name); }; |
---|
27 | void setIP(const IP& ip) { this->_ip.setText(std::string("at ") + ip.ipString()); this->_storedIP = ip; }; |
---|
28 | |
---|
29 | void setNameWidth(float width) { this->_name.setLineWidth(width); }; |
---|
30 | |
---|
31 | bool operator==(const IP& ip) const { return (this->_storedIP == ip); }; |
---|
32 | bool operator==(const std::string& name) const { return (this->_name == name); }; |
---|
33 | |
---|
34 | protected: |
---|
35 | virtual void showing(); |
---|
36 | virtual void hiding(); |
---|
37 | |
---|
38 | private: |
---|
39 | void init(); |
---|
40 | private: |
---|
41 | OrxGui::GLGuiText _name; //!< The Name of the Proxy server to be displayed. |
---|
42 | OrxGui::GLGuiText _ip; //!< The IP of the proxy server. |
---|
43 | IP _storedIP; //!< The ip to compare. |
---|
44 | |
---|
45 | static Font* _font; |
---|
46 | }; |
---|
47 | |
---|
48 | |
---|
49 | class NodeWidget : public OrxGui::GLGuiBox |
---|
50 | { |
---|
51 | public: |
---|
52 | NodeWidget(const std::string& proxyName, const IP& ip); |
---|
53 | NodeWidget(const NetworkNode* node); |
---|
54 | |
---|
55 | void addNode(const NetworkNode* node); |
---|
56 | void addNode(const std::string& name, const IP& ip); |
---|
57 | |
---|
58 | bool removeNode(const IP& ip); |
---|
59 | bool removeNode(const std::string& name); |
---|
60 | bool removeNode(const std::string& name, const IP& ip); |
---|
61 | |
---|
62 | void setNodeNameWidths(float width); |
---|
63 | |
---|
64 | |
---|
65 | protected: |
---|
66 | virtual void hiding(); |
---|
67 | virtual void showing(); |
---|
68 | |
---|
69 | |
---|
70 | private: |
---|
71 | HostWidget _proxyWidget; |
---|
72 | |
---|
73 | std::vector<NodeWidget*> _nodes; |
---|
74 | float _nodeNameWidth; |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | //! A class to display network Statistics. |
---|
81 | class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox |
---|
82 | { |
---|
83 | ObjectListDeclaration(NetworkStatsWidget); |
---|
84 | public: |
---|
85 | static void toggleGUI(); |
---|
86 | |
---|
87 | NetworkStatsWidget(const NetworkMonitor* monitor); |
---|
88 | virtual ~NetworkStatsWidget(); |
---|
89 | |
---|
90 | void setUpstream(unsigned int upstream); |
---|
91 | void setDownstream(unsigned int upstream); |
---|
92 | void setIP(const IP& ip); |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | void addProxy(const std::string& name, const IP& proxy); |
---|
97 | void addNode(const NetworkNode* node); |
---|
98 | |
---|
99 | void clearProxies(); |
---|
100 | |
---|
101 | void rebuild(); |
---|
102 | |
---|
103 | //void rebuildConnectedHosts(std::vector<hosts> hosts); |
---|
104 | |
---|
105 | void setMaximum(float max); |
---|
106 | void setValue(float value); |
---|
107 | |
---|
108 | virtual void tick(float dt); |
---|
109 | |
---|
110 | protected: |
---|
111 | virtual void resize(); |
---|
112 | virtual void showing(); |
---|
113 | virtual void hiding(); |
---|
114 | |
---|
115 | private: |
---|
116 | const NetworkMonitor* _monitor; |
---|
117 | |
---|
118 | OrxGui::GLGuiText _thisHostIs; |
---|
119 | HostWidget _thisHost; |
---|
120 | |
---|
121 | OrxGui::GLGuiText _upstreamText; |
---|
122 | OrxGui::GLGuiText _downstreamText; |
---|
123 | |
---|
124 | OrxGui::GLGuiBox _serverBox; |
---|
125 | |
---|
126 | std::vector<NodeWidget*> _proxies; |
---|
127 | |
---|
128 | |
---|
129 | static NetworkStatsWidget* _statsWidget; |
---|
130 | |
---|
131 | |
---|
132 | float _passedTime; |
---|
133 | //OrxGui::GLGuiText _valueText; |
---|
134 | //OrxGui::GLGuiBar _bar; |
---|
135 | }; |
---|
136 | |
---|
137 | #endif /* _NETWORK_STATS_WIDGET_H */ |
---|