Nokia N97 SDK
Example Applications Guide

alrapplication.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : alrapplication.cpp
00004 *  Part of     : datamobility
00005 *  Description : CALRApplication implementation.
00006 *
00007 *  Copyright (c) 2007 Nokia Corporation.
00008 *  This material, including documentation and any related
00009 *  computer programs, is protected by copyright controlled by
00010 *  Nokia Corporation.
00011 * ==============================================================================
00012 */
00013 
00014 // INCLUDE FILES
00015 #include <e32cons.h>
00016 #include <stringloader.h>
00017 #include <datamobility.rsg>
00018 #include <connpref.h>
00019 #include "alrapplication.h"
00020 #include "datamobilityprinter.h"
00021 
00022 // ============================ MEMBER FUNCTIONS ===============================
00023 
00024 // -----------------------------------------------------------------------------
00025 // CALRApplication::NewL
00026 // -----------------------------------------------------------------------------
00027 //
00028 CALRApplication* CALRApplication::NewL( MDataMobilityPrinter& aObserver )
00029     {
00030     CALRApplication* self =
00031         new ( ELeave ) CALRApplication( aObserver );
00032     CleanupStack::PushL( self );
00033     self->ConstructL();
00034     CleanupStack::Pop( self );
00035     return self;
00036     }
00037 
00038 // -----------------------------------------------------------------------------
00039 // CALRApplication::ConstructL
00040 // -----------------------------------------------------------------------------
00041 //
00042 void CALRApplication::ConstructL()
00043     {
00044     User::LeaveIfError( iSocketServer.Connect() );
00045     }
00046 
00047 // -----------------------------------------------------------------------------
00048 // CALRApplication::CALRApplication
00049 // -----------------------------------------------------------------------------
00050 //
00051 CALRApplication::CALRApplication( MDataMobilityPrinter& aObserver )
00052     : CActive( CActive::EPriorityStandard ),
00053       iObserver( aObserver ),
00054       iMobility( NULL )
00055     {
00056     CActiveScheduler::Add( this );
00057     }
00058 
00059 // -----------------------------------------------------------------------------
00060 // CALRApplication::~CALRApplication
00061 // -----------------------------------------------------------------------------
00062 //
00063 CALRApplication::~CALRApplication()
00064     {
00065     delete iMobility;
00066 
00067     Cancel();
00068 
00069     iConnection.Close();
00070 
00071     iSocketServer.Close();
00072     }
00073 
00074 // -----------------------------------------------------------------------------
00075 // CALRApplication::StartL
00076 // -----------------------------------------------------------------------------
00077 //
00078 void CALRApplication::StartL()
00079     {
00080     User::LeaveIfError( iConnection.Open( iSocketServer ) );
00081 
00082     TConnSnapPref prefs;
00083     prefs.SetSnap( 1 ); // assume 1 is a valid SNAP configured in CommsDat
00084 
00085     Print( R_OUTPUT_START_CONNECTION_WITH_PREFERENCES );
00086 
00087     Print( R_OUTPUT_SNAP_ID, prefs.Snap() );
00088 
00089     iConnection.Start( prefs, iStatus );
00090 
00091     SetActive();
00092     }
00093 
00094 // -----------------------------------------------------------------------------
00095 // CALRApplication::PreferredCarrierAvailable
00096 // -----------------------------------------------------------------------------
00097 //
00098 void CALRApplication::PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
00099                                                  TAccessPointInfo aNewAPInfo,
00100                                                  TBool aIsUpgrade,
00101                                                  TBool aIsSeamless )
00102     {
00103     Print( R_OUTPUT_PREFERREDCARRIERAVAILABLE );
00104 
00105     Print( R_OUTPUT_OLD_IAP_ID, aOldAPInfo.AccessPoint() );
00106     
00107     Print( R_OUTPUT_NEW_IAP_ID, aNewAPInfo.AccessPoint() );
00108 
00109     if ( aIsUpgrade )
00110         {
00111         Print( R_OUTPUT_IT_IS_UPGRADE );
00112         }
00113     else
00114         {
00115         Print( R_OUTPUT_IT_IS_NOT_UPGRADE );
00116         }
00117 
00118     if ( aIsSeamless )
00119         {
00120         // in S60 3.2, this situation cannot occur.
00121         Print( R_OUTPUT_IT_IS_SEAMLESS );
00122         }
00123     else
00124         {
00125         Print( R_OUTPUT_IT_IS_NOT_SEAMLESS );
00126         // Sockets have to be closed at this point.
00127         Print( R_OUTPUT_WE_ASK_TO_MIGRATE );
00128 
00129         iMobility->MigrateToPreferredCarrier();
00130         }
00131 
00132     }
00133 
00134 // -----------------------------------------------------------------------------
00135 // CALRApplication::NewCarrierActive
00136 // -----------------------------------------------------------------------------
00137 //
00138 void CALRApplication::NewCarrierActive( TAccessPointInfo aNewAPInfo,
00139                                         TBool aIsSeamless )
00140     {
00141     Print( R_OUTPUT_NEWCARRIERACTIVE_IAP_ID, aNewAPInfo.AccessPoint() );
00142 
00143     if ( aIsSeamless )
00144         {
00145         // in S60 3.2, this situation cannot occur.
00146         Print( R_OUTPUT_IT_IS_SEAMLESS );
00147         }
00148     else
00149         {
00150         Print( R_OUTPUT_IT_IS_NOT_SEAMLESS );
00151         // Sockets have to be re-opened and check they can connect
00152         // to their server at this point.
00153         Print( R_OUTPUT_WE_ACCEPT_IT );
00154 
00155         iMobility->NewCarrierAccepted();
00156         }
00157     }
00158 
00159 // -----------------------------------------------------------------------------
00160 // CALRApplication::Error
00161 // -----------------------------------------------------------------------------
00162 //
00163 void CALRApplication::Error( TInt aError )
00164     {
00165     Print( R_OUTPUT_MOBILITY_ERROR, aError );
00166     }
00167 
00168 // -----------------------------------------------------------------------------
00169 // CALRApplication::RunL
00170 // -----------------------------------------------------------------------------
00171 //
00172 void CALRApplication::RunL()
00173     {
00174     if ( iStatus.Int() == KErrNone )
00175         {
00176         TUint32 iap( 0 );
00177         _LIT( KIAPId, "IAP\\Id" );
00178         iConnection.GetIntSetting( KIAPId, iap );
00179 
00180         Print( R_OUTPUT_CONNECTION_STARTED_WITH_IAP_ID, iap );
00181 
00182         iMobility = CActiveCommsMobilityApiExt::NewL( iConnection, *this );
00183 
00184         Print( R_OUTPUT_APPLICATION_REGISTERED_FOR_MOBILITY );
00185 
00186         Print( R_OUTPUT_MESSAGE_NOTIFICATIONS );
00187         }
00188     else
00189         {
00190         Print( R_OUTPUT_RUNL_STATUS_ERROR, iStatus.Int() );
00191         }
00192     }
00193 
00194 // -----------------------------------------------------------------------------
00195 // CALRApplication::DoCancel
00196 // -----------------------------------------------------------------------------
00197 //
00198 void CALRApplication::DoCancel()
00199     {
00200     iConnection.Close();
00201     // iConnection.Stop() should be avoided:
00202     // other client applications' connection should not be terminated.
00203     }
00204 
00205 // -----------------------------------------------------------------------------
00206 // CALRApplication::RunError
00207 // -----------------------------------------------------------------------------
00208 //
00209 TInt CALRApplication::RunError( TInt aError )
00210     {
00211     Print( R_OUTPUT_RUNERROR_ERROR, aError );
00212 
00213     return KErrNone;
00214     }
00215 
00216 // -----------------------------------------------------------------------------
00217 // CALRApplication::Print
00218 // -----------------------------------------------------------------------------
00219 //
00220 void CALRApplication::Print( TInt aResourceId )
00221     {
00222     // Load a string from the resource file.
00223     HBufC* message = NULL;
00224     TRAPD( err, message = StringLoader::LoadL( aResourceId ) );
00225     if ( err != KErrNone )
00226         {
00227         return;
00228         }
00229 
00230     iObserver.Print( *message );
00231 
00232     delete message;
00233     }
00234 
00235 // -----------------------------------------------------------------------------
00236 // CALRApplication::Print
00237 // -----------------------------------------------------------------------------
00238 //
00239 void CALRApplication::Print( TInt aResourceId, TInt aInt )
00240     {
00241     // Load a string from the resource file.
00242     HBufC* message = NULL;
00243     TRAPD( err, message = StringLoader::LoadL( aResourceId, aInt ) );
00244     if ( err != KErrNone )
00245         {
00246         return;
00247         }
00248 
00249     iObserver.Print( *message );
00250 
00251     delete message;
00252     }
00253 
00254 //  End of File

© Nokia 2009

Back to top