Nokia N97 SDK
Example Applications Guide

standardapplication.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : standardapplication.cpp
00004 *  Part of     : datamobility
00005 *  Description : CStandardApplication 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 <CommDbConnPref.h>
00019 #include "standardapplication.h"
00020 #include "datamobilityprinter.h"
00021 
00022 // ============================ MEMBER FUNCTIONS ===============================
00023 
00024 // -----------------------------------------------------------------------------
00025 // CStandardApplication::NewL
00026 // -----------------------------------------------------------------------------
00027 //
00028 CStandardApplication* CStandardApplication::NewL( MDataMobilityPrinter& aObserver )
00029     {
00030     CStandardApplication* self =
00031         new ( ELeave ) CStandardApplication( aObserver );
00032     CleanupStack::PushL( self );
00033     self->ConstructL();
00034     CleanupStack::Pop( self );
00035     return self;
00036     }
00037 
00038 // -----------------------------------------------------------------------------
00039 // CStandardApplication::ConstructL
00040 // -----------------------------------------------------------------------------
00041 //
00042 void CStandardApplication::ConstructL()
00043     {
00044     User::LeaveIfError( iSocketServer.Connect() );
00045     }
00046 
00047 // -----------------------------------------------------------------------------
00048 // CStandardApplication::CStandardApplication
00049 // -----------------------------------------------------------------------------
00050 //
00051 CStandardApplication::CStandardApplication( MDataMobilityPrinter& aObserver )
00052     : CActive( CActive::EPriorityStandard ),
00053       iObserver( aObserver )
00054     {
00055     CActiveScheduler::Add( this );
00056     }
00057 
00058 // -----------------------------------------------------------------------------
00059 // CStandardApplication::~CStandardApplication
00060 // -----------------------------------------------------------------------------
00061 //
00062 CStandardApplication::~CStandardApplication()
00063     {
00064     Cancel();
00065 
00066     iConnection.Close();
00067 
00068     iSocketServer.Close();
00069     }
00070 
00071 // -----------------------------------------------------------------------------
00072 // CStandardApplication::StartL
00073 // -----------------------------------------------------------------------------
00074 //
00075 void CStandardApplication::StartL()
00076     {
00077     User::LeaveIfError( iConnection.Open( iSocketServer ) );
00078 
00079     // Let's open a valid access point
00080     TCommDbConnPref prefs;
00081     prefs.SetIapId( 1 ); // assume 1 is a valid IAP configured in CommsDat
00082     prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
00083 
00084     PrintL( R_OUTPUT_START_CONNECTION_WITH_PREFERENCES );
00085 
00086     PrintL( R_OUTPUT_IAP_ID, prefs.IapId() );
00087 
00088     iConnection.Start( prefs, iStatus );
00089 
00090     SetActive();
00091     }
00092 
00093 // -----------------------------------------------------------------------------
00094 // CStandardApplication::RunL
00095 // -----------------------------------------------------------------------------
00096 //
00097 void CStandardApplication::RunL()
00098     {
00099     if ( iStatus.Int() == KErrNone )
00100         {
00101         PrintL( R_OUTPUT_CONNECTION_STARTED );
00102         }
00103     else
00104         {
00105         PrintL( R_OUTPUT_RUNL_STATUS_ERROR, iStatus.Int() );
00106         }
00107     }
00108 
00109 // -----------------------------------------------------------------------------
00110 // CStandardApplication::DoCancel
00111 // -----------------------------------------------------------------------------
00112 //
00113 void CStandardApplication::DoCancel()
00114     {
00115     iConnection.Close();
00116     // iConnection.Stop() should be avoided:
00117     // other client applications' connection should not be terminated.
00118     }
00119 
00120 // -----------------------------------------------------------------------------
00121 // CStandardApplication::PrintL
00122 // -----------------------------------------------------------------------------
00123 //
00124 void CStandardApplication::PrintL( TInt aResourceId )
00125     {
00126     // Load a string from the resource file.
00127     HBufC* message = StringLoader::LoadL( aResourceId );
00128 
00129     iObserver.Print( *message );
00130 
00131     delete message;
00132     }
00133 
00134 // -----------------------------------------------------------------------------
00135 // CStandardApplication::PrintL
00136 // -----------------------------------------------------------------------------
00137 //
00138 void CStandardApplication::PrintL( TInt aResourceId, TInt aInt )
00139     {
00140     // Load a string from the resource file.
00141     HBufC* message = StringLoader::LoadL( aResourceId, aInt );
00142 
00143     iObserver.Print( *message );
00144 
00145     delete message;
00146     }
00147 
00148 //  End of File

© Nokia 2009

Back to top