| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
SampleCM.h |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
Generic class to act as Sample CM interface |
| 7 |
|
| 8 |
PUBLIC CLASSES AND METHODS: |
| 9 |
cSampleCM |
| 10 |
Generic class to act as Sample CM interface |
| 11 |
|
| 12 |
Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 13 |
|
| 14 |
Redistribution and use in source and binary forms, with or without |
| 15 |
modification, are permitted provided that the following conditions are met: |
| 16 |
* Redistributions of source code must retain the above copyright |
| 17 |
notice, this list of conditions and the following disclaimer. |
| 18 |
* Redistributions in binary form must reproduce the above copyright |
| 19 |
notice, this list of conditions and the following disclaimer in the |
| 20 |
documentation and/or other materials provided with the distribution. |
| 21 |
* Neither the name of Code Aurora Forum nor |
| 22 |
the names of its contributors may be used to endorse or promote |
| 23 |
products derived from this software without specific prior written |
| 24 |
permission. |
| 25 |
|
| 26 |
|
| 27 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 28 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 29 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 30 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 31 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 32 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 33 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 34 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 35 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 36 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 37 |
POSSIBILITY OF SUCH DAMAGE. |
| 38 |
===========================================================================*/ |
| 39 |
|
| 40 |
//--------------------------------------------------------------------------- |
| 41 |
// Pragmas |
| 42 |
//--------------------------------------------------------------------------- |
| 43 |
#pragma once |
| 44 |
|
| 45 |
//--------------------------------------------------------------------------- |
| 46 |
// Include Files |
| 47 |
//--------------------------------------------------------------------------- |
| 48 |
#include "StdAfx.h" |
| 49 |
#include "GobiCMDLL.h" |
| 50 |
#include "Event.h" |
| 51 |
|
| 52 |
#include <string> |
| 53 |
#include <sstream> |
| 54 |
#include <list> |
| 55 |
|
| 56 |
// Prototypes |
| 57 |
void * DeviceDetectionThread( void * pData ); |
| 58 |
void * UpdateNetworkInfo( void * pData ); |
| 59 |
|
| 60 |
// A global pointer to the CM, used by the callbacks |
| 61 |
extern class cSampleCM * gpCM; |
| 62 |
|
| 63 |
/*=========================================================================*/ |
| 64 |
// Class cSampleCM |
| 65 |
/*=========================================================================*/ |
| 66 |
class cSampleCM |
| 67 |
{ |
| 68 |
public: |
| 69 |
// Constructor |
| 70 |
cSampleCM() |
| 71 |
: mDeviceID(), |
| 72 |
mSessionState( 0 ), |
| 73 |
mSessionID( 0xFFFFFFFF ), |
| 74 |
mInitialState( 0xFFFFFFFF ), |
| 75 |
mStartTime( 0 ), |
| 76 |
mPreviousRX( 0 ), |
| 77 |
mPreviousTX( 0 ), |
| 78 |
mTotalRX( 0 ), |
| 79 |
mTotalTX( 0 ), |
| 80 |
mLifeTotalRX( 0 ), |
| 81 |
mLifeTotalTX( 0 ), |
| 82 |
mCurrentDuration( 0 ), |
| 83 |
mTotalDuration( 0 ), |
| 84 |
mLifeTotalDuration( 0 ), |
| 85 |
mbInitiatedStartDataSession( false ), |
| 86 |
mbInitiatedStopDataSession( false ), |
| 87 |
mDataBearerTech( eQMIDataBearerTechnologies_Unknown ), |
| 88 |
mDeviceDetectionThreadID( 0 ), |
| 89 |
mUpdateNetworkInfoThreadID( 0 ) |
| 90 |
{ |
| 91 |
mDeviceDetectionStopPipe[READING] = -1; |
| 92 |
mDeviceDetectionStopPipe[WRITING] = -1; |
| 93 |
|
| 94 |
// Create an ordered list of service preferences |
| 95 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_CDMA1xEVDORevB ); |
| 96 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_CDMA1xEVDORevA ); |
| 97 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_CDMA1xEVDORev0 ); |
| 98 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_CDMA ); |
| 99 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_DCHSDPAPlus ); |
| 100 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_HSDPAPlus ); |
| 101 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_HSDPA ); |
| 102 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_WCDMA ); |
| 103 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_EGPRS ); |
| 104 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_GPRS ); |
| 105 |
mPreferredServices.push_back( eQMINASDataServiceCapabilities2_GSM ); |
| 106 |
} |
| 107 |
|
| 108 |
// Destructor |
| 109 |
~cSampleCM(); |
| 110 |
|
| 111 |
// Initialize UI, begin waiting for devices |
| 112 |
virtual bool Init(); |
| 113 |
|
| 114 |
// Connect to a device and send initial callback registrations |
| 115 |
virtual ULONG Connect( LPCSTR pInterface ); |
| 116 |
|
| 117 |
// Disconnect from a device and set members as "Unknown" |
| 118 |
virtual ULONG Disconnect(); |
| 119 |
|
| 120 |
// Process a start data session request |
| 121 |
virtual ULONG OnStartDataSession( ULONG * pFailureCode ); |
| 122 |
|
| 123 |
// Process a cancel data session request |
| 124 |
virtual ULONG OnCancelDataSession(); |
| 125 |
|
| 126 |
// Process a stop data session request |
| 127 |
virtual ULONG OnStopDataSession(); |
| 128 |
|
| 129 |
// Set mState |
| 130 |
virtual void SetState( const std::string & state ) |
| 131 |
{ |
| 132 |
mState = state; |
| 133 |
} |
| 134 |
|
| 135 |
// Set mRSSI |
| 136 |
virtual void SetRSSI( const std::string & rssi ) |
| 137 |
{ |
| 138 |
mRSSI = rssi; |
| 139 |
} |
| 140 |
|
| 141 |
// Set mTech |
| 142 |
virtual void SetTech( const std::string & tech ) |
| 143 |
{ |
| 144 |
mTech = tech; |
| 145 |
} |
| 146 |
|
| 147 |
// Set mRx |
| 148 |
virtual void SetRx( const std::string & rx ) |
| 149 |
{ |
| 150 |
mRx = rx; |
| 151 |
} |
| 152 |
|
| 153 |
// Set mTx |
| 154 |
virtual void SetTx( const std::string & tx ) |
| 155 |
{ |
| 156 |
mTx = tx; |
| 157 |
} |
| 158 |
|
| 159 |
// Set mMaxRx |
| 160 |
virtual void SetMaxRx( const std::string & maxRx ) |
| 161 |
{ |
| 162 |
mMaxRx = maxRx; |
| 163 |
} |
| 164 |
|
| 165 |
// Set mMaxTx |
| 166 |
virtual void SetMaxTx( const std::string & maxTx ) |
| 167 |
{ |
| 168 |
mMaxTx = maxTx; |
| 169 |
} |
| 170 |
|
| 171 |
// Set mRoam |
| 172 |
virtual void SetRoam( const std::string & roam ) |
| 173 |
{ |
| 174 |
mRoam = roam; |
| 175 |
} |
| 176 |
|
| 177 |
// Set mDuration |
| 178 |
virtual void SetDuration( const std::string & duration ) |
| 179 |
{ |
| 180 |
mDuration = duration; |
| 181 |
} |
| 182 |
|
| 183 |
// Set mLifeDuration |
| 184 |
virtual void SetLifeDuration( const std::string & lifeDuration ) |
| 185 |
{ |
| 186 |
mLifeDuration = lifeDuration; |
| 187 |
} |
| 188 |
|
| 189 |
// Set mLifeRx |
| 190 |
virtual void SetLifeRx( const std::string & lifeRx ) |
| 191 |
{ |
| 192 |
mLifeRx = lifeRx; |
| 193 |
} |
| 194 |
|
| 195 |
// Set mLifeTx |
| 196 |
virtual void SetLifeTx( const std::string & lifeTx ) |
| 197 |
{ |
| 198 |
mLifeTx = lifeTx; |
| 199 |
} |
| 200 |
|
| 201 |
// Set mManufact |
| 202 |
virtual void SetManufact( const std::string & manufact ) |
| 203 |
{ |
| 204 |
mManufact = manufact; |
| 205 |
} |
| 206 |
|
| 207 |
// Set mModel |
| 208 |
virtual void SetModel( const std::string & model ) |
| 209 |
{ |
| 210 |
mModel = model; |
| 211 |
} |
| 212 |
|
| 213 |
// Set mHardware |
| 214 |
virtual void SetHardware( const std::string & hardware ) |
| 215 |
{ |
| 216 |
mHardware = hardware; |
| 217 |
} |
| 218 |
|
| 219 |
// Set mFirmware |
| 220 |
virtual void SetFirmware( const std::string & firmware ) |
| 221 |
{ |
| 222 |
mFirmware = firmware; |
| 223 |
} |
| 224 |
|
| 225 |
// Set mMDN |
| 226 |
virtual void SetMDN( const std::string & mdn ) |
| 227 |
{ |
| 228 |
mMDN = mdn; |
| 229 |
} |
| 230 |
|
| 231 |
// Set mMIN |
| 232 |
virtual void SetMIN( const std::string & min ) |
| 233 |
{ |
| 234 |
mMIN = min; |
| 235 |
} |
| 236 |
|
| 237 |
// Set mESN |
| 238 |
virtual void SetESN( const std::string & esn ) |
| 239 |
{ |
| 240 |
mESN = esn; |
| 241 |
} |
| 242 |
|
| 243 |
// Set mMEID |
| 244 |
virtual void SetMEID( const std::string & meid ) |
| 245 |
{ |
| 246 |
mMEID = meid; |
| 247 |
} |
| 248 |
|
| 249 |
// Set mIMEI |
| 250 |
virtual void SetIMEI( const std::string & imei ) |
| 251 |
{ |
| 252 |
mIMEI = imei; |
| 253 |
} |
| 254 |
|
| 255 |
// Set mIMSI |
| 256 |
virtual void SetIMSI( const std::string & imsi ) |
| 257 |
{ |
| 258 |
mIMSI = imsi; |
| 259 |
} |
| 260 |
|
| 261 |
// Handle signal strength callback notification |
| 262 |
void OnSignalStrengthCBNotificaion( |
| 263 |
INT8 signalStr, |
| 264 |
ULONG radioInterface ); |
| 265 |
|
| 266 |
// Handle session state callback notification |
| 267 |
void OnSessionStateCBNotification( ULONG state ); |
| 268 |
|
| 269 |
// Handle data bearer callback notification |
| 270 |
void OnDataBearerCBNotification( ULONG dataBearerTech ); |
| 271 |
|
| 272 |
// Handle data capabilities callback notification |
| 273 |
void OnDataCapsNotification( |
| 274 |
ULONG numDataCaps, |
| 275 |
eQMINASDataServiceCapabilities2 * pDataCaps ); |
| 276 |
|
| 277 |
// Handle byte totals callback notification |
| 278 |
void OnByteTotalsNotification( ULONGLONG rx, ULONGLONG tx ); |
| 279 |
|
| 280 |
// Update the signal strength and technology |
| 281 |
void UpdateSignalAndTech(); |
| 282 |
|
| 283 |
// Update the session state |
| 284 |
void UpdateSessionState( |
| 285 |
bool bExternal, |
| 286 |
ULONG state ); |
| 287 |
|
| 288 |
// Calculate and update the connection time being displayed |
| 289 |
void UpdateTimeDisplay(); |
| 290 |
|
| 291 |
// Calculate and update the tx and rx rates being displayed |
| 292 |
void UpdateRateDisplay(); |
| 293 |
|
| 294 |
// Check data bearer and duration, which are only available while |
| 295 |
// connected |
| 296 |
void CheckConnectedStats(); |
| 297 |
|
| 298 |
// Update the device info stats |
| 299 |
void UpdateDeviceInfo(); |
| 300 |
|
| 301 |
// Update the Connection Stats |
| 302 |
void UpdateConnectionInfo(); |
| 303 |
|
| 304 |
protected: |
| 305 |
|
| 306 |
/* Class for interfacing with Gobi API */ |
| 307 |
cGobiCMDLL mGobi; |
| 308 |
|
| 309 |
/* Connected device's ID */ |
| 310 |
std::string mDeviceID; |
| 311 |
|
| 312 |
/* All the display elements */ |
| 313 |
std::string mState; |
| 314 |
std::string mRSSI; |
| 315 |
std::string mTech; |
| 316 |
std::string mRx; |
| 317 |
std::string mTx; |
| 318 |
std::string mMaxRx; |
| 319 |
std::string mMaxTx; |
| 320 |
std::string mRoam; |
| 321 |
std::string mDuration; |
| 322 |
std::string mLifeDuration; |
| 323 |
std::string mLifeRx; |
| 324 |
std::string mLifeTx; |
| 325 |
std::string mManufact; |
| 326 |
std::string mModel; |
| 327 |
std::string mHardware; |
| 328 |
std::string mFirmware; |
| 329 |
std::string mMDN; |
| 330 |
std::string mMIN; |
| 331 |
std::string mESN; |
| 332 |
std::string mMEID; |
| 333 |
std::string mIMEI; |
| 334 |
std::string mIMSI; |
| 335 |
|
| 336 |
/* All the input elements */ |
| 337 |
std::string mAPN; |
| 338 |
std::string mUsername; |
| 339 |
std::string mPassword; |
| 340 |
|
| 341 |
/* Session state */ |
| 342 |
ULONG mSessionState; |
| 343 |
|
| 344 |
/* Data session ID */ |
| 345 |
ULONG mSessionID; |
| 346 |
|
| 347 |
/* Initial state, used to determine if the connection |
| 348 |
was initiated internally or externally */ |
| 349 |
ULONG mInitialState; |
| 350 |
|
| 351 |
/* Preferred service order */ |
| 352 |
std::list <ULONG> mPreferredServices; |
| 353 |
|
| 354 |
/* Stores the time that connection was started */ |
| 355 |
ULONGLONG mStartTime; |
| 356 |
|
| 357 |
/* Stores the connection rates updated by callbacks */ |
| 358 |
ULONGLONG mPreviousRX; |
| 359 |
ULONGLONG mPreviousTX; |
| 360 |
ULONGLONG mTotalRX; |
| 361 |
ULONGLONG mTotalTX; |
| 362 |
ULONGLONG mLifeTotalRX; |
| 363 |
ULONGLONG mLifeTotalTX; |
| 364 |
|
| 365 |
// Current and total durations |
| 366 |
ULONGLONG mCurrentDuration; |
| 367 |
ULONGLONG mTotalDuration; |
| 368 |
ULONGLONG mLifeTotalDuration; |
| 369 |
|
| 370 |
/* Did we initiate a start data session? */ |
| 371 |
bool mbInitiatedStartDataSession; |
| 372 |
|
| 373 |
/* Did we initiate a stop data session? */ |
| 374 |
bool mbInitiatedStopDataSession; |
| 375 |
|
| 376 |
/* Current signal map */ |
| 377 |
std::map <ULONG, INT8> mServiceSignals; |
| 378 |
|
| 379 |
/* Current data bearer technology */ |
| 380 |
ULONG mDataBearerTech; |
| 381 |
|
| 382 |
/* Current data capabilities */ |
| 383 |
std::list <ULONG> mDataCapabilities; |
| 384 |
|
| 385 |
/* Handle to the device detection thread */ |
| 386 |
pthread_t mDeviceDetectionThreadID; |
| 387 |
int mDeviceDetectionStopPipe[2]; |
| 388 |
|
| 389 |
// Device detection "thread" |
| 390 |
friend void * DeviceDetectionThread( void * pData ); |
| 391 |
|
| 392 |
/* Handle to the UpdateNetworkInfo thread */ |
| 393 |
pthread_t mUpdateNetworkInfoThreadID; |
| 394 |
cEvent mUpdateNetworkInfoEvent; |
| 395 |
|
| 396 |
// Async Network info updater |
| 397 |
friend void * UpdateNetworkInfoThread( void * pData ); |
| 398 |
}; |