Nokia N97 SDK
Example Applications Guide

applicationtriggeringconndlg.cpp

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

© Nokia 2009

Back to top