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(20001, 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(), 0, 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(20001, KAiwCmdNFCGive, KContentType);
00127 criteria->SetServiceClass(base);
00128 User::LeaveIfError(interest.Append(criteria));
00129
00130
00131 iAiwServiceHandler->Reset();
00132 iAiwServiceHandler->AttachL(interest);
00133
00134 iAiwServiceHandler->ExecuteServiceCmdL(KAiwCmdNFCGive,
00135 iAiwServiceHandler->InParamListL(),
00136 iAiwServiceHandler->OutParamListL(), 0, 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 if (aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventStarted)
00160 {
00161 iAiwServiceHandler->ExecuteServiceCmdL(KAiwCmdNFCEasySetup,
00162 iAiwServiceHandler->InParamListL(),
00163 iAiwServiceHandler->OutParamListL(), 0, this);
00164
00165 }
00166 else if (aCmdId == KAiwCmdNFCGive && aEventId == KAiwEventStarted)
00167 {
00168 TInt err = KErrNone;
00169 if (ENfcvCard == iSharingType)
00170 {
00171 DoCommandL( KVCardFileName, err );
00172 }
00173 else if(ENfcvCal == iSharingType)
00174 {
00175 DoCommandL( KCalenderFileName, err );
00176 }
00177 }
00178 else if ( aCmdId == KAiwCmdNFCGive && aEventId == KAiwEventCompleted)
00179 {
00180
00181 if (ENfcvCard == iSharingType)
00182 {
00183 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("vCard sharing is successfully completed")));
00184 }
00185 else if(ENfcvCal == iSharingType)
00186 {
00187 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("vCal sharing is successfully completed")));
00188 }
00189 iAiwServiceHandler->Reset();
00190 }
00191
00192 else if ( aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventCompleted )
00193 {
00194
00195 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Easy set up is complete.")));
00196 iAiwServiceHandler->Reset();
00197 }
00198 else if ( aCmdId == KAiwCmdNFCGive && aEventId == KAiwEventError )
00199 {
00200
00201 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Error during asynchronous transfer request! Please try again")));
00202 iAiwServiceHandler->Reset();
00203 }
00204 else if ( aCmdId == KAiwCmdNFCEasySetup && aEventId == KAiwEventError )
00205 {
00206
00207 QT_TRYCATCH_LEAVING(emit(iNfcShareWrapper->windowUpdated("Error during asynchronous service setup request!")));
00208 iAiwServiceHandler->Reset();
00209 }
00210
00211 else if ( aEventId == KAiwEventCanceled )
00212 {
00213
00214 iAiwServiceHandler->Reset();
00215 }
00216 else if ( aEventId == KAiwEventError )
00217 {
00218
00219 iAiwServiceHandler->Reset();
00220 }
00221 else
00222 {
00223
00224 iAiwServiceHandler->Reset();
00225 }
00226 return KErrNone;
00227 }
00228
00229
00230
00231
00232
00233 void CNfcAiwEngine::StopServiceL()
00234 {
00235 iAiwServiceHandler->Reset();
00236 if(iAiwServiceHandler)
00237 {
00238 delete iAiwServiceHandler;
00239 }
00240 iAiwServiceHandler = CAiwServiceHandler::NewL();
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 TInt CNfcAiwEngine::DoCommandL( const TDesC& aFileName, TInt error )
00250 {
00251 error = iFs.Connect();
00252 if (error == KErrNone)
00253 {
00254 error = iFs.ShareProtected();
00255 }
00256
00257 if (error == KErrNone)
00258 {
00259 error = iFile.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly);
00260 }
00261 if (error != KErrNone)
00262 {
00263 return error;
00264 }
00265
00266 CAiwGenericParamList* inParamList = CAiwGenericParamList::NewLC();
00267 TAiwGenericParam obj(EGenericParamFile, TAiwVariant(iFile));
00268
00269 inParamList->AppendL(obj);
00270
00271 iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdNFCGive, *inParamList,
00272 iAiwServiceHandler->OutParamListL(), 0,
00273 this);
00274 CleanupStack::PopAndDestroy();
00275 iFile.Close();
00276 iFs.Close();
00277 return error;
00278 }