examples/Messaging/TextMTM/txts/TXTSERV.CPP

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

Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by  doxygen 1.5.3