Nokia N97 SDK
Example Applications Guide

gmssignalmonitor.cpp

00001 /*
00002  ============================================================================
00003  Name           : GMSSignalMonitor.cpp
00004  Author   : 
00005  Version         : 1.1
00006  Copyright   : This material, including documentation and any related computer
00007           programs, is protected by copyright controlled by Nokia Corporation.
00008  Description : CGMSSignalMonitor implementation
00009  ============================================================================
00010  */
00011 
00012 #include "gmssignalmonitor.h"
00013 
00014 // -----------------------------------------------------------------------------
00015 // C++ constructor
00016 // -----------------------------------------------------------------------------
00017 //
00018 CGMSSignalMonitor::CGMSSignalMonitor(MSignalObserver& aObserver) :
00019         CActive(EPriorityStandard), // Standard priority
00020         iPackage(iSignal),
00021         iObserver(aObserver)
00022         {
00023         }
00024 
00025 // -----------------------------------------------------------------------------
00026 // Two-phased constructor. Leaves constructed object on the cleanup stack
00027 // -----------------------------------------------------------------------------
00028 //
00029 CGMSSignalMonitor* CGMSSignalMonitor::NewLC(MSignalObserver& aObserver)
00030         {
00031         CGMSSignalMonitor* self = new (ELeave) CGMSSignalMonitor(aObserver);
00032         CleanupStack::PushL(self);
00033         self->ConstructL();
00034         return self;
00035         }
00036         
00037 // -----------------------------------------------------------------------------
00038 // Two-phased constructor. 
00039 // -----------------------------------------------------------------------------
00040 //
00041 CGMSSignalMonitor* CGMSSignalMonitor::NewL(MSignalObserver& aObserver)
00042         {
00043         CGMSSignalMonitor* self = CGMSSignalMonitor::NewLC(aObserver);
00044         CleanupStack::Pop(); // self;
00045         return self;
00046         }
00047 
00048 // -----------------------------------------------------------------------------
00049 // Second-phase constructor
00050 // -----------------------------------------------------------------------------
00051 //
00052 void CGMSSignalMonitor::ConstructL()
00053         {
00054         iTelephony = CTelephony::NewL();
00055         CActiveScheduler::Add(this); // Add to scheduler
00056         StartL();
00057         }
00058 
00059 // -----------------------------------------------------------------------------
00060 // Cancel the pending request and destroy the object
00061 // -----------------------------------------------------------------------------
00062 //
00063 CGMSSignalMonitor::~CGMSSignalMonitor()
00064         {
00065         Cancel(); // Cancel any request, if outstanding
00066         delete iTelephony;
00067         // Delete instance variables if any
00068         }
00069 
00070 // -----------------------------------------------------------------------------
00071 // From CActive.
00072 // Get's called when the current pending request is being canceled. 
00073 // -----------------------------------------------------------------------------
00074 //
00075 void CGMSSignalMonitor::DoCancel()
00076         {
00077         iTelephony->CancelAsync(CTelephony::ESignalStrengthChangeCancel);
00078         }
00079 
00080 // -----------------------------------------------------------------------------
00081 // Function for making the initial asynchronous request
00082 // -----------------------------------------------------------------------------
00083 //
00084 void CGMSSignalMonitor::StartL()
00085         {
00086         if(!IsActive())
00087                 {
00088                 iTelephony->NotifyChange(iStatus,
00089                         CTelephony::ESignalStrengthChange, iPackage);
00090                 SetActive(); // Tell scheduler a request is active
00091                 }
00092         }
00093 
00094 // -----------------------------------------------------------------------------
00095 // From CActive. Handle completion of the current pending request
00096 // -----------------------------------------------------------------------------
00097 //
00098 void CGMSSignalMonitor::RunL()
00099         {
00100         // leave in case the call completed with an error
00101         // this will cause the RunError method to be called with
00102         // CActive::iStatus' value as parameter
00103         User::LeaveIfError(iStatus.Int());
00104 
00105         // forward the info to the observer
00106         iObserver.SignalLevelChangedL(iSignal.iSignalStrength, iSignal.iBar);
00107 
00108         // re-start
00109         StartL();
00110         }
00111 
00112 // -----------------------------------------------------------------------------
00113 // From CActive. Override to handle leaves from RunL().
00114 // Ignores all errors but the active object remains innactive 
00115 // -----------------------------------------------------------------------------
00116 //
00117 TInt CGMSSignalMonitor::RunError(TInt /*aError*/)
00118         {
00119         return KErrNone; // aError;
00120         }
00121 

© Nokia 2009

Back to top