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