Qt Virtual Chart Table (QVCT)
CDeviceSample.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QDomElement> // QtXml module
21 #include <QString>
22 #include <QXmlStreamWriter>
23 
24 // QVCT
25 #include "QVCTRuntime.hpp"
30 
31 
32 //------------------------------------------------------------------------------
33 // CONSTRUCTORS / DESTRUCTOR
34 //------------------------------------------------------------------------------
35 
36 CDeviceSample::CDeviceSample( const QString& _rqsName )
37  : CDevice( _rqsName )
38  , qsHost( "127.0.0.1" )
39  , iPort( 12345 )
40 {}
41 
43 {
44  // TODO: stop the device
45  // stop();
46 }
47 
48 
49 //------------------------------------------------------------------------------
50 // METHODS: CDevice (implement/override)
51 //------------------------------------------------------------------------------
52 
54 {
55  QVCT::EStatus __eStatus = QVCT::CRITICAL;
56  switch( _eOperatingMode )
57  {
58 
59  case CDevice::STOP:
60  // TODO: stop the device
61  // __eStatus = stop();
62  break;
63 
64  case CDevice::PAUSE:
65  // TODO: pause the device
66  // __eStatus = pause();
67  break;
68 
69  case CDevice::START:
70  // TODO: start the device
71  // __eStatus = start();
72  break;
73 
74  default:;
75  }
76  if( __eStatus != QVCT::OK )
77  {
78  qCritical( "ERROR[%s]: Failed to switch operating mode; host=%s, port=%d", Q_FUNC_INFO, qPrintable( qsHost ), iPort );
79  }
80  return __eStatus;
81 }
82 
84 {
89 }
90 
92 {
93  CDeviceSampleEditView* __poDeviceSampleEditView = new CDeviceSampleEditView( this );
94  if( __poDeviceSampleEditView->exec() == QDialog::Accepted ) showDetail();
95  delete __poDeviceSampleEditView;
96 }
97 
98 void CDeviceSample::parseQVCT( const QDomElement& _rqDomElement )
99 {
100  QDomElement __qDomElement = _rqDomElement.firstChildElement( "Configuration" );
101  if( __qDomElement.isNull() ) return;
102  qsHost = __qDomElement.attribute( "host", "127.0.0.1" );
103  iPort = __qDomElement.attribute( "port", "12345" ).toInt();
104 }
105 
106 void CDeviceSample::dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter ) const
107 {
108  // Device
109  _rqXmlStreamWriter.writeStartElement( "Device" );
110  // ... driver
111  _rqXmlStreamWriter.writeAttribute( "name", qsName );
112  _rqXmlStreamWriter.writeAttribute( "driver", "sample" ); // MUST match CDeviceDriverCodes
113  // ... configuration
114  _rqXmlStreamWriter.writeStartElement( "Configuration" );
115  _rqXmlStreamWriter.writeAttribute( "host", qsHost );
116  _rqXmlStreamWriter.writeAttribute( "port", QString::number( iPort ) );
117  _rqXmlStreamWriter.writeEndElement(); // Configuration
118  // ... [end]
119  _rqXmlStreamWriter.writeEndElement(); // Device
120 }
121 
122 
123 //------------------------------------------------------------------------------
124 // METHODS
125 //------------------------------------------------------------------------------
126 
127 //
128 // Methods to process the device data and send corresponding CDeviceDataFix
129 // and/or CDeviceDataSkyView
130 //
131 
134 {
135  //qDebug( "DEBUG[%s]: Begin", Q_FUNC_INFO );
136 
137  // Prevent application data deletion (and potential segfaults) while processing device data
138  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
139  __pqMutexDataChange->lock();
140 
141  // emit signalActivity();
142 
143  // CDeviceDataFix __oDeviceDataFix( __qsSourceName );
144  // ...
145  // emit signalDataFix( __oDeviceDataFix );
146 
147  // CDeviceDataSkyView __oDeviceDataSkyView( __qsSourceName );
148  // ...
149  // emit signalDataSkyView( __oDeviceDataSkyView );
150 
151  // Release application data deletion lock
152  __pqMutexDataChange->unlock();
153 
154  //qDebug( "DEBUG[%s]: End", Q_FUNC_INFO );
155 }
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Route container's edit view
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
virtual ~CDeviceSample()
void parseQVCT(const QDomElement &_rqDomElement)
Retrieves the device's configuration from the given QVCT source (file)
virtual void showDetail()
Displays the device's details (in the appropriate widget/view)
virtual void showEdit()
Displays the device's edit (configuration) widget/view.
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores the device's configuration to the given QVCT destination (file)
void slotProcessData(int)
Slots to process device data.
QString qsHost
Network host.
int iPort
Network port.
CDeviceSample(const QString &_rqsName)
Generic navigation device (GPS, speedometer, compass, etc.)
Definition: CDevice.hpp:43
EOperatingMode
Device operating mode (stop, start, pause)
Definition: CDevice.hpp:58
@ PAUSE
Definition: CDevice.hpp:58
@ STOP
Definition: CDevice.hpp:58
@ START
Definition: CDevice.hpp:58
void switchView(EView eView)
Displays the requested container/item details (switching to the appropriate widget)
@ DEVICE
Device overlay.
void switchView(EView eView)
Displays the requested overlay (switching to the appropriate tab)
void setOverlayObject(COverlayObject *_poOverlayObject)
Sets the overlay object to be displayed (and refreshes the underlying widget)
QString qsName
Object name.
static COverlayDetailView * useOverlayDetailView()
static CDeviceDetailView * useDeviceDetailView()
static QMutex * useMutexDataChange()
static COverlayListView * useOverlayListView()
EStatus
Definition: QVCT.hpp:41
@ OK
Definition: QVCT.hpp:41
@ CRITICAL
Definition: QVCT.hpp:41