00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "nfcsharewrapper.h"
00033 #include "nfcaiwengine.h"
00034
00035
00036
00037
00038 CNfcAiwEngine::CNfcAiwEngine(NfcShareWrapper* aNfcShareWrapper) : iNfcShareWrapper(aNfcShareWrapper)
00039 {
00040 }
00041
00042
00043
00044
00045
00046 CNfcAiwEngine* CNfcAiwEngine::NewL(NfcShareWrapper* aNfcShareWrapper)
00047 {
00048 CNfcAiwEngine* self = CNfcAiwEngine::NewLC(aNfcShareWrapper);
00049 CleanupStack::Pop();
00050 return self;
00051 }
00052
00053
00054
00055
00056
00057 CNfcAiwEngine* CNfcAiwEngine::NewLC(NfcShareWrapper* aNfcShareWrapper)
00058 {
00059 CNfcAiwEngine* self = new (ELeave) CNfcAiwEngine(aNfcShareWrapper);
00060 CleanupStack::PushL(self);
00061 self->ConstructL();
00062 return self;
00063 }
00064
00065
00066
00067
00068 void CNfcAiwEngine::ConstructL()
00069 {
00070 iAiwServiceHandler = CAiwServiceHandler::NewL();
00071 }
00072
00073
00074
00075
00076 CNfcAiwEngine::~CNfcAiwEngine()
00077 {
00078 iFs.Close();
00079 if (iAiwServiceHandler)
00080 {
00081 delete iAiwServiceHandler;
00082 iAiwServiceHandler = NULL;
00083 }
00084 }
00085
00086
00087
00088
00089 TInt CNfcAiwEngine::StartEasySetupServiceL()
00090 {
00091
00092 RCriteriaArray interest;
00093 CleanupClosePushL(interest);
00094 TUid base;
00095 _LIT8(KContentType,"*");
00096 base.iUid = KAiwClassBase;
00097 CAiwCriteriaItem* criteria = CAiwCriteriaItem::NewLC( KAiwCmdNFCEasySetup, KAiwCmdNFCEasySetup, KContentType );
00098 criteria->SetServiceClass(base);
00099 User::LeaveIfError(interest.Append(criteria));
00100
00101
00102 iAiwServiceHandler->Reset();
00103 iAiwServiceHandler->AttachL(interest);
00104
00105 iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdNFCEasySetup,
00106 iAiwServiceHandler->InParamListL(),
00107 iAiwServiceHandler->OutParamListL(), KAiwOptASyncronous, this);
00108 CleanupStack::PopAndDestroy(2);
00109 return KErrNone;
00110 }
00111
00112
00113
00114
00115
00116
00117 TInt CNfcAiwEngine::StartSharingServiceL(NfcSharingType aSharingType)
00118 {
00119
00120 RCriteriaArray interest;
00121 CleanupClosePushL(interest);
00122 iSharingType = aSharingType;
00123 TUid base;
00124 base.iUid = KAiwClassBase;
00125 _LIT8(KContentType,"*");
00126 CAiwCriteriaItem* criteria = CAiwCriteriaItem::NewLC( KAiwCmdNFCGiveUi, KAiwCmdNFCGiveUi, KContentType);
00127 criteria->SetServiceClass(base);
00128 User::LeaveIfError(interest.Append(criteria));
00129
00130
00131 iAiwServiceHandler->Reset();
00132 iAiwServiceHandler->AttachL(interest);
00133
00134 iAiwServiceHandler->ExecuteServiceCmdL(KAiwCmdNFCGiveUi,
00135 iAiwServiceHandler->InParamListL(),
00136 iAiwServiceHandler->OutParamListL(), KAiwOptASyncronous, this);
00137 CleanupStack::PopAndDestroy(2);
00138 return KErrNone;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 TInt CNfcAiwEngine::HandleNotifyL(TInt aCmdId, TInt aEventId,
00155 CAiwGenericParamList& ,
00156 const CAiwGenericParamList& )
00157 {
00158
00159
00160 if (aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventStarted)
00161 {
00162 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated
00163 ("Easy setup will complete, if you tap it with a NFC device.")));
00164
00165 }
00166 else if (aCmdId == KAiwCmdNFCGiveUi && aEventId == KAiwEventStarted)
00167 {
00168 TInt err = KErrNone;
00169 if (ENfcvCard == iSharingType)
00170 {
00171 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated
00172 ("sharing vCard started.")));
00173 DoCommandL( KVCardFileName, err );
00174 }
00175 else if(ENfcvCal == iSharingType)
00176 {
00177 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated
00178 ("sharing vCal started.")));
00179 DoCommandL( KCalenderFileName, err );
00180 }
00181 }
00182 else if ( aCmdId == KAiwCmdNFCGiveUi && aEventId == KAiwEventCompleted)
00183 {
00184
00185
00186 if (ENfcvCard == iSharingType)
00187 {
00188 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("vCard sharing is successfully completed")));
00189 }
00190 else if(ENfcvCal == iSharingType)
00191 {
00192 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("vCal sharing is successfully completed")));
00193 }
00194 iAiwServiceHandler->Reset();
00195 }
00196
00197 else if ( aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventCompleted )
00198 {
00199
00200
00201 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Easy set up is complete.")));
00202 iAiwServiceHandler->Reset();
00203 }
00204 else if ( aCmdId == KAiwCmdNFCGiveUi && aEventId == KAiwEventError )
00205 {
00206
00207
00208 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Error during asynchronous transfer request! Please try again")));
00209 iAiwServiceHandler->Reset();
00210 }
00211 else if ( aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventError )
00212 {
00213
00214
00215 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Error during asynchronous service setup request!")));
00216 iAiwServiceHandler->Reset();
00217 }
00218
00219 else if ( aEventId == KAiwEventCanceled )
00220 {
00221
00222
00223 iAiwServiceHandler->Reset();
00224 }
00225 else if ( aEventId == KAiwEventError )
00226 {
00227
00228
00229 iAiwServiceHandler->Reset();
00230 }
00231 else
00232 {
00233
00234
00235 iAiwServiceHandler->Reset();
00236 }
00237 return KErrNone;
00238 }
00239
00240
00241
00242
00243
00244 void CNfcAiwEngine::StopServiceL()
00245 {
00246 iAiwServiceHandler->Reset();
00247 if(iAiwServiceHandler)
00248 {
00249 delete iAiwServiceHandler;
00250 }
00251 iAiwServiceHandler = CAiwServiceHandler::NewL();
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 TInt CNfcAiwEngine::DoCommandL( const TDesC& aFileName, TInt error )
00261 {
00262 error = iFs.Connect();
00263 if (error == KErrNone)
00264 {
00265 error = iFs.ShareProtected();
00266 }
00267
00268 if (error == KErrNone)
00269 {
00270 error = iFile.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly);
00271 }
00272 if (error != KErrNone)
00273 {
00274 return error;
00275 }
00276
00277 CAiwGenericParamList* inParamList = CAiwGenericParamList::NewLC();
00278 TAiwGenericParam obj(EGenericParamFile, TAiwVariant(iFile));
00279
00280
00281 inParamList->AppendL(obj);
00282
00283
00284 iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdNFCGiveUi, *inParamList,
00285 iAiwServiceHandler->OutParamListL(), KAiwOptASyncronous,
00286 this);
00287 CleanupStack::PopAndDestroy();
00288 iFile.Close();
00289 iFs.Close();
00290 return error;
00291 }