remotestoragefw/remotefileengine/src/rsfwrfemessagerequest.cpp
branchRCL_3
changeset 19 88ee4cf65e19
parent 16 87c71b25c937
child 20 1aa8c82cb4cb
equal deleted inserted replaced
16:87c71b25c937 19:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  A request sent by a client (i.e. non-internal request)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "rsfwrfemessagerequest.h"
       
    20 #include "rsfwrfeoperation.h"
       
    21 #include "rsfwvolumetable.h"
       
    22 #include "rsfwvolume.h"
       
    23 #include "rsfwcommon.h"
       
    24 #include "rsfwinterface.h"
       
    25 #include "mdebug.h"
       
    26 #include "rsfwrfesession.h"
       
    27 
       
    28 
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CRsfwRfeMessageRequest::CRsfwRfeMessageRequest
       
    32 // ----------------------------------------------------------------------------
       
    33 //     
       
    34 CRsfwRfeMessageRequest::CRsfwRfeMessageRequest() 
       
    35     {
       
    36     SetRequestType(EMessageRequest);
       
    37     iMessageCompleted = EFalse;
       
    38     }
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CRsfwRfeMessageRequest::SetL
       
    42 // ----------------------------------------------------------------------------
       
    43 //     
       
    44 void CRsfwRfeMessageRequest::SetL(const RMessage2& aMessage,
       
    45                              CRsfwRfeSession* aSession)
       
    46     {    
       
    47     DEBUGSTRING(("CRsfwRfeMessageRequest::Set"));
       
    48     
       
    49     // common for all operations
       
    50     iMessage = aMessage;
       
    51     iSession = aSession;
       
    52     iVolumeTable = aSession->Volume(); 
       
    53     
       
    54     // if a file system access operation
       
    55     if (aMessage.Function() >=  ERenameReplace) 
       
    56         {
       
    57         switch (aMessage.Function())
       
    58             {
       
    59             // read input parameters
       
    60         case ERenameReplace:
       
    61             {
       
    62             TRfeRenameInArgs* inArgs = new (ELeave) TRfeRenameInArgs();
       
    63             CleanupStack::PushL(inArgs);
       
    64             TPckg<TRfeRenameInArgs> pkgInArgs(*inArgs);
       
    65             aMessage.ReadL(0, pkgInArgs);
       
    66             CleanupStack::Pop(inArgs);
       
    67             iInArgs = inArgs;
       
    68             iOutArgs = NULL;
       
    69             break;
       
    70             }
       
    71         case ESetAttr:
       
    72             {
       
    73             TRfeSetAttrInArgs* inArgs = new (ELeave) TRfeSetAttrInArgs();
       
    74             CleanupStack::PushL(inArgs);
       
    75             TPckg<TRfeSetAttrInArgs> pkgInArgs(*inArgs);
       
    76             aMessage.ReadL(0, pkgInArgs);
       
    77             CleanupStack::Pop(inArgs);
       
    78             iInArgs = inArgs;
       
    79             iOutArgs = NULL;
       
    80             break;
       
    81             }
       
    82         case EFsIoctl:
       
    83             {
       
    84             TRfeIoctlInArgs* inArgs = new (ELeave) TRfeIoctlInArgs();
       
    85             CleanupStack::PushL(inArgs);
       
    86             TPckg<TRfeIoctlInArgs> pkgInArgs(*inArgs);
       
    87             aMessage.ReadL(0, pkgInArgs);
       
    88             CleanupStack::Pop(inArgs);
       
    89             iInArgs = inArgs;
       
    90             iOutArgs = NULL;
       
    91             break;
       
    92             }
       
    93         
       
    94         case EGetAttr:
       
    95             {
       
    96             TRfeGetAttrInArgs* inArgs = new (ELeave) TRfeGetAttrInArgs();
       
    97             CleanupStack::PushL(inArgs);
       
    98             TRfeGetAttrOutArgs* outArgs = new (ELeave )TRfeGetAttrOutArgs();
       
    99             CleanupStack::PushL(outArgs);
       
   100             TPckg<TRfeGetAttrInArgs> pkgInArgs(*inArgs);
       
   101             aMessage.ReadL(0, pkgInArgs);
       
   102             CleanupStack::Pop(2, inArgs); // inArgs, outArgs
       
   103             iInArgs = inArgs;
       
   104             iOutArgs = outArgs;
       
   105             break;
       
   106             }
       
   107 
       
   108         case EOpenByPath:
       
   109             {
       
   110             TRfeOpenByPathInArgs* inArgs = new (ELeave) TRfeOpenByPathInArgs();
       
   111             CleanupStack::PushL(inArgs);
       
   112             TRfeOpenByPathOutArgs* outArgs = new (ELeave) TRfeOpenByPathOutArgs();
       
   113             CleanupStack::PushL(outArgs);
       
   114             TPckg<TRfeOpenByPathInArgs> pkgInArgs(*inArgs);
       
   115             aMessage.ReadL(0, pkgInArgs);
       
   116             CleanupStack::Pop(2, inArgs); // inArgs, outArgs
       
   117             iInArgs = inArgs;
       
   118             iOutArgs = outArgs;
       
   119             break;      
       
   120             }   
       
   121 
       
   122         case EFsRoot:
       
   123             {
       
   124             TRfeRootInArgs* inArgs = new (ELeave) TRfeRootInArgs();
       
   125             CleanupStack::PushL(inArgs);
       
   126             TRfeRootOutArgs* outArgs = new (ELeave) TRfeRootOutArgs();
       
   127             CleanupStack::PushL(outArgs);
       
   128             TPckg<TRfeRootInArgs> pkgInArgs(*inArgs);
       
   129             aMessage.ReadL(0, pkgInArgs);
       
   130             CleanupStack::Pop(2, inArgs); // inArgs, outArgs
       
   131             iInArgs = inArgs;
       
   132             iOutArgs = outArgs;
       
   133             break;      
       
   134             }   
       
   135 
       
   136         case EMkDir:
       
   137             {
       
   138             TRfeMkdirInArgs* inArgs = new (ELeave) TRfeMkdirInArgs();
       
   139             CleanupStack::PushL(inArgs);
       
   140             TPckg<TRfeMkdirInArgs> pkgInArgs(*inArgs);
       
   141             aMessage.ReadL(0, pkgInArgs);
       
   142             CleanupStack::Pop(inArgs);
       
   143             iInArgs = inArgs;
       
   144             iOutArgs = NULL;
       
   145             break;
       
   146             }
       
   147 
       
   148         case ERemoveDir:
       
   149             {
       
   150             TRfeRmdirInArgs* inArgs = new (ELeave) TRfeRmdirInArgs();
       
   151             CleanupStack::PushL(inArgs);
       
   152             TPckg<TRfeRmdirInArgs> pkgInArgs(*inArgs);
       
   153             aMessage.ReadL(0, pkgInArgs);
       
   154             CleanupStack::Pop(inArgs);
       
   155             iInArgs = inArgs;
       
   156             iOutArgs = NULL;
       
   157             break;
       
   158             }
       
   159 
       
   160         case ECreateFile:
       
   161             {
       
   162             TRfeCreateInArgs* inArgs = new (ELeave) TRfeCreateInArgs();
       
   163             CleanupStack::PushL(inArgs);
       
   164             TRfeCreateOutArgs* outArgs = new (ELeave) TRfeCreateOutArgs();
       
   165             CleanupStack::PushL(outArgs);
       
   166             TPckg<TRfeCreateInArgs> pkgInArgs(*inArgs);
       
   167             aMessage.ReadL(0, pkgInArgs);
       
   168             CleanupStack::Pop(2, inArgs); // inArgs, outArgs
       
   169             iInArgs = inArgs;
       
   170             iOutArgs = outArgs;
       
   171             break;      
       
   172             }   
       
   173 
       
   174         case ERemove:
       
   175             {
       
   176             TRfeRemoveInArgs* inArgs = new (ELeave) TRfeRemoveInArgs();
       
   177             CleanupStack::PushL(inArgs);
       
   178             TPckg<TRfeRemoveInArgs> pkgInArgs(*inArgs);
       
   179             aMessage.ReadL(0, pkgInArgs);
       
   180             CleanupStack::Pop(inArgs);
       
   181             iInArgs = inArgs;
       
   182             iOutArgs = NULL;
       
   183             break;
       
   184             }
       
   185 
       
   186         case ELookUp:
       
   187             {
       
   188             TRfeLookupInArgs* inArgs = new (ELeave) TRfeLookupInArgs();
       
   189             CleanupStack::PushL(inArgs);
       
   190             TRfeLookupOutArgs* outArgs = new (ELeave) TRfeLookupOutArgs();
       
   191             CleanupStack::PushL(outArgs);
       
   192             TPckg<TRfeLookupInArgs> pkgInArgs(*inArgs);
       
   193             aMessage.ReadL(0, pkgInArgs);
       
   194             CleanupStack::Pop(2, inArgs);
       
   195             iInArgs = inArgs;
       
   196             iOutArgs = outArgs;
       
   197             break;      
       
   198             }   
       
   199 
       
   200         case EClose:
       
   201             {
       
   202             TRfeCloseInArgs* inArgs = new (ELeave) TRfeCloseInArgs();
       
   203             inArgs->iFid.iVolumeId = aMessage.Int0();
       
   204             inArgs->iFid.iNodeId = aMessage.Int1();
       
   205             inArgs->iOpCode = EClose;
       
   206             inArgs->iFlags = aMessage.Int2();
       
   207             iInArgs = inArgs;
       
   208             iOutArgs = NULL;
       
   209             break;
       
   210             }
       
   211 
       
   212        case EFlush:
       
   213             {
       
   214             TRfeFlushInArgs* inArgs = new (ELeave) TRfeFlushInArgs();
       
   215             CleanupStack::PushL(inArgs);
       
   216             TPckg<TRfeFlushInArgs> pkgInArgs(*inArgs);
       
   217             aMessage.ReadL(0, pkgInArgs);
       
   218             CleanupStack::Pop(inArgs);
       
   219             iInArgs = inArgs;
       
   220             break;
       
   221             }
       
   222 
       
   223         case EFetch:
       
   224             {
       
   225             TRfeFetchInArgs* inArgs = new (ELeave) TRfeFetchInArgs();
       
   226             CleanupStack::PushL(inArgs);
       
   227             TRfeFetchOutArgs* outArgs = new (ELeave) TRfeFetchOutArgs();
       
   228             CleanupStack::PushL(outArgs);
       
   229             TPckg<TRfeFetchInArgs> pkgInArgs(*inArgs);
       
   230             aMessage.ReadL(0, pkgInArgs);
       
   231             CleanupStack::Pop(2, inArgs);
       
   232             iInArgs = inArgs;
       
   233             iOutArgs = outArgs;
       
   234             break;  
       
   235             }
       
   236 
       
   237         case EFetchData:
       
   238             {
       
   239             TRfeFetchDataInArgs* inArgs = new (ELeave) TRfeFetchDataInArgs();
       
   240             CleanupStack::PushL(inArgs);
       
   241             TRfeFetchDataOutArgs* outArgs = new (ELeave) TRfeFetchDataOutArgs();
       
   242             CleanupStack::PushL(outArgs);
       
   243             TPckg<TRfeFetchDataInArgs> pkgInArgs(*inArgs);
       
   244             aMessage.ReadL(0, pkgInArgs);
       
   245             CleanupStack::Pop(2, inArgs);
       
   246             iInArgs = inArgs;
       
   247             iOutArgs = outArgs;
       
   248             break;
       
   249             }
       
   250 
       
   251         case EOkToWrite:
       
   252             {
       
   253             TRfeWriteDataInArgs* inArgs = new (ELeave) TRfeWriteDataInArgs();
       
   254             CleanupStack::PushL(inArgs);
       
   255             TRfeWriteDataOutArgs* outArgs = new (ELeave) TRfeWriteDataOutArgs();
       
   256             CleanupStack::PushL(outArgs);
       
   257             TPckg<TRfeWriteDataInArgs> pkgInArgs(*inArgs);
       
   258             aMessage.ReadL(0, pkgInArgs);
       
   259             CleanupStack::Pop(2, inArgs);
       
   260             iInArgs = inArgs;
       
   261             iOutArgs = outArgs;
       
   262             break;
       
   263             }   
       
   264             }
       
   265     
       
   266         DEBUGSTRING(("volume id %d", iInArgs->iFid.iVolumeId));
       
   267         // Here volumeId may be 0 to denote "no volume id"
       
   268         // This is OK - we assume that drive letter A is never allocated
       
   269         iVolume = iVolumeTable->VolumeByVolumeId(iInArgs->iFid.iVolumeId);
       
   270         
       
   271         // As this is a file system access operation - not mount operation,
       
   272         // if volume is null we are not ready for file operations
       
   273         // - indicate this to the client who needs to call mount
       
   274         TBool ready =
       
   275             iVolume &&
       
   276             (iVolume->iMountInfo.iMountStatus.iMountState !=
       
   277              KMountStateDormant);
       
   278         if (!ready && aMessage.Function() != EFsRoot && aMessage.Function() != EClose) 
       
   279             {
       
   280             aMessage.Complete(KErrNotReady);
       
   281             iMessageCompleted = ETrue;
       
   282             }
       
   283         }
       
   284     }
       
   285     
       
   286 // ----------------------------------------------------------------------------
       
   287 // CRsfwRfeMessageRequest::Message
       
   288 // ----------------------------------------------------------------------------
       
   289 //     
       
   290 const RMessage2& CRsfwRfeMessageRequest::Message()
       
   291     {
       
   292     return iMessage;
       
   293     }
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 // CRsfwRfeMessageRequest::Session
       
   297 // ----------------------------------------------------------------------------
       
   298 //         
       
   299 CRsfwRfeSession* CRsfwRfeMessageRequest::Session()
       
   300     {
       
   301     return iSession;
       
   302     }
       
   303 
       
   304 
       
   305 // ----------------------------------------------------------------------------
       
   306 // CRsfwRfeMessageRequest::Session
       
   307 // ----------------------------------------------------------------------------
       
   308 //         
       
   309 void CRsfwRfeMessageRequest::SetSession(CRsfwRfeSession* aSession)
       
   310     {
       
   311     iSession = aSession;
       
   312     }
       
   313 
       
   314 
       
   315 // ----------------------------------------------------------------------------
       
   316 // CRsfwRfeMessageRequest::Complete
       
   317 // ----------------------------------------------------------------------------
       
   318 //         
       
   319 void CRsfwRfeMessageRequest::Complete(TInt aError)
       
   320     {
       
   321    	DEBUGSTRING(("CRsfwRfeMessageRequest::Complete"));
       
   322     if (iSession) 
       
   323         {
       
   324         DEBUGSTRING((">>> Dispatch exit (operation %d, error %d, return %d)",
       
   325                      Operation()->iFunction,
       
   326                      aError,
       
   327                      aError));
       
   328         DEBUGSTRING(("completing request"));  
       
   329         if (!Message().IsNull()) 
       
   330             {
       
   331             Message().Complete(aError);
       
   332             }
       
   333         DEBUGSTRING(("request completed")); 
       
   334         iMessageCompleted = ETrue;  
       
   335         }
       
   336     }   
       
   337 
       
   338 // ----------------------------------------------------------------------------
       
   339 // CRsfwRfeMessageRequest::CompleteAndDestroy
       
   340 // ----------------------------------------------------------------------------
       
   341 //     
       
   342 void CRsfwRfeMessageRequest::CompleteAndDestroy(TInt aError)
       
   343     {
       
   344   	DEBUGSTRING(("CRsfwRfeMessageRequest::CompleteAndDestroy"));
       
   345   	
       
   346   	TInt err;
       
   347     err = KErrNone;
       
   348     if (iSession) 
       
   349         {
       
   350         DEBUGSTRING((">>> Dispatch exit (operation %d, error %d, return %d)",
       
   351                      Operation()->iFunction, aError, aError));
       
   352         switch (Operation()->iFunction)
       
   353             {
       
   354             // write output parameters
       
   355         case EFetch:
       
   356             {
       
   357             DEBUGSTRING(("writing parameters: EFetch"));	
       
   358             TRfeFetchOutArgs* outArgs = (TRfeFetchOutArgs *)(iOutArgs);
       
   359             TPckg<TRfeFetchOutArgs> pkgOutArgs(*outArgs);
       
   360             err = Message().Write(1, pkgOutArgs);
       
   361             break;                  
       
   362             }   
       
   363 
       
   364         case EFetchData:
       
   365             {
       
   366            DEBUGSTRING(("writing parameters: EFetchData"));	
       
   367             TRfeFetchDataOutArgs* outArgs = (TRfeFetchDataOutArgs *)(iOutArgs);
       
   368             TPckg<TRfeFetchDataOutArgs> pkgOutArgs(*outArgs);
       
   369             err = Message().Write(1, pkgOutArgs);
       
   370             break;                  
       
   371             }   
       
   372 
       
   373         case EOkToWrite:
       
   374             {
       
   375            DEBUGSTRING(("writing parameters: EOkToWrite"));	 	
       
   376             TRfeWriteDataOutArgs* outArgs = (TRfeWriteDataOutArgs *)(iOutArgs);
       
   377             TPckg<TRfeWriteDataOutArgs> pkgOutArgs(*outArgs);
       
   378             err = Message().Write(1, pkgOutArgs);
       
   379             break;                  
       
   380             }           
       
   381 
       
   382         case ELookUp:
       
   383             {
       
   384             DEBUGSTRING(("writing parameters: ELookup"));		
       
   385             TRfeLookupOutArgs* outArgs = (TRfeLookupOutArgs *)(iOutArgs);
       
   386             TPckg<TRfeLookupOutArgs> pkgOutArgs(*outArgs);
       
   387             err = Message().Write(1, pkgOutArgs);
       
   388             break;                  
       
   389             }   
       
   390 
       
   391         case ECreateFile:
       
   392             {
       
   393            DEBUGSTRING(("writing parameters: ECreateFile"));		 	
       
   394             TRfeCreateOutArgs* outArgs = (TRfeCreateOutArgs *)(iOutArgs);
       
   395             TPckg<TRfeCreateOutArgs> pkgOutArgs(*outArgs);
       
   396             err = Message().Write(1, pkgOutArgs);
       
   397             break;  
       
   398             }           
       
   399 
       
   400         case EOpenByPath:
       
   401             {
       
   402            DEBUGSTRING(("writing parameters: EOpenByPath"));		 	
       
   403             TRfeOpenByPathOutArgs* outArgs =
       
   404                 (TRfeOpenByPathOutArgs *)(iOutArgs);
       
   405             TPckg<TRfeOpenByPathOutArgs> pkgOutArgs(*outArgs);
       
   406             err = Message().Write(1, pkgOutArgs);
       
   407             break;  
       
   408             }
       
   409             
       
   410         case EGetAttr:
       
   411             {
       
   412             DEBUGSTRING(("writing parameters: EGetAttr"));		
       
   413             TRfeGetAttrOutArgs* outArgs = (TRfeGetAttrOutArgs *)(iOutArgs);
       
   414             TPckg<TRfeGetAttrOutArgs> pkgOutArgs(*outArgs);
       
   415             err = Message().Write(1, pkgOutArgs);
       
   416             break;      
       
   417             }
       
   418 
       
   419         case EFsRoot:
       
   420             {
       
   421             DEBUGSTRING(("writing parameters: EFsRoot"));			
       
   422             TRfeRootOutArgs* outArgs = (TRfeRootOutArgs *)(iOutArgs);
       
   423             TPckg<TRfeRootOutArgs> pkgOutArgs(*outArgs);
       
   424             err = Message().Write(1, pkgOutArgs);
       
   425             break;      
       
   426             }
       
   427           }
       
   428           
       
   429   		if (err)
       
   430   		    {
       
   431   		    aError = err;
       
   432   			}
       
   433   
       
   434         DEBUGSTRING(("completing request"));
       
   435         if (!Message().IsNull()) 
       
   436             {
       
   437             Message().Complete(aError);
       
   438             }
       
   439         DEBUGSTRING(("request completed")); 
       
   440         iMessageCompleted = ETrue;  
       
   441         }
       
   442   
       
   443     Destroy();
       
   444     }
       
   445     
       
   446     
       
   447  // ----------------------------------------------------------------------------
       
   448 // CRsfwRfeRequest::Destroy
       
   449 // ----------------------------------------------------------------------------
       
   450 // 
       
   451 void CRsfwRfeMessageRequest::Destroy()
       
   452     {
       
   453     if (iSession) 
       
   454         {
       
   455         iSession->RemoveFromMessageRequestArray(this);
       
   456         }
       
   457         
       
   458     CRsfwRfeRequest::Destroy();
       
   459     }
       
   460        
       
   461