ThreadViewer.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2013
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "ThreadViewer.h"
24
28
29#include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ThreadViewer.h>
30
31#include "ProgressbarDelegate.h"
32#include "RunningTaskModel.h"
33#include "ThreadViewerModel.h"
34
35namespace armarx
36{
38 periodicTaskModel(0), runningTaskModel(0), ui(new Ui::ThreadViewer)
39
40 {
41 ui->setupUi(getWidget());
42
43 periodicTaskModel = new ThreadViewerModel(getWidget());
44
45 ui->threadListView->setModel(periodicTaskModel);
46 ui->threadListView->setItemDelegateForColumn(3, new ProgressbarDelegate());
47
48 ui->threadListView->setColumnWidth(0, 150);
49 ui->threadListView->setColumnWidth(1, 30);
50 ui->threadListView->setColumnWidth(2, 50);
51 ui->threadListView->setColumnWidth(3, 90);
52 ui->threadListView->setColumnWidth(4, 100);
53 ui->threadListView->setColumnWidth(5, 100);
54 ui->threadListView->setColumnWidth(6, 80);
55 ui->threadListView->setColumnWidth(7, 70);
56 ui->threadListView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
57
58 runningTaskModel = new RunningTaskModel(getWidget());
59
60 ui->runningTaskView->setModel(runningTaskModel);
61 ui->runningTaskView->setItemDelegateForColumn(2, new ProgressbarDelegate());
62
63 ui->runningTaskView->setColumnWidth(0, 150);
64 ui->runningTaskView->setColumnWidth(1, 30);
65 ui->runningTaskView->setColumnWidth(2, 90);
66 ui->runningTaskView->setColumnWidth(3, 100);
67 ui->runningTaskView->setColumnWidth(4, 100);
68 ui->runningTaskView->setColumnWidth(5, 70);
69 ui->runningTaskView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
70
71 QFont font;
72 font.setPointSize(8);
73 ui->threadListView->setFont(font);
74 ui->runningTaskView->setFont(font);
75
76 connect(this,
77 SIGNAL(threadManagerListUpdated(QStringList)),
78 this,
79 SLOT(updateThreadManagerList(QStringList)));
80 connect(this, SIGNAL(cpuUsageValueUpdated(int)), this, SLOT(cpuUsageValueSet(int)));
81 connect(ui->cbThreadListManager,
82 SIGNAL(currentIndexChanged(QString)),
83 this,
84 SLOT(managedSelectionChanged(QString)));
85 connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(triggerThreadManagerListUpdate()));
86 }
87
89 {
90 delete ui;
91 }
92
93 void
94 ThreadViewer::loadSettings(QSettings* settings)
95 {
96 }
97
98 void
99 ThreadViewer::saveSettings(QSettings* settings)
100 {
101 }
102
103 void
107
108 void
110 {
111
113 periodicTask =
114 new PeriodicTask<ThreadViewer>(this, &ThreadViewer::runThreadManagerUpdate, 500);
115 periodicTask->start();
116 }
117
118 void
120 {
121 if (periodicTask)
122 {
123 periodicTask->stop();
124 }
125
126 if (managerUpdateTask)
127 {
128 managerUpdateTask->stop();
129 }
130 }
131
132 void
134 {
135 if (managerUpdateTask && managerUpdateTask->isRunning())
136 {
137 return;
138 }
139
140 ui->btnRefresh->setEnabled(false);
141 ui->btnRefresh->setToolTip("Refreshing manager list...please wait");
142 managerUpdateTask =
144 managerUpdateTask->start();
145 }
146
147 void
149 {
150 std::vector<std::string> managerList;
151 QStringList qManagerList;
152
153 try
154 {
155 if (getIceManager() && getIceManager()->getIceGridSession())
156 managerList = getIceManager()
157 ->getIceGridSession()
158 ->getRegisteredObjectNames<ThreadListInterfacePrx>("*ThreadList");
159
160 for (unsigned int i = 0; i < managerList.size(); ++i)
161 {
162 qManagerList << QString::fromStdString(managerList.at(i));
163 }
164 }
165 catch (...)
166 {
167 emit threadManagerListUpdated(qManagerList);
168 throw;
169 }
170
171 emit threadManagerListUpdated(qManagerList);
172 }
173
174 void
176 {
177 QString lastSelectionText = ui->cbThreadListManager->currentText();
178 ui->cbThreadListManager->clear();
179 ui->cbThreadListManager->addItems(list);
180 int index = ui->cbThreadListManager->findText(lastSelectionText);
181
182 if (index > 0)
183 {
184 ui->cbThreadListManager->setCurrentIndex(index);
185 }
186
187 ui->btnRefresh->setEnabled(true);
188 ui->btnRefresh->setToolTip("Refresh the thread manager list");
189 }
190
191 void
193 {
194 if (selectedString.size() == 0)
195 {
196 return;
197 }
198
199 std::unique_lock lock(proxyMutex);
200 threadManagerProxy = getProxy<ThreadListInterfacePrx>(selectedString.toStdString());
201 ARMARX_VERBOSE << "new proxy for ThreadViewerModel set: " << selectedString;
202 }
203
204 void
206 {
207
208 ui->cpuUsageProgressBar->setValue(value);
209 }
210
211 void
212 ThreadViewer::runThreadManagerUpdate()
213 {
214 std::unique_lock lock(proxyMutex);
215
216 if (!threadManagerProxy)
217 {
218 return;
219 }
220
221 try
222 {
223 PeriodicTaskList periodicTaskList = threadManagerProxy->getPeriodicTasks();
224 periodicTaskModel->setPeriodicTaskListData(periodicTaskList);
225
226 RunningTaskList runningTaskList = threadManagerProxy->getRunningTasks();
227 runningTaskModel->setRunningTaskListData(runningTaskList);
228
229 Ice::Double cpuProcTotalTime = threadManagerProxy->getCpuUsage();
230 int value = static_cast<int>(cpuProcTotalTime);
231 emit cpuUsageValueUpdated(value);
232 }
233 catch (Ice::NotRegisteredException& e)
234 {
235 }
236 catch (Ice::ObjectAdapterDeactivatedException& e)
237 {
238 }
239 catch (Ice::UnknownLocalException& e)
240 {
241 }
242 }
243} // namespace armarx
uint8_t index
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void setRunningTaskListData(const RunningTaskList &runningTaskList)
void setPeriodicTaskListData(const PeriodicTaskList &periodicTaskList)
void onInitComponent() override
void managedSelectionChanged(QString selectedString)
void loadSettings(QSettings *settings) override
Load stored manager models.
void saveSettings(QSettings *settings) override
Saves the manager models.
void updateThreadManagerList(QStringList list)
void cpuUsageValueUpdated(int value)
void triggerThreadManagerListUpdate()
void onConnectComponent() override
void threadManagerListUpdated(QStringList list)
void onExitComponent() override
Hook for subclass.
void cpuUsageValueSet(int value)
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.