Nokia N97 SDK
Example Applications Guide

alrapplicationusingnopref.cpp

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

© Nokia 2009

Back to top