RDK Documentation (Open Sourced RDK Components)
TRMMonitorGUI.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22 * @defgroup trm
23 * @{
24 * @defgroup qtapp
25 * @{
26 **/
27 
28 
29 #include <QApplication>
30 #include <QDialog>
31 #include <QPainter>
32 #include <QDebug>
33 #include "ui_gui.h"
34 #include <QTimer>
35 #include <QTime>
36 #include <QMessageBox>
37 
38 #include "trm/TunerState.h"
39 
40 #include "TRMMonitorGUI.h"
41 #include "TRMMonitor.h"
42 
43 using namespace TRM;
44 
45 #define TUNER_REFRESH_INTERVAL 5000
46 #define TOTAL_TUNER_NUMBER 4
47 #define TOTAL_DEVICE_NUMBER 5
48 #define TOTAL_LOCATOR_NUMBER 7
49 #define RESERVATION_BAR_WIDTH 550
50 //#define RESERVATION_BAR_TIME_WIDTH (3600*3) //seconds
51 #define RBW RESERVATION_BAR_WIDTH
52 #define SECOND_SCALE 1 //how many actual seconds is for each 1 second in the timespin box
53 
54 int RESERVATION_BAR_TIME_WIDTH = 0;
55 
56 const char *deviceNames[TOTAL_DEVICE_NUMBER] = {
57  "Xi3 Family Room",
58  "Xi3 Living Room",
59  "Xi3 Bedroom",
60  "Xi3 Kitchen",
61  "Xi3 Dining Room",
62 };
63 
64 const char *locatorNames[TOTAL_LOCATOR_NUMBER] = {
65  "ocap://0xCNN",
66  "ocap://0xABC",
67  "ocap://0xCBS",
68  "ocap://0xNBC",
69  "ocap://0xFOX",
70  "ocap://0xHBO",
71  "ocap://QVC",
72 };
73 
74 TRMMonitorGUI::~TRMMonitorGUI(void)
75 {
76 }
77 
78 TRMMonitorGUI::TRMMonitorGUI(const QHostAddress &address, quint16 port, const QString &clientId, const QString &barWidth, QObject *parent) :
79  QMainWindow(), monitorUI(0), hostAddress(address), portNumber(port), clientId(clientId)
80 {
81  bool ok;
82  uint32_t connectionClientId = clientId.toUInt(&ok, 16);
83  uint32_t barWidthSeconds = barWidth.toUInt(&ok, 10);
84 
85  qDebug() << "connectionClientId to " << connectionClientId;
86  qDebug() << "barWidthSeconds is " << barWidthSeconds;
87 
88  RESERVATION_BAR_TIME_WIDTH = barWidthSeconds;
89 
90  if (!ok) connectionClientId = 0;
91  monitor = new TRMMonitor(hostAddress, portNumber, connectionClientId);
92 
93  UNUSED_VARIABLE(parent);
94  monitorUI = new Ui_TRMMonitor;
95  monitorUI->setupUi(this);
96 
97  /*
98  * =======================================================
99  * Bootup Configurations.
100  */
101  qDebug() << "Setting Window Title to " << clientId;
102  setWindowTitle(clientId);
103 
104  {/* Set Tab Order */
105  QWidget::setTabOrder(monitorUI->deviceListComboBox, monitorUI->startTimeHourSpinBox);
106  QWidget::setTabOrder(monitorUI->startTimeHourSpinBox, monitorUI->startTimeMinSpinBox);
107  QWidget::setTabOrder(monitorUI->startTimeMinSpinBox, monitorUI->durationHourSpinBox);
108  QWidget::setTabOrder(monitorUI->durationHourSpinBox, monitorUI->durationMinSpinBox);
109  QWidget::setTabOrder(monitorUI->durationMinSpinBox, monitorUI->locatorListComboBox);
110  QWidget::setTabOrder(monitorUI->locatorListComboBox, monitorUI->activityLiveRadioButton);
111  QWidget::setTabOrder(monitorUI->activityLiveRadioButton, monitorUI->activityRecordRadioButton);
112  QWidget::setTabOrder(monitorUI->activityRecordRadioButton, monitorUI->activityEASRadioButton);
113  QWidget::setTabOrder(monitorUI->activityEASRadioButton, monitorUI->reserveButton);
114  }
115 
116 
117  {/* Populate list of devices */
118  for (int i = 0; i < TOTAL_DEVICE_NUMBER; i++) {
119  monitorUI->deviceListComboBox->insertItem(0, deviceNames[TOTAL_DEVICE_NUMBER - i - 1]);
120  }
121  }
122 
123  {/* Populate list of locators */
124  for (int i = 0; i < TOTAL_LOCATOR_NUMBER; i++) {
125  monitorUI->locatorListComboBox->insertItem(0, locatorNames[TOTAL_LOCATOR_NUMBER - i - 1]);
126  }
127  }
128 
129  monitorUI->deviceListComboBox->setCurrentIndex(0);
130 
131  {/* Connect a 1-second repeat timer to currentTimeLabel */
132  QTimer *timer = new QTimer(monitorUI->currentTimeLabel);
133  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(onTimestampTimerTimeout()));
134  onTimestampTimerTimeout();
135  timer->start(1000);
136  }
137 
138  {/* Connect reserveButton to reserve action.*/
139  QObject::connect(monitorUI->reserveButton, SIGNAL(clicked()), this, SLOT(onReserveButtonClicked()));
140  }
141 
142 
143  {/* TunerIds must be retrieved first */
144  monitor->sendGetAllTunerIds();
145 
146  QTimer *timer = new QTimer(this);
147  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(onTunerStateUpdateTimerTimeout()));
148  onTunerStateUpdateTimerTimeout();
149  timer->start(TUNER_REFRESH_INTERVAL);
150 
151  QObject::connect(monitor,SIGNAL(tunerStatesUpdated(std::map<std::string, std::string>)), this, SLOT(onTunerStatesUpdated(std::map<std::string, std::string>)));
152  QObject::connect(monitor,SIGNAL(tunerIdsUpdated(std::list<std::string>)), this, SLOT(onTunerIdsUpdated(std::list<std::string>)));
153  QObject::connect(monitor,SIGNAL(tunerReservationsUpdated(std::map<std::string, std::list<TunerReservation> >)), this, SLOT(onTunerReservationsUpdated(std::map<std::string, std::list<TunerReservation> >)));
154  QObject::connect(monitor,SIGNAL(statusMessageReceived(std::string)), this, SLOT(onStatusMessageReceived(std::string)));
155  QObject::connect(monitor,SIGNAL(conflictsReceived(ReserveTunerResponse::ConflictCT)), this, SLOT(onConflictsReceived(ReserveTunerResponse::ConflictCT)));
156 
157 
158 
159  }
160 }
161 
162 void TRMMonitorGUI::drawReservationBar(QLabel *label, TunerReservation *reservation)
163 {
164  int totalWidth = label->width();
165  int totalDuration = RESERVATION_BAR_TIME_WIDTH;
166  qint64 durationWidth = totalWidth;
167  QString labelText = "";
168  qint64 now = QDateTime(QDate::currentDate(), QTime::currentTime()).toMSecsSinceEpoch();
169  QColor fillColor3(255, 153, 51);
170  QColor fillColor2(0xFF, 0xC1, 0xC1);
171  QColor fillColor1(0xBD, 0xFC, 0xC9);
172  QColor fillColor(0xE8, 0xE8, 0xE8);
173  QPixmap reservationBar;
174  if (reservation == 0) {
175  reservationBar = QPixmap(totalWidth, 30);
176  reservationBar.fill(fillColor);
177  }
178  else {
179  reservationBar = QPixmap(*label->pixmap());
180  }
181 
182  if (reservation) {
183  std::cout << "DRAW DRAW " << reservation->getServiceLocator() << std::endl;
184  }
185 
186  qint64 currentEpoch = QDateTime(QDate::currentDate(), QTime::currentTime()).toMSecsSinceEpoch();
187 
188  label->clear();
189  if (reservation != 0) {
190  /* Only show token string of the in-progress reservation */
191  if (reservation->getStartTime() < now) {
192  qDebug() << "setting text" << QString(reservation->getReservationToken().c_str());
193 
194  label->setText(QString(reservation->getReservationToken().c_str()));
195  label->setToolTip(QString(reservation->getReservationToken().c_str()) + " " + QString(reservation->getServiceLocator().c_str()));
196  label->setVisible(true);
197  if (reservation->getActivity() == Activity::kLive) {
198  labelText = " [" + QString(reservation->getDevice().c_str()) + "] - [" + QString(reservation->getServiceLocator().c_str()) + "]";
199  fillColor = fillColor1;
200  }
201  else {
202  labelText = " [" + QString(reservation->getServiceLocator().c_str()) + "]";
203  fillColor = fillColor2;
204  }
205  }
206  else {
207  fillColor = fillColor3;
208  }
209 
210 #if 0
211  //draw fixed duration
212  durationWidth = (reservation->getDuration() * totalWidth) / (totalDuration * 1000);
213 #else
214  /* calculate what is left in duration */
215  qint64 duration = 0;
216  if (reservation->getStartTime() < now) {
217  duration = reservation->getStartTime() + reservation->getDuration() - now;
218  }
219  else {
220  duration = reservation->getDuration();
221  }
222 
223  if (duration < 0) {
224  duration = 0;
225  }
226 
227  durationWidth = (duration * label->width()) / (totalDuration * 1000);
228 #endif
229 
230  qDebug() << "Duration Width is " << durationWidth;
231  }
232 
233  int state = TunerState::kHybrid;
234  QPainter painter;
235  painter.begin(&reservationBar);
236  int startX = 0;
237  if (reservation != 0){
238  if (reservation->getStartTime() < now) {
239 
240  startX = 0;
241  }
242  else {
243  startX = (((reservation->getStartTime() - now) * label->width()) / (totalDuration * 1000)) + 2;
244 
245  }
246  }
247 
248  painter.fillRect(startX, 0, durationWidth, 30, fillColor);
249  painter.drawText(QPoint(0, 20), labelText);
250  painter.end();
251  label->setPixmap(reservationBar);
252 }
253 
254 void TRMMonitorGUI::setTunerStateIndicator(const QString &tunerId, const TunerState& state)
255 {
256  qDebug() << "setTunerStateIndicator " << tunerId << " for state " << (const char *)(state.getState());;
257 
258  tunerStateIndicatorLabels[tunerId]->clear();
259  QPixmap labelSquare = QPixmap(60, 60);
260  QColor fillColor = Qt::darkGray;
261  QColor fillColor2 = Qt::darkGray;
262 
263  if (state == TunerState::kFree) {
264  fillColor = Qt::darkGray;
265  fillColor2 = Qt::darkGray;
266  } else if (state == TunerState::kLive) {
267  fillColor = Qt::darkGreen;
268  fillColor2 = Qt::darkGreen;
269  } else if (state == TunerState::kRecord) {
270  fillColor = Qt::darkRed;
271  fillColor2 = Qt::darkRed;
272  } else if (state == TunerState::kHybrid) {
273  fillColor = Qt::darkGreen;
274  fillColor2 = Qt::darkRed;
275  } else if (state == TunerState::kEAS) {
276  fillColor = Qt::red;
277  fillColor2 = Qt::red;
278  }
279 
280  labelSquare.fill(fillColor);
281  QPainter painter;
282  painter.begin(&labelSquare);
283  painter.fillRect(0, 0, 30, 60, fillColor);
284  painter.fillRect(30, 0, 60, 60, fillColor2);
285  painter.end();
286  tunerStateIndicatorLabels[tunerId]->setPixmap(labelSquare);
287 }
288 
289 void TRMMonitorGUI::onReserveButtonClicked(void)
290 {
291  /* Reserve */
292 #if 0
293  //startTimeHourSpinBox and MinSpinBox indicates the start HH::MM
294  QTime startQTime(monitorUI->startTimeHourSpinBox->value(), monitorUI->startTimeMinSpinBox->value());
295 
296  if (monitorUI->startTimeHourSpinBox->value() == 0 && monitorUI->startTimeMinSpinBox->value() == 0) {
297  startQTime = QTime::currentTime();
298  }
299 #elif 0
300  //startTime = now();
301  qint64 startTime = QDateTime(QDate::currentDate(), startQTime).toMSecsSinceEpoch();
302 #else
303  //startTimeHourSpinBox and MinSpinBox indicates the startTime = now() + MM::SS
304  qint64 startTime = QDateTime(QDate::currentDate(), QTime::currentTime()).toMSecsSinceEpoch() ;//+ monitorUI->startTimeMinSpinBox->value();
305  startTime += ((monitorUI->startTimeHourSpinBox->value() * 60 + monitorUI->startTimeMinSpinBox->value() * 10) * SECOND_SCALE * 1000);
306 #endif
307 
308 #if 0
309 #else
310  //durationHourSpinBox and MinSpinBox indicates the duration = MM::SS
311  qint64 duration = (monitorUI->durationHourSpinBox->value() * 60 + monitorUI->durationMinSpinBox->value()) * SECOND_SCALE * 1000;
312 #endif
313 
314  QString device = deviceNames[monitorUI->deviceListComboBox->currentIndex()];
315  QString locator = locatorNames[monitorUI->locatorListComboBox->currentIndex()];
316  QString activity="";
317  if (monitorUI->activityLiveRadioButton->isChecked()) {
318  activity="Live";
319  }
320  else if (monitorUI->activityRecordRadioButton->isChecked()) {
321  activity="Record";
322  }
323  else if (monitorUI->activityEASRadioButton->isChecked()) {
324  activity="EAS";
325  }
326  else {
327  //@TODO Error message box.
328  return;
329  }
330  qDebug() << "onReserveButtonClicked";
331 
332  monitor->sendTunerReserve(device, startTime, duration, locator, activity, "");
333 }
334 
335 void TRMMonitorGUI::onTimestampTimerTimeout(void)
336 {
337  monitorUI->currentTimeLabel->setText(QTime::currentTime().toString());
338 }
339 
340 void TRMMonitorGUI::onTunerStateUpdateTimerTimeout(void)
341 {
342  qDebug() << "Updating Tuner State";
343  monitor->sendGetAllTunerStates();
344  monitor->sendGetAllReservations();
345 }
346 
347 void TRMMonitorGUI::onTunerIdsUpdated(std::list<std::string> tunerIds)
348 {
349  qDebug() << "onTunerIdsUpdated";
350  {/* Gray out all tuners */
351  std::list<std::string>::iterator it = tunerIds.begin();
352  Q_ASSERT(tunerIds.size() == TOTAL_TUNER_NUMBER);
353  {
354  tunerStateIndicatorLabels.insert(QString((*it).c_str()), monitorUI->tuner1Label); it++;
355  tunerStateIndicatorLabels.insert(QString((*it).c_str()), monitorUI->tuner2Label); it++;
356  tunerStateIndicatorLabels.insert(QString((*it).c_str()), monitorUI->tuner3Label); it++;
357  tunerStateIndicatorLabels.insert(QString((*it).c_str()), monitorUI->tuner4Label); it++;
358  }
359 
360  { /* Index ReservationBar with "TunerID" + "Activity" */
361  it = tunerIds.begin();
362  QMap<QString, QLabel *> tunerReservationBarLabel;
363  tunerReservationBarLabel.clear();
364  tunerReservationBarLabel.insert(QString((const char *)Activity::kLive), monitorUI->tuner1LiveReservationIndicationBar);
365  tunerReservationBarLabel.insert(QString((const char *)Activity::kRecord), monitorUI->tuner1RecordReservationIndicationBar);
366  tunerReservationBarLabels.insert(QString((*it).c_str()),tunerReservationBarLabel); it++;
367 
368  tunerReservationBarLabel.clear();
369  tunerReservationBarLabel.insert(QString((const char *)Activity::kLive), monitorUI->tuner2LiveReservationIndicationBar);
370  tunerReservationBarLabel.insert(QString((const char *)Activity::kRecord), monitorUI->tuner2RecordReservationIndicationBar);
371  tunerReservationBarLabels.insert(QString((*it).c_str()),tunerReservationBarLabel); it++;
372 
373  tunerReservationBarLabel.clear();
374  tunerReservationBarLabel.insert(QString((const char *)Activity::kLive), monitorUI->tuner3LiveReservationIndicationBar);
375  tunerReservationBarLabel.insert(QString((const char *)Activity::kRecord), monitorUI->tuner3RecordReservationIndicationBar);
376  tunerReservationBarLabels.insert(QString((*it).c_str()),tunerReservationBarLabel); it++;
377 
378  tunerReservationBarLabel.clear();
379  tunerReservationBarLabel.insert((const char *)Activity::kLive, monitorUI->tuner4LiveReservationIndicationBar);
380  tunerReservationBarLabel.insert((const char *)Activity::kRecord, monitorUI->tuner4RecordReservationIndicationBar);
381  tunerReservationBarLabels.insert(QString((*it).c_str()),tunerReservationBarLabel); it++;
382 
383  }
384  }
385 
386  {/* Draw Tuner Status Square */
387  const std::list<std::string> &tunerIds = monitor->getTunerIds();
388  std::list<std::string>::const_iterator it = tunerIds.begin();
389 
390  for (it = tunerIds.begin(); it != tunerIds.end(); it++) {
391  setTunerStateIndicator(QString((*it).c_str()), TunerState::kFree);
392  }
393 
394  }
395  {/* Draw Reservation Bars */
396  monitorUI->tuner1LiveReservationIndicationBar->setVisible(true);
397  monitorUI->tuner2LiveReservationIndicationBar->setVisible(true);
398  monitorUI->tuner3LiveReservationIndicationBar->setVisible(true);
399  monitorUI->tuner4LiveReservationIndicationBar->setVisible(true);
400 
401  monitorUI->tuner1RecordReservationIndicationBar->setVisible(true);
402  monitorUI->tuner2RecordReservationIndicationBar->setVisible(true);
403  monitorUI->tuner3RecordReservationIndicationBar->setVisible(true);
404  monitorUI->tuner4RecordReservationIndicationBar->setVisible(true);
405 
406  drawReservationBar(monitorUI->tuner1LiveReservationIndicationBar, 0);
407  drawReservationBar(monitorUI->tuner2LiveReservationIndicationBar, 0);
408  drawReservationBar(monitorUI->tuner3LiveReservationIndicationBar, 0);
409  drawReservationBar(monitorUI->tuner4LiveReservationIndicationBar, 0);
410 
411  drawReservationBar(monitorUI->tuner1RecordReservationIndicationBar, 0);
412  drawReservationBar(monitorUI->tuner2RecordReservationIndicationBar, 0);
413  drawReservationBar(monitorUI->tuner3RecordReservationIndicationBar, 0);
414  drawReservationBar(monitorUI->tuner4RecordReservationIndicationBar, 0);
415  }
416 
417  {/*Setup Reservation Bar Actions, action data is ReservationToken */
418 
419  QList<QString> tunerIds = tunerReservationBarLabels.keys();
420  for (int i = 0; i < tunerIds.size(); i++) {
421  QList<QString> activities = tunerReservationBarLabels[tunerIds[i]].keys();
422  for (int j = 0; j < activities.size(); j++) {
423  QLabel *reservationIndicationBar = tunerReservationBarLabels[tunerIds[i]][activities[j]];
424  qDebug() << "Adding Action for " << tunerIds[i] << "for activity" << activities[j];
425  QAction *releaseTunerReservationAction = new QAction(tr("Release"), this);
426  releaseTunerReservationAction->setVisible(false);
427  releaseTunerReservationAction->setEnabled(false);
428  releaseTunerReservationAction->setData(0);
429  reservationIndicationBar->addAction(releaseTunerReservationAction);
430  QObject::connect(releaseTunerReservationAction, SIGNAL(triggered()), this, SLOT(onReleaseTunerReservationActionTriggered()));
431 
432  QAction *validateTunerReservationAction = new QAction(tr("Validate"), this);
433  validateTunerReservationAction->setVisible(false);
434  validateTunerReservationAction->setEnabled(false);
435  validateTunerReservationAction->setData(0);
436  reservationIndicationBar->addAction(validateTunerReservationAction);
437  QObject::connect(validateTunerReservationAction, SIGNAL(triggered()), this, SLOT(onValidateTunerReservationActionTriggered()));
438 
439  QAction *cancelRecordingAction = new QAction(tr("CancelRecording"), this);
440  cancelRecordingAction->setVisible(false);
441  cancelRecordingAction->setEnabled(false);
442  cancelRecordingAction->setData(0);
443  reservationIndicationBar->addAction(cancelRecordingAction);
444  QObject::connect(cancelRecordingAction, SIGNAL(triggered()), this, SLOT(onCancelRecordingActionTriggered()));
445 
446  QAction *renewTunerReservationAction = new QAction(tr("Renew"), this);
447  renewTunerReservationAction->setVisible(false);
448  renewTunerReservationAction->setEnabled(false);
449  renewTunerReservationAction->setData(0);
450  reservationIndicationBar->addAction(renewTunerReservationAction);
451  QObject::connect(renewTunerReservationAction, SIGNAL(triggered()), this, SLOT(onRenewTunerReservationActionTriggered()));
452 
453  reservationIndicationBar->setContextMenuPolicy(Qt::ActionsContextMenu);
454 
455  }
456 
457  }
458  }
459 }
460 
461 void TRMMonitorGUI::onTunerStatesUpdated(std::map<std::string, std::string> states)
462 {
463  qDebug() << "onTunerStatesUpdated";
464  std::map<std::string, std::string>::iterator it = states.begin();
465  Q_ASSERT(states.size() == TOTAL_TUNER_NUMBER);
466  for (it = states.begin(); it != states.end(); it++ ) {
467  qDebug() << "Updating tuner [" << (*it).first.c_str() << "] state to " << (*it).second.c_str();
468  setTunerStateIndicator((*it).first.c_str(), TunerState((*it).second.c_str()));
469  tunerStates[(*it).first.c_str()] = (*it).second.c_str();
470  }
471 }
472 
473 void TRMMonitorGUI::onTunerReservationsUpdated(std::map<std::string, std::list<TunerReservation> > reservations)
474 {
475 #if 1
476  std::map<std::string, std::list<TunerReservation> >::iterator it = reservations.begin();
477 
478  qDebug() << "onTunerReservationsUpdated===========================with tuner size === " << reservations.size();
479  {
480  //wipe out everything first.
481  drawReservationBar(monitorUI->tuner1LiveReservationIndicationBar, 0);
482  drawReservationBar(monitorUI->tuner2LiveReservationIndicationBar, 0);
483  drawReservationBar(monitorUI->tuner3LiveReservationIndicationBar, 0);
484  drawReservationBar(monitorUI->tuner4LiveReservationIndicationBar, 0);
485 
486  drawReservationBar(monitorUI->tuner1RecordReservationIndicationBar, 0);
487  drawReservationBar(monitorUI->tuner2RecordReservationIndicationBar, 0);
488  drawReservationBar(monitorUI->tuner3RecordReservationIndicationBar, 0);
489  drawReservationBar(monitorUI->tuner4RecordReservationIndicationBar, 0);
490  }
491  //Q_ASSERT(tunerIds.size() <= TOTAL_TUNER_NUMBER);
492  for (it = reservations.begin(); it != reservations.end(); it++ ) {
493  std::list<TunerReservation> & tunerReservations = (*it).second;
494 
495  qDebug() << "===========================Updating tuner [" << (*it).first.c_str() << "]";
496  /* first set all actions invisible */
497  {
498  QList<QAction *> actions = tunerReservationBarLabels[(*it).first.c_str()][(const char *)Activity::kLive]->actions();
499  for(int j = 0; j < actions.size(); j++) {
500  actions[j]->setVisible(false);
501  actions[j]->setEnabled(false);
502  TunerReservation *reservation = (TunerReservation *)((actions[j]->data()).toInt());
503  delete reservation;
504  actions[j]->setData(0);
505  }
506  drawReservationBar(tunerReservationBarLabels[(*it).first.c_str()][(const char *)Activity::kLive], 0);
507 
508  actions = tunerReservationBarLabels[(*it).first.c_str()][(const char *)Activity::kRecord]->actions();
509  for(int j = 0; j < actions.size(); j++) {
510  actions[j]->setVisible(false);
511  actions[j]->setEnabled(false);
512  TunerReservation *reservation = (TunerReservation *)((actions[j]->data()).toInt());
513  delete reservation;
514  actions[j]->setData(0);
515  }
516  drawReservationBar(tunerReservationBarLabels[(*it).first.c_str()][(const char *)Activity::kRecord], 0);
517  }
518 
519  /* Update actions */
520  std::list<TunerReservation>::iterator it2 = tunerReservations.begin();
521  for (it2 = tunerReservations.begin(); it2 != tunerReservations.end(); it2++) {
522  qDebug() << " udpating action for "
523  << QString((*it2).getReservationToken().c_str())
524  << " WITH STAR TIME " << (*it2).getStartTime()
525  << " WITH DURATION " << (*it2).getDuration()
526  ;
527 
528  QLabel *reservationBar = tunerReservationBarLabels[(*it).first.c_str()][(const char *)((*it2).getActivity().getActivity())];
529  QList<QAction *> actions = reservationBar->actions();
530  for(int k = 0; k < actions.size(); k++) {
531  actions[k]->setVisible(true);
532  actions[k]->setEnabled(true);
533 #if 1
534  //save entire copy
535  TunerReservation *copyReservation = new TunerReservation();
536  *copyReservation = (*it2);
537  actions[k]->setData((int)copyReservation);
538 #else
539  //just save the token
540  actions[k]->setData(QString((*it2).getReservationToken().c_str()));
541 #endif
542  }
543  drawReservationBar(reservationBar, &(*it2));
544  }
545  }
546 
547 
548 #endif
549 }
550 
551 void TRMMonitorGUI::onReleaseTunerReservationActionTriggered(void)
552 {
553  QAction *action = qobject_cast<QAction *>(sender());
554  if (action) {
555  TunerReservation *reservation = (TunerReservation *)(action->data().toInt());
556  qDebug() << reservation->getReservationToken().c_str();
557  const QString &reservationToken = reservation->getReservationToken().c_str();
558  if (!reservationToken.isEmpty()) {
559  monitor->sendReleaseTunerReservation(reservationToken);
560  }
561  }
562  qDebug() << "sendReleaseTunerReservation done";
563 }
564 
565 void TRMMonitorGUI::onValidateTunerReservationActionTriggered(void)
566 {
567  QAction *action = qobject_cast<QAction *>(sender());
568  if (action) {
569  TunerReservation *reservation = (TunerReservation *)(action->data().toInt());
570  qDebug() << reservation->getReservationToken().c_str();
571  const QString &reservationToken = reservation->getReservationToken().c_str();
572  if (!reservationToken.isEmpty()) {
573  monitor->sendValidateTunerReservation("MonitorUI", reservationToken);
574  }
575  }
576  qDebug() << "sendValidateTunerReservation done";
577 }
578 
579 void TRMMonitorGUI::onCancelRecordingActionTriggered(void)
580 {
581  QAction *action = qobject_cast<QAction *>(sender());
582  if (action) {
583  TunerReservation *reservation = (TunerReservation *)(action->data().toInt());
584  qDebug() << reservation->getReservationToken().c_str();
585  const QString &reservationToken = reservation->getReservationToken().c_str();
586  if (!reservationToken.isEmpty()) {
587  monitor->sendCancelRecording("MonitorUI", reservationToken);
588  }
589  }
590  qDebug() << "sendValidateTunerReservation done";
591 }
592 
593 void TRMMonitorGUI::onRenewTunerReservationActionTriggered(void)
594 {
595  QAction *action = qobject_cast<QAction *>(sender());
596  if (action) {
597  TunerReservation *reservation = (TunerReservation *)(action->data().toInt());
598  monitor->sendTunerReserve(reservation->getDevice().c_str(),
599  QDateTime(QDate::currentDate(), QTime::currentTime()).toMSecsSinceEpoch(),
600  reservation->getDuration(),
601  reservation->getServiceLocator().c_str(),
602  (const char *)reservation->getActivity().getActivity(),
603  reservation->getReservationToken().c_str());
604  }
605  qDebug() << "sendRenewTunerReservation done";
606 }
607 
608 
609 void TRMMonitorGUI::onStatusMessageReceived(std::string statusMessage)
610 {
611  //QMessageBox::information(this, "TRM Status Message", statusMessage);
612  monitorUI->logTextEdit->clear();
613  monitorUI->logTextEdit->setText(QString(statusMessage.c_str()));
614 }
615 
616 void TRMMonitorGUI::onConflictsReceived(ReserveTunerResponse::ConflictCT conflicts)
617 {
618  QString conflictMessage;
619  ReserveTunerResponse::ConflictCT::iterator it = conflicts.begin();
620 
621  conflictMessage += ("<b>" + clientId + "<br>");
622  conflictMessage += "<b>Requested Activity</b> is in conflict with the following group of activities\r\n\r\n<br>";
623  conflictMessage += ("<br>");
624  conflictMessage += ("<br>");
625 
626  for (it = conflicts.begin(); it != conflicts.end(); it++) {
627  conflictMessage += " " + QString((const char *)((*it).getActivity().getActivity())) + " : " + QString((*it).getServiceLocator().c_str()) + "<br>";
628  conflictMessage += ("<br>");
629  }
630 
631  conflictMessage += ("<br>");
632  conflictMessage += ("<br>");
633 
634  conflictMessage += "Please cancel one group and retry your request<br>";
635  QMessageBox::information(this, "Conflicts", conflictMessage);
636 
637 }
638 
639 
640 
641 /** @} */
642 /** @} */
TRM::TunerReservationBase::getStartTime
uint64_t getStartTime(void) const
This function is used to get the start time of the reservation in milliseconds from the epoch.
Definition: TunerReservation.cpp:105
TRM::TRMMonitor
Definition: TRMMonitor.h:46
TRM::TunerReservationBase::getDevice
const std::string & getDevice(void) const
This function is used to get the remote device id requesting for tuner reservation.
Definition: TunerReservation.cpp:127
TRM::TunerState
The TunerState class represents state of the tuner. The state field in the class indicates the activi...
Definition: TunerState.h:147
TRM::TunerReservationBase::getActivity
const Activity & getActivity(void) const
This function is used to return the granted activity. Granted activity may or may not be the same as ...
Definition: TunerReservation.cpp:142
TRM::TunerReservationBase::getServiceLocator
const std::string & getServiceLocator(void) const
This function is used to return the locator of the service that the tuner is tuned to.
Definition: TunerReservation.cpp:94
TRM::TunerReservationBase::getDuration
uint64_t getDuration(void) const
This function is used to get the reservation period measured from the start in milliseconds.
Definition: TunerReservation.cpp:116
TRM::TunerReservationBase
The TunerReservation class is used to set the requested or granted tuner reservation from client....
Definition: TunerReservation.h:139
TRM::TunerReservationBase::getReservationToken
const std::string & getReservationToken(void) const
This function is used to return the unique token generated when a reservation is created.
Definition: TunerReservation.cpp:83
TRM::Activity::getActivity
const Enum< Activity > & getActivity(void) const
This function is used to return the request or granted usage of tuner. The Activity field represents ...
Definition: Activity.cpp:89