Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/GobiSampleCM/QTSampleCM.h

raw
1 /*===========================================================================
2 FILE:
3 QTSampleCM.h
4
5 DESCRIPTION:
6 QT implementation of the Sample CM
7
8 PUBLIC CLASSES AND METHODS:
9 cButton
10 Generic clickable button for QT
11 cTextInput
12 Generic text input field for QT
13 cQTSampleCM
14 QT implementation of the Sample CM
15
16 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20 * Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 * Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
25 * Neither the name of Code Aurora Forum nor
26 the names of its contributors may be used to endorse or promote
27 products derived from this software without specific prior written
28 permission.
29
30
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 POSSIBILITY OF SUCH DAMAGE.
42 ===========================================================================*/
43
44 //---------------------------------------------------------------------------
45 // Pragmas
46 //---------------------------------------------------------------------------
47 #pragma once
48
49 //---------------------------------------------------------------------------
50 // Include Files
51 //---------------------------------------------------------------------------
52 #include <QtGui/QApplication>
53 #include "qmlapplicationviewer.h"
54 #include <qvariant.h>
55 #include <qdeclarativecontext.h>
56
57 #include "SampleCM.h"
58
59 // Prototypes
60 class cQTSampleCM;
61 void * AsyncConnectThread( void * pData );
62 QVariant OnInfosButton( cQTSampleCM * pCM );
63 QVariant OnConnectionsButton( cQTSampleCM * pCM );
64 QVariant OnConnectButton( cQTSampleCM * pCM );
65
66 /*=========================================================================*/
67 // Class cButton
68 // Generic clickable button for QT
69 /*=========================================================================*/
70 class cButton : public QObject
71 {
72 Q_OBJECT
73
74 public:
75
76 // Constructor
77 cButton( cQTSampleCM * pCM,
78 QVariant (*pOnClick)( cQTSampleCM * ) )
79 {
80 mpCM = pCM;
81 mpOnClick = pOnClick;
82 }
83
84 public slots:
85
86 // Function to be run on a click event
87 QVariant Click()
88 {
89 if (mpOnClick != 0)
90 {
91 return mpOnClick( mpCM );
92 }
93
94 return "";
95 }
96
97 protected:
98
99 /* The main object */
100 cQTSampleCM * mpCM;
101
102 /* Function to run when clicked */
103 QVariant (* mpOnClick)( cQTSampleCM * );
104 };
105
106 /*=========================================================================*/
107 // cTextInput
108 // Generic text input field for QT
109 /*=========================================================================*/
110 class cTextInput : public QObject
111 {
112 Q_OBJECT
113 Q_PROPERTY( QString text READ getText WRITE setText )
114
115 public slots:
116
117 // Get the value
118 QString getText() const
119 {
120 return mText;
121 }
122
123 // Set the value
124 void setText( const QString & text )
125 {
126 mText = text;
127 }
128
129 private:
130
131 /* The text */
132 QString mText;
133 };
134
135 /*=========================================================================*/
136 // Class cQTSampleCM
137 /*=========================================================================*/
138 class cQTSampleCM : public cSampleCM
139 {
140 public:
141 // Constructor
142 cQTSampleCM( int argc, char ** argv )
143 : mApp( argc, argv ),
144 mConnectButtonText( "No Device" ),
145 mConnectButton( this, OnConnectButton ),
146 mInfosButton( this, OnInfosButton ),
147 mConnectionsButton( this, OnConnectionsButton )
148 { }
149
150 // Initialize UI, begin waiting for devices
151 bool Init();
152
153 // Run the GUI (blocks until exit)
154 int Run();
155
156 // Disconnect
157 ULONG Disconnect();
158
159 // Process a start data session request
160 ULONG OnStartDataSession( ULONG * pFailureCode );
161
162 // Set mState and the connection button
163 void SetState( const std::string & state )
164 {
165 cSampleCM::SetState( state );
166
167 // Update the connection button as well
168 switch (mSessionState)
169 {
170 case eQMIConnectionStatus_Disconnected:
171 {
172 SetConnectButtonText( "Connect" );
173
174 if (mInitialState != eQMIConnectionStatus_Disconnected
175 && mInitialState != eQMIConnectionStatus_Suspended)
176 {
177 // Clear the initial state
178 mInitialState = eQMIConnectionStatus_Disconnected;
179 }
180 }
181 break;
182
183 case eQMIConnectionStatus_Connected:
184 {
185 if (mInitialState != eQMIConnectionStatus_Disconnected
186 && mInitialState != eQMIConnectionStatus_Suspended)
187 {
188 SetConnectButtonText( "External Con" );
189 }
190 else
191 {
192 SetConnectButtonText( "Disconnect" );
193 }
194 }
195 break;
196
197 case eQMIConnectionStatus_Authenticating:
198 {
199 if (mInitialState != eQMIConnectionStatus_Disconnected
200 && mInitialState != eQMIConnectionStatus_Suspended)
201 {
202 SetConnectButtonText( "Ext Connecting" );
203 }
204 else
205 {
206 SetConnectButtonText( "Cancel" );
207 }
208 }
209 break;
210
211 case eQMIConnectionStatus_Suspended:
212 default:
213 break;
214 }
215
216 // No more than 12 characters
217 if (mState.size() > 12)
218 {
219 mState.resize( 12 );
220 }
221
222 // Note: "state" is already a property, can't duplicate
223 // using "status" instead
224 mView.rootContext()->setContextProperty( "status", mState.c_str() );
225 }
226
227 // Set mRSSI
228 void SetRSSI( const std::string & rssi )
229 {
230 cSampleCM::SetRSSI( rssi );
231
232 mView.rootContext()->setContextProperty( "rssi", mRSSI.c_str() );
233 }
234
235 // Set mTech
236 void SetTech( const std::string & tech )
237 {
238 cSampleCM::SetTech( tech );
239
240 // No more than 12 characters
241 if (mTech.size() > 12)
242 {
243 mTech.resize( 12 );
244 }
245
246 mView.rootContext()->setContextProperty( "tech", mTech.c_str() );
247 }
248
249 // Set mRx
250 void SetRx( const std::string & rx )
251 {
252 cSampleCM::SetRx( rx );
253
254 mView.rootContext()->setContextProperty( "rx", mRx.c_str() );
255 }
256
257 // Set mTx
258 void SetTx( const std::string & tx )
259 {
260 cSampleCM::SetTx( tx );
261
262 mView.rootContext()->setContextProperty( "tx", mTx.c_str() );
263 }
264
265 // Set mMaxRx
266 void SetMaxRx( const std::string & maxRx )
267 {
268 cSampleCM::SetMaxRx( maxRx );
269
270 mView.rootContext()->setContextProperty( "maxRx", mMaxRx.c_str() );
271 }
272
273 // Set mMaxTx
274 void SetMaxTx( const std::string & maxTx )
275 {
276 cSampleCM::SetMaxTx( maxTx );
277
278 mView.rootContext()->setContextProperty( "maxTx", mMaxTx.c_str() );
279 }
280
281 // Set mRoam
282 void SetRoam( const std::string & roam )
283 {
284 cSampleCM::SetRoam( roam );
285
286 mView.rootContext()->setContextProperty( "roam", mRoam.c_str() );
287 }
288
289 // Set mDuration
290 void SetDuration( const std::string & duration )
291 {
292 cSampleCM::SetDuration( duration );
293
294 mView.rootContext()->setContextProperty( "duration", mDuration.c_str() );
295 }
296
297 // Set mLifeDuration
298 void SetLifeDuration( const std::string & lifeDuration )
299 {
300 cSampleCM::SetLifeDuration( lifeDuration );
301
302 mView.rootContext()->setContextProperty( "lifeDuration", mLifeDuration.c_str() );
303 }
304
305 // Set mLifeRx
306 void SetLifeRx( const std::string & lifeRx )
307 {
308 cSampleCM::SetLifeRx( lifeRx );
309
310 mView.rootContext()->setContextProperty( "lifeRx", mLifeRx.c_str() );
311 }
312
313 // Set mLifeTx
314 void SetLifeTx( const std::string & lifeTx )
315 {
316 cSampleCM::SetLifeTx( lifeTx );
317
318 mView.rootContext()->setContextProperty( "lifeTx", mLifeTx.c_str() );
319 }
320
321 // Set mManufact
322 void SetManufact( const std::string & manufact )
323 {
324 cSampleCM::SetManufact( manufact );
325
326 mView.rootContext()->setContextProperty( "manufact", mManufact.c_str() );
327 }
328
329 // Set mModel
330 void SetModel( const std::string & model )
331 {
332 cSampleCM::SetModel( model );
333
334 // No more than 20 characters
335 if (mModel.size() > 20)
336 {
337 mModel.resize( 20 );
338 }
339
340 mView.rootContext()->setContextProperty( "model", mModel.c_str() );
341 }
342
343 // Set mHardware
344 void SetHardware( const std::string & hardware )
345 {
346 cSampleCM::SetHardware( hardware );
347
348 mView.rootContext()->setContextProperty( "hardware", mHardware.c_str() );
349 }
350
351 // Set mFirmware
352 void SetFirmware( const std::string & firmware )
353 {
354 cSampleCM::SetFirmware( firmware );
355
356 // No more than 20 characters
357 if (mFirmware.size() > 20)
358 {
359 mFirmware.resize( 20 );
360 }
361
362 mView.rootContext()->setContextProperty( "firmware", mFirmware.c_str() );
363 }
364
365 // Set mMDN
366 void SetMDN( const std::string & mdn )
367 {
368 cSampleCM::SetMDN( mdn );
369
370 mView.rootContext()->setContextProperty( "mdn", mMDN.c_str() );
371 }
372
373 // Set mMIN
374 void SetMIN( const std::string & min )
375 {
376 cSampleCM::SetMIN( min );
377
378 mView.rootContext()->setContextProperty( "min", mMIN.c_str() );
379 }
380
381 // Set mESN
382 void SetESN( const std::string & esn )
383 {
384 cSampleCM::SetESN( esn );
385
386 mView.rootContext()->setContextProperty( "esn", mESN.c_str() );
387 }
388
389 // Set mMEID
390 void SetMEID( const std::string & meid )
391 {
392 cSampleCM::SetMEID( meid );
393
394 mView.rootContext()->setContextProperty( "meid", mMEID.c_str() );
395 }
396
397 // Set mIMEI
398 void SetIMEI( const std::string & imei )
399 {
400 cSampleCM::SetIMEI( imei );
401
402 mView.rootContext()->setContextProperty( "imei", mIMEI.c_str() );
403 }
404
405 // Set mIMSI
406 void SetIMSI( const std::string & imsi )
407 {
408 cSampleCM::SetIMSI( imsi );
409
410 mView.rootContext()->setContextProperty( "imsi", mIMSI.c_str() );
411 }
412
413 // Set mConnectButtonText
414 void SetConnectButtonText( const std::string & connectButtonText )
415 {
416 mConnectButtonText = connectButtonText;
417
418 mView.rootContext()->setContextProperty( "connectButtonText",
419 connectButtonText.c_str() );
420 }
421
422 protected:
423
424 /* QApplication object */
425 QApplication mApp;
426
427 /* QmlApplicationViewer object */
428 QmlApplicationViewer mView;
429
430 /* APN text input field */
431 cTextInput mAPNText;
432
433 /* Username text input field */
434 cTextInput mUsernameText;
435
436 /* Password text input field */
437 cTextInput mPasswordText;
438
439 /* "Connect" button's text */
440 std::string mConnectButtonText;
441
442 /* "Connect" button */
443 cButton mConnectButton;
444
445 /* "Info Stats" button */
446 cButton mInfosButton;
447
448 /* "Connection Stats" button */
449 cButton mConnectionsButton;
450
451 /* Async connection thread ID */
452 pthread_t mAsyncConnectThreadID;
453
454 // Friend functions
455 friend void * AsyncConnectThread( void * pData );
456 friend QVariant OnInfosButton( cQTSampleCM * pCM );
457 friend QVariant OnConnectionsButton( cQTSampleCM * pCM );
458 friend QVariant OnConnectButton( cQTSampleCM * pCM );
459 };