remotestoragefw/remotefilesystemplugin/src/rsfwfsdircb.cpp
branchRCL_3
changeset 15 88ee4cf65e19
parent 12 87c71b25c937
child 16 1aa8c82cb4cb
equal deleted inserted replaced
12:87c71b25c937 15:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2003-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: 	File server interface class representing an open directory.
       
    15 *                The code in this class allows to access a specific 
       
    16 *                remote directory.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "rsfwfsdircb.h"
       
    23 #include "rsfwfsmountcb.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // static constructor
       
    28 CRsfwFsDirCB* CRsfwFsDirCB::NewL()
       
    29     {
       
    30     CRsfwFsDirCB* remoteFsDirCB = new (ELeave) CRsfwFsDirCB;
       
    31     return remoteFsDirCB;
       
    32     }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CRsfwFsDirCB::CRsfwFsDirCB
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CRsfwFsDirCB::CRsfwFsDirCB()
       
    41     {
       
    42     iHasBeenFetched = EFalse;
       
    43     iEntryPos = 0;
       
    44     iStreamPos = 0;
       
    45     }
       
    46 
       
    47 // destructor
       
    48 CRsfwFsDirCB::~CRsfwFsDirCB()
       
    49     { 
       
    50     delete iMatch;
       
    51     iDirContReadStream.Close();   
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CRsfwFsDirCB::ReadL
       
    57 // File Server calls this function to retrieve one entry from open directory 
       
    58 // (next unread). When the last entry has been read, the function leaves with 
       
    59 // User::Leave(KErrEof). All of the properties of a TEntry, other than the  UID 
       
    60 // types, are always read.  The time stored in the iModified member of  anEntry 
       
    61 // should be converted from UTC time to local time. When storing the iName 
       
    62 // member of anEntry, the current (.), or parent marker (..) in the directory 
       
    63 // should not be returned.
       
    64 //
       
    65 // If the KEntryAttAllowUid flag is set in the iAtt member of anEntry, then
       
    66 // the entry UID type of an entry will be read. If, on reading the UID from
       
    67 // a file, KErrCorrupt is generated, because the file is corrupt,
       
    68 // ReadL() should not leave with this error message, but should return
       
    69 // as normal.
       
    70 //
       
    71 // FILTERING:
       
    72 // The function should read successive entries until a suitable entry is found.
       
    73 // An entry is suitable if the entry attributes match the criteria set by this
       
    74 // object's attributes, which are set on initialisation.  The File Server has 
       
    75 // set CDirCB::iAtt (which we inherit) with the bitmask.
       
    76 //
       
    77 // The File Server opened the directory with a name mask (e.g. "*"). 
       
    78 // This mask has been to stored to iMask of this class. We must only return entries, 
       
    79 // whose name match this mask.
       
    80 //
       
    81 // If, on return, the entry's full file name, TEntry::iName, is longer than
       
    82 // the maximum buffer size, then the entry cannot be returned to the client.
       
    83 // In this case the file server will set iPending to true and will call
       
    84 // StoreLongEntryName() before calling this function again.
       
    85 // In this case (when iPending is true), the function should re-read
       
    86 // the last entry to be read; it should also set iPending to false and
       
    87 //  should not advance the current read position.
       
    88 //
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 // 
       
    92 void CRsfwFsDirCB::ReadL
       
    93 (TEntry& anEntry)
       
    94     {       
       
    95       
       
    96     if (!iHasBeenFetched)
       
    97         {
       
    98         //   First read, the directory hasn't been fetched from the server
       
    99         //   yet (can't be done from open as that is always synchronous
       
   100         //   operation from UI's point of view)
       
   101         TInt totalBytes;
       
   102         User::LeaveIfError(static_cast<CRsfwFsMountCB&>
       
   103                 (Mount()).RSessionL()->Fetch(iThisFid, 0, 0, totalBytes));
       
   104         iHasBeenFetched = ETrue;
       
   105         }
       
   106 
       
   107     TEntry entry;
       
   108     
       
   109     if (iPending) 
       
   110         {
       
   111         iStreamPos = iPendingPos;
       
   112         iPending = EFalse; 
       
   113         }
       
   114         
       
   115     MStreamBuf* contFileStreamBuf = iDirContReadStream.Source();
       
   116     // Skip over entries already read
       
   117     contFileStreamBuf->SeekL(MStreamBuf::ERead, iStreamPos);
       
   118 
       
   119     TDirEnt d;
       
   120        
       
   121     do
       
   122         {
       
   123         TInt strippedBits = 0;
       
   124         TBool matchName = EFalse;
       
   125    		TBool matchAttr = EFalse;
       
   126         
       
   127         iPendingPos = iStreamPos;
       
   128         // Each round must fill one TEntry (or leave with KErrEof)
       
   129         d.InternalizeL(iDirContReadStream); // leaves with KErrEof
       
   130         iEntryPos++;
       
   131           
       
   132         entry.iName.Des().Copy(d.iName);
       
   133         entry.iAtt = d.iAttr.iAtt;
       
   134         entry.iSize = d.iAttr.iSize;
       
   135         entry.iModified = d.iAttr.iModified;
       
   136         entry.iType = (KNullUid, KNullUid, d.iAttr.iUid3);
       
   137         // do not set KEntryAttRemote for directories
       
   138         // it is defined by Symbian to be a file attribute only
       
   139         // remote file engine uses it internally for dirs also
       
   140         if (entry.iAtt & KEntryAttDir) 
       
   141             {
       
   142             entry.iAtt &= ~KEntryAttRemote;
       
   143             }
       
   144              
       
   145         // Filtering:
       
   146             
       
   147         // compare name against the match pattern
       
   148         matchName = (entry.iName.Match(*iMatch) != KErrNotFound);
       
   149         
       
   150         // compare against iAtt attribute mask
       
   151         // The mask works as follows: 
       
   152         // To match files only, specify KEntryAttNormal. 
       
   153         // To match both files and directories, specify KEntryAttDir. 
       
   154         // To match directories only, specify KEntryAttDir|KEntryAttMatchExclusive. 
       
   155         // To match files with a specific attribute, then OR the attribute involved with KEntryAttMatchExclusive. 
       
   156         // For example, to match read-only files, specify KEntryAttReadOnly|KEntryAttMatchExclusive. 
       
   157         if (iAtt & KEntryAttMatchExclusive)
       
   158         	{ // files with a specific attribute only
       
   159         	matchAttr = iAtt & entry.iAtt; 
       
   160         	}
       
   161         else 
       
   162         	{
       
   163         	if (iAtt & KEntryAttDir)
       
   164        			{
       
   165        			// both files and directories
       
   166        			matchAttr = ETrue;
       
   167        			}
       
   168        		else 
       
   169        			{
       
   170        			// files only
       
   171        			if (!(entry.iAtt & KEntryAttDir)) 
       
   172        				{
       
   173        				matchAttr = ETrue;
       
   174        				}
       
   175        			}
       
   176         	}     	
       
   177         if (matchName && matchAttr)
       
   178             {
       
   179             // "reverse" bits modified to make comparison easier
       
   180             entry.iAtt |= strippedBits;
       
   181             entry.iAtt &= ~KEntryAttMatchExclusive; 
       
   182             anEntry = entry;
       
   183             break;
       
   184             }
       
   185         }
       
   186     while (1);
       
   187 
       
   188     iStreamPos = contFileStreamBuf->TellL(MStreamBuf::ERead);
       
   189         
       
   190     }
       
   191     
       
   192     
       
   193 // -----------------------------------------------------------------------------
       
   194 // CRsfwFsDirCB::SetDirL
       
   195 // Opens read stream in the container file. Called in CRsfwFsMountCB when the 
       
   196 // directory is opened.
       
   197 // Implementation notice: As this class only reads the container file, it would
       
   198 // seem sensible to open  EFileRead|EFileShareAny here, but when Remote 
       
   199 // File Engine then tries to open EFileWrite|EFileShareAny it fails unless
       
   200 // EFileWrite is specified here also...
       
   201 //
       
   202 // (other items were commented in a header).
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CRsfwFsDirCB::SetDirL(
       
   206     const TDesC& aPath, 
       
   207     const TDesC& aName)
       
   208     {
       
   209       
       
   210     User::LeaveIfError(iDirContReadStream.Open(*(RFs* )Dll::Tls(),
       
   211                                                aPath, EFileWrite | EFileShareAny));
       
   212     iMatch = aName.AllocL();
       
   213     
       
   214     }
       
   215 
       
   216 // End of File