remotestoragefw/remotefileengine/src/rsfwremoteaccesssync.cpp
branchRCL_3
changeset 19 88ee4cf65e19
parent 16 87c71b25c937
child 20 1aa8c82cb4cb
equal deleted inserted replaced
16:87c71b25c937 19:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Synchronous layer on top of the Access Protocol plug-in API
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "rsfwremoteaccesssync.h"
       
    21 
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ==============================
       
    24 
       
    25 CRsfwRemoteAccessSync* CRsfwRemoteAccessSync::NewL(const TDesC8& aService,
       
    26                                            CRsfwRemoteAccess* aRemoteAccess)
       
    27     {
       
    28     CRsfwRemoteAccessSync* self = new (ELeave) CRsfwRemoteAccessSync;
       
    29     CleanupStack::PushL(self);
       
    30     self->ConstructL(aService, aRemoteAccess);
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33     }
       
    34 
       
    35 void CRsfwRemoteAccessSync::ConstructL(const TDesC8& aService,
       
    36                                    CRsfwRemoteAccess* aRemoteAccess)
       
    37     {
       
    38     if (aRemoteAccess)
       
    39         {
       
    40         iRemoteAccess = aRemoteAccess;
       
    41         }
       
    42     else
       
    43         {
       
    44         iRemoteAccess = CRsfwRemoteAccess::NewL(aService);
       
    45         iOwnRemoteAccess = ETrue;
       
    46         }
       
    47     iSchedulerWait = new CActiveSchedulerWait();   
       
    48     }
       
    49 
       
    50 CRsfwRemoteAccessSync::~CRsfwRemoteAccessSync()
       
    51     {
       
    52     if (iOwnRemoteAccess)
       
    53         {
       
    54         delete iRemoteAccess;
       
    55         }
       
    56     delete iSchedulerWait;    
       
    57     }
       
    58 
       
    59 TInt CRsfwRemoteAccessSync::Setup(
       
    60     MRsfwRemoteAccessObserver* aRsfwRemoteAccessObserver)
       
    61     {
       
    62     TRAPD(err, iRemoteAccess->SetupL(aRsfwRemoteAccessObserver));
       
    63     return err;
       
    64     }
       
    65 
       
    66 TInt CRsfwRemoteAccessSync::Open(const TDesC& aUserName,
       
    67                              const TDesC& aPassword,
       
    68                              const TDesC& aServerName,
       
    69                              TInt aPortNumber,
       
    70                              const TDesC& aRootDirectory,
       
    71                              const TDesC& aAuxData)
       
    72     {
       
    73     if (iPending)
       
    74         {
       
    75         return KErrServerBusy;
       
    76         }
       
    77     iPending = ETrue;
       
    78     TBuf<KMaxPath> url;
       
    79     url.Append(_L("http://"));
       
    80     url.Append(aServerName);
       
    81     url.Append(_L(":"));
       
    82     url.AppendNum(aPortNumber);
       
    83     url.Append(_L("/"));
       
    84     url.Append(aRootDirectory);
       
    85     
       
    86     
       
    87     TUriParser uriParser;
       
    88     uriParser.Parse(url);
       
    89     
       
    90     TRAP(iStatus, iRemoteAccess->OpenL(uriParser,
       
    91                                        aServerName,
       
    92                                        aUserName,
       
    93                                        aPassword,
       
    94                                        aAuxData,
       
    95                                        this));
       
    96     return Epilog();
       
    97     }
       
    98 
       
    99 TInt CRsfwRemoteAccessSync::GetDirectory(const TDesC& aPathName,
       
   100                                      RPointerArray<CRsfwDirEnt>& aDirEnts)
       
   101     {
       
   102     if (iPending)
       
   103         {
       
   104         return KErrServerBusy;
       
   105         }
       
   106     iPending = ETrue;
       
   107     TRAP(iStatus, iRemoteAccess->GetDirectoryL(aPathName,
       
   108                                                aDirEnts,
       
   109                                                this));
       
   110     return Epilog();
       
   111     }
       
   112 
       
   113 TInt CRsfwRemoteAccessSync::GetFile(const TDesC& aRemotePathName,
       
   114                                 const TDesC& aLocalPathName,
       
   115                                 TInt aOffset,
       
   116                                 TInt* aLength,
       
   117                                 TUint aFlags)
       
   118     {
       
   119     if (iPending)
       
   120         {
       
   121         return KErrServerBusy;
       
   122         }
       
   123     iPending = ETrue;
       
   124     TRAP(iStatus, iRemoteAccess->GetFileL(aRemotePathName,
       
   125                                           aLocalPathName,
       
   126                                           aOffset,
       
   127                                           aLength,
       
   128                                           aFlags,
       
   129                                           this));
       
   130     return Epilog();
       
   131     }
       
   132 
       
   133 TInt CRsfwRemoteAccessSync::MakeDirectory(const TDesC& aPathName)
       
   134     {
       
   135     if (iPending)
       
   136         {
       
   137         return KErrServerBusy;
       
   138         }
       
   139     iPending = ETrue;
       
   140     TRAP(iStatus, iRemoteAccess->MakeDirectoryL(aPathName, this));
       
   141     return Epilog();
       
   142     }
       
   143 
       
   144 TInt CRsfwRemoteAccessSync::CreateFile(const TDesC& aPathName)
       
   145     {
       
   146     if (iPending)
       
   147         {
       
   148         return KErrServerBusy;
       
   149         }
       
   150     iPending = ETrue;
       
   151     TRAP(iStatus, iRemoteAccess->CreateFileL(aPathName, 0, this));
       
   152     return Epilog();
       
   153     }
       
   154 
       
   155 TInt CRsfwRemoteAccessSync::PutFile(const TDesC& aLocalPathName,
       
   156                                 const TDesC& aRemotePathName)
       
   157     {
       
   158     _LIT8(KTextPlain, "text/plain");
       
   159     if (iPending)
       
   160         {
       
   161         return KErrServerBusy;
       
   162         }
       
   163     iPending = ETrue;
       
   164     TRAP(iStatus, iRemoteAccess->PutFileL(aLocalPathName,
       
   165                                           aRemotePathName,
       
   166                                           KTextPlain,
       
   167                                           this));
       
   168     return Epilog();
       
   169     }
       
   170 
       
   171 TInt CRsfwRemoteAccessSync::DeleteDirectory(const TDesC& aPathName)
       
   172     {
       
   173     if (iPending)
       
   174         {
       
   175         return KErrServerBusy;
       
   176         }
       
   177     iPending = ETrue;
       
   178     TRAP(iStatus, iRemoteAccess->DeleteDirectoryL(aPathName, this));
       
   179     return Epilog();
       
   180     }
       
   181 
       
   182 TInt CRsfwRemoteAccessSync::DeleteFile(const TDesC& aPathName)
       
   183     {
       
   184     if (iPending)
       
   185         {
       
   186         return KErrServerBusy;
       
   187         }
       
   188     iPending = ETrue;
       
   189     TRAP(iStatus, iRemoteAccess->DeleteFileL(aPathName, this));
       
   190     return Epilog();
       
   191     }
       
   192 
       
   193 
       
   194 TInt CRsfwRemoteAccessSync::Rename(const TDesC& aSrcPathName,
       
   195                                const TDesC& aDstPathName,
       
   196                                TBool aOverwrite)
       
   197     {
       
   198     if (iPending)
       
   199         {
       
   200         return KErrServerBusy;
       
   201         }
       
   202     iPending = ETrue;
       
   203     TRAP(iStatus, iRemoteAccess->RenameL(aSrcPathName,
       
   204                                          aDstPathName,
       
   205                                          aOverwrite,
       
   206                                          this));
       
   207     return Epilog();
       
   208     }
       
   209 
       
   210 TInt CRsfwRemoteAccessSync::GetDirectoryAttributes(const TDesC& aPathName,
       
   211                                                CRsfwDirEntAttr*& aAttr)
       
   212     {
       
   213     if (iPending)
       
   214         {
       
   215         return KErrServerBusy;
       
   216         }
       
   217     iPending = ETrue;
       
   218     TRAP(iStatus,
       
   219          iRemoteAccess->GetDirectoryAttributesL(aPathName, aAttr, this));
       
   220     return Epilog();
       
   221     }
       
   222 
       
   223 TInt CRsfwRemoteAccessSync::GetFileAttributes(const TDesC& aPathName,
       
   224                                           CRsfwDirEntAttr*& aAttr)
       
   225     {
       
   226     if (iPending)
       
   227         {
       
   228         return KErrServerBusy;
       
   229         }
       
   230     iPending = ETrue;
       
   231     TRAP(iStatus, iRemoteAccess->GetFileAttributesL(aPathName,
       
   232                                                     aAttr,
       
   233                                                     this));
       
   234     return Epilog();
       
   235     }
       
   236 
       
   237 TInt CRsfwRemoteAccessSync::SetAttributes(const TDesC& aPathName,
       
   238                                       CRsfwDirEntAttr& aAttr)
       
   239     {
       
   240     if (iPending)
       
   241         {
       
   242         return KErrServerBusy;
       
   243         }
       
   244     iPending = ETrue;
       
   245     TRAP(iStatus, iRemoteAccess->SetAttributesL(aPathName, aAttr, this));
       
   246     return Epilog();
       
   247     }
       
   248 
       
   249 TInt CRsfwRemoteAccessSync::ObtainLock(const TDesC& aPathName,
       
   250                                    TUint aLockFlags,
       
   251                                    TUint& aTimeout,
       
   252                                    TDesC8*& aLockToken)
       
   253     {
       
   254     if (iPending)
       
   255         {
       
   256         return KErrServerBusy;
       
   257         }
       
   258     iPending = ETrue;
       
   259     TRAP(iStatus,
       
   260          iRemoteAccess->ObtainLockL(aPathName,
       
   261                                     aLockFlags,
       
   262                                     aTimeout,
       
   263                                     aLockToken,
       
   264                                     this));
       
   265     return Epilog();
       
   266     }
       
   267 
       
   268 TInt CRsfwRemoteAccessSync::ReleaseLock(const TDesC& aPathName)
       
   269     {
       
   270     if (iPending)
       
   271         {
       
   272         return KErrServerBusy;
       
   273         }
       
   274     iPending = ETrue;
       
   275     TRAP(iStatus, iRemoteAccess->ReleaseLockL(aPathName, this));
       
   276     return Epilog();
       
   277     }
       
   278 
       
   279 TInt CRsfwRemoteAccessSync::RefreshLock(const TDesC& aPathName,
       
   280                                     TUint& aTimeout)
       
   281 
       
   282     {
       
   283     if (iPending)
       
   284         {
       
   285         return KErrServerBusy;
       
   286         }
       
   287     iPending = ETrue;
       
   288     TRAP(iStatus, iRemoteAccess->RefreshLockL(aPathName, aTimeout, this));
       
   289     return Epilog();
       
   290     }
       
   291 
       
   292 TInt CRsfwRemoteAccessSync::SetLockToken(const TDesC& aPathName,
       
   293                                      const TDesC8& aLockToken)
       
   294     {
       
   295     return iRemoteAccess->SetLockToken(aPathName, aLockToken);
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------
       
   299 // from MRemoteAccessResponseHandler
       
   300 // -----------------------------------------------------------------
       
   301 
       
   302 void CRsfwRemoteAccessSync::HandleRemoteAccessResponse(TUint /* aId */,
       
   303                                                    TInt aStatus)
       
   304     {
       
   305     iStatus = aStatus;
       
   306     if (iSchedulerWait->IsStarted())
       
   307         {
       
   308         iSchedulerWait->AsyncStop();
       
   309         }
       
   310     iPending = EFalse;
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------
       
   314 
       
   315 TInt CRsfwRemoteAccessSync::Epilog()
       
   316     {
       
   317     if (iPending && (iStatus == KErrNone))
       
   318         {
       
   319         iSchedulerWait->Start();
       
   320         }
       
   321     return iStatus;
       
   322     }
       
   323 
       
   324 // End of File