00001 // TXTSERV.CPP 00002 // 00003 // Copyright (c) 1999 Symbian Ltd. All rights reserved. 00004 // 00005 00006 #if !defined(__MSVENTRY_H__) 00007 #include <msventry.h> 00008 #endif 00009 00010 #if !defined(__TXTRICH_H__) 00011 #include <txtrich.h> 00012 #endif 00013 00014 #if !defined(_TXTCMDS_H_) 00015 #include "txtcmds.hrh" 00016 #endif 00017 #if !defined(__TXUT_H__) 00018 #include "../../Util/inc/txut.h" // Current service settings 00019 #endif 00020 00021 #include "txtserv.h" 00022 #include "txtscpmv.h" 00023 #include "txtmbox.h" 00024 00025 // 00026 // Factory function, constructor, initialisation, and destructor functions 00027 // 00028 00029 EXPORT_C CTextServerMtm* CTextServerMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aInitialEntry) 00030 // Exported factory function 00031 { 00032 CleanupStack::PushL(aInitialEntry); 00033 CTextServerMtm* self=new (ELeave) CTextServerMtm(aRegisteredMtmDll, aInitialEntry); 00034 CleanupStack::Pop(); 00035 00036 CleanupStack::PushL(self); 00037 self->ConstructL(); 00038 CleanupStack::Pop(); 00039 return self; 00040 } 00041 00042 CTextServerMtm::CTextServerMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aInitialEntry) 00043 : CBaseServerMtm(aRegisteredMtmDll, aInitialEntry), 00044 iCurrentOperation(ETxtOpIdle), 00045 iServiceEntryId(aInitialEntry->Entry().Id()) 00046 { 00047 } 00048 00049 void CTextServerMtm::ConstructL() 00050 { 00051 iReportStatus=NULL; 00052 CActiveScheduler::Add(this); 00053 User::LeaveIfError(iFs.Connect()); 00054 } 00055 00056 CTextServerMtm::~CTextServerMtm() 00057 { 00058 Cancel(); 00059 delete iTxtCopyMove; 00060 delete iTxtSettings; 00061 } 00062 00063 // 00064 // Copy and move functions 00065 // 00066 00067 void CTextServerMtm::CopyToLocalL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00068 TRequestStatus& aStatus) 00069 // Get remote entries (by copying) 00070 { 00071 ConnectToServiceL(); 00072 CTxtActiveOper* activeOperation = new (ELeave) CTxtCopyToLocalOp(iFs,*iServerEntry); 00073 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00074 } 00075 00076 void CTextServerMtm::CopyFromLocalL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00077 TRequestStatus& aStatus) 00078 // Transfer to remote (by copying) 00079 { 00080 ConnectToServiceL(); 00081 CTxtActiveOper* activeOperation = new (ELeave) CTxtCopyFromLocalOp(iFs,*iServerEntry); 00082 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00083 } 00084 00085 void CTextServerMtm::CopyWithinServiceL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00086 TRequestStatus& aStatus) 00087 // Copy entries within service 00088 { 00089 ConnectToServiceL(); 00090 CTxtActiveOper* activeOperation = new (ELeave) CTxtCopyWithinServiceOp(iFs,*iServerEntry); 00091 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00092 } 00093 00094 void CTextServerMtm::MoveToLocalL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00095 TRequestStatus& aStatus) 00096 // Get remote entries (by moving) 00097 { 00098 ConnectToServiceL(); 00099 CTxtActiveOper* activeOperation = new (ELeave) CTxtMoveToLocalOp(iFs, *iServerEntry); 00100 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00101 } 00102 00103 void CTextServerMtm::MoveFromLocalL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00104 TRequestStatus& aStatus) 00105 // Transfer to remote (by moving) 00106 { 00107 ConnectToServiceL(); 00108 CTxtActiveOper* activeOperation = new (ELeave) CTxtMoveFromLocalOp(iFs, *iServerEntry); 00109 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00110 } 00111 00112 void CTextServerMtm::MoveWithinServiceL(const CMsvEntrySelection& aSelection, TMsvId aDestination, 00113 TRequestStatus& aStatus) 00114 // Move entries within service 00115 { 00116 ConnectToServiceL(); 00117 CTxtActiveOper* activeOperation = new (ELeave) CTxtMoveWithinServiceOp(iFs,*iServerEntry); 00118 DoOperationL(activeOperation, aSelection,aDestination, aStatus); 00119 } 00120 00121 // 00122 // Create, change, delete functions 00123 // 00124 00125 void CTextServerMtm::DeleteAllL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus) 00126 // Delete entries recursively 00127 { 00128 ConnectToServiceL(); 00129 CTxtActiveOper* activeOperation = new (ELeave) CTxtDeleteOp(iFs, *iServerEntry); 00130 DoOperationL(activeOperation, aSelection,KMsvNullIndexEntryId, aStatus); 00131 } 00132 00133 void CTextServerMtm::CreateL(TMsvEntry /*aNewEntry*/, TRequestStatus& aStatus) 00134 // Remote creation (other than by copying) not supported 00135 // 00136 { 00137 TRequestStatus *sP = &aStatus; 00138 User::RequestComplete(sP, KErrAlreadyExists); 00139 } 00140 00141 void CTextServerMtm::ChangeL(TMsvEntry /*aNewEntry*/, TRequestStatus& aStatus) 00142 // Change entry 00143 // 00144 // This function could change file names in the file system. It would then also have 00145 // to change the details field of all the children of a changed folder name. 00146 // Not supported for now. 00147 // 00148 { 00149 TRequestStatus *sP = &aStatus; 00150 User::RequestComplete(sP, KErrNone); 00151 } 00152 00153 void CTextServerMtm::ConnectToServiceL() 00154 // Retrieves service settings before doing a "remote" operation 00155 { 00156 iServerEntry->SetEntry(iServiceEntryId); 00157 __ASSERT_DEBUG(iServerEntry->Entry().iType == KUidMsvServiceEntry, gPanic(ETxtsInvalidService)); 00158 00159 // Retrieve settings 00160 if (iTxtSettings == NULL) iTxtSettings = new (ELeave) TMTMTxtSettings; 00161 CMTMTxtSettings* settings = CMTMTxtSettings::NewL(); 00162 CleanupStack::PushL(settings); 00163 settings->LoadSettingsL(iServerEntry->Entry().Id(), *iTxtSettings); 00164 CleanupStack::PopAndDestroy(); // settings 00165 } 00166 00167 void CTextServerMtm::DoOperationL(CTxtActiveOper* aActiveOperation, const CMsvEntrySelection& aSelection, 00168 TMsvId aDestination, TRequestStatus& aStatus) 00169 // Do any of the copy/move from or to local, or delete operations, defined by aActiveOperation 00170 { 00171 CleanupStack::PushL(aActiveOperation); 00172 00173 __ASSERT_DEBUG(aActiveOperation,gPanic(ETxtsInvalidNullOperation)); 00174 AssertIdle(); 00175 AssertConnected(); 00176 00177 iReportStatus=&aStatus; 00178 iCurrentOperation=ETxtOpCopyMoveDel; 00179 00180 if (aDestination != KMsvNullIndexEntryId) 00181 { 00182 // Get folder name for destination 00183 iServerEntry->SetEntry(aDestination); 00184 TUid type = iServerEntry->Entry().iType; 00185 if (type == KUidMsvServiceEntry) 00186 { 00187 iParse.Set(KNullDesC,NULL,NULL); 00188 } 00189 else if (type == KUidMsvFolderEntry) 00190 { 00191 iParse.Set(iServerEntry->Entry().iDetails,NULL,NULL); 00192 iParse.AddDir(iServerEntry->Entry().iDescription); 00193 } 00194 else 00195 { 00196 gPanic(ETxtsInvalidDestination); 00197 } 00198 } 00199 00200 CleanupStack::Pop(); //aActiveOperation now owned by iTxtCopyMove 00201 iTxtCopyMove=CTxtCopyMoveBase::NewL(aActiveOperation,aSelection, *iServerEntry, iServiceEntryId, iParse); 00202 aStatus=iStatus = KRequestPending; 00203 iTxtCopyMove->Start(iStatus); 00204 SetActive(); 00205 } 00206 00207 // 00208 // Command and progress functions 00209 // 00210 00211 void CTextServerMtm::StartCommandL(CMsvEntrySelection& /*aSelection*/, TInt aCommand, 00212 const TDesC8& /*aParameter*/, TRequestStatus& aStatus) 00213 // Run MTM-specific command on selection of entries 00214 // Only command supported is Refresh 00215 { 00216 AssertIdle(); 00217 00218 switch (aCommand) 00219 { 00220 case KTXTMTMRefresh: 00221 { 00222 ConnectToServiceL(); 00223 DoRefreshL(); 00224 TRequestStatus* sP=&aStatus; 00225 User::RequestComplete(sP,KErrNone); 00226 } 00227 break; 00228 default: 00229 TRequestStatus* sP=&aStatus; 00230 User::RequestComplete(sP, KErrNotSupported); 00231 break; 00232 } 00233 } 00234 00235 TBool CTextServerMtm::CommandExpected() 00236 // Prevent object deletion on command completion 00237 // Allow unloading 00238 { 00239 return EFalse; 00240 } 00241 00242 const TDesC8& CTextServerMtm::Progress() 00243 // Pass-back progress information 00244 { 00245 switch (iCurrentOperation) 00246 { 00247 case ETxtOpCopyMoveDel: 00248 iProgressBuf() = iTxtCopyMove->Progress(); 00249 break; 00250 default: 00251 break; 00252 } 00253 return iProgressBuf; 00254 } 00255 00256 // 00257 // Active object completion functions 00258 // 00259 00260 void CTextServerMtm::DoCancel() 00261 // Cancel current operation 00262 { 00263 // The only operations that are actually asynchronous are the 00264 // copy, move, delete. Others complete synchronously. 00265 switch (iCurrentOperation) 00266 { 00267 case ETxtOpCopyMoveDel: 00268 { 00269 delete iTxtCopyMove; 00270 iTxtCopyMove=NULL; 00271 } 00272 break; 00273 default: 00274 AssertIdle(); 00275 break; 00276 } 00277 iCurrentOperation=ETxtOpIdle; 00278 TRequestStatus* pS=&iStatus; 00279 User::RequestComplete(pS, KErrCancel); 00280 } 00281 00282 void CTextServerMtm::DoComplete(TInt aError) 00283 // Active object complete leave handler 00284 // 00285 // Never expect this to be called 00286 // as CTextServerMtm::DoRunL() does not leave 00287 { 00288 User::RequestComplete(iReportStatus,aError); 00289 iReportStatus=NULL; 00290 } 00291 00292 void CTextServerMtm::DoRunL() 00293 // Active object completion 00294 // 00295 // Run is used in this object to clean up after operations have finished. 00296 // 00297 { 00298 __ASSERT_DEBUG(iReportStatus != NULL,gPanic(ETxtsStrayRequest)); 00299 // Pass on an error code if there was one. 00300 00301 // Shouldn't have any errors in iStatus, but put them in Progress 00302 // anyway for safety 00303 00304 if (iStatus!=KErrNone) 00305 iProgressBuf().iErrorCode=iStatus.Int(); 00306 00307 // Determine the kind of clean up to do after the active process has stopped 00308 switch (iCurrentOperation) 00309 { 00310 case ETxtOpCopyMoveDel: 00311 { 00312 iProgressBuf() = iTxtCopyMove->Progress(); 00313 delete iTxtCopyMove; 00314 iTxtCopyMove=NULL; 00315 } 00316 break; 00317 default: 00318 break; 00319 } 00320 iCurrentOperation=ETxtOpIdle; 00321 // Always return KErrNone; errors are returned in Progress 00322 User::RequestComplete(iReportStatus,KErrNone); 00323 iReportStatus=NULL; 00324 } 00325 00326 00327 // 00328 // Methods needed to refresh the service 00329 // 00330 00331 void CTextServerMtm::DoRefreshL() 00332 // Perform refresh 00333 { 00334 AssertConnected(); 00335 TFileName relativePath(KNullDesC); 00336 00337 CTxtRefreshMBox *folderSynchroniser = CTxtRefreshMBox::NewL(iFs, relativePath, 00338 iServiceEntryId, iServerEntry, iServiceEntryId, *iTxtSettings); 00339 00340 CleanupStack::PushL(folderSynchroniser); 00341 while (!folderSynchroniser->DoStepL()) ; 00342 CleanupStack::PopAndDestroy(); //folderSynchroniser 00343 } 00344
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.